Sucran
9/10/2017 - 8:33 AM

PyCaffe load net

Load network

Analyzing

load_net.py

model_def 定义了 model 的 prototxt 文件路径

caffe 的 prototxt 的类型有三种:

  • deploy
  • train
  • test deploy

是可以通过代码来修改test得到,具体代码可以借鉴:http://www.cnblogs.com/denny402/p/5685818.html

model_weights 定义了 model 的 caffemodel 路径, 一般是直接从作者网站上进行下载

net 是 caffe.Net,具体是:……

对于 deploy 的过程,一般也是选择 caffe.TEST。

# set the size of the input (we can skip this if we're happy
#  with the default; we can also change it later, e.g., for different batch sizes)
net.blobs['data'].reshape(50,        # batch size
                          3,         # 3-channel (BGR) images
                          227, 227)  # image size is 227x227
# 修改prototxt中的内容
model_def = caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt'
model_weights = caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'

net = caffe.Net(model_def,      # defines the structure of the model
                model_weights,  # contains the trained weights
                caffe.TEST)     # use test mode (e.g., don't perform dropout)