def get_caffenet(netname):
if netname=='googlenet':
# caffemodel paths
model_path = './Caffe_Models/googlenet/'
net_fn = model_path + 'deploy.prototxt'
param_fn = model_path + 'bvlc_googlenet.caffemodel'
# get the mean (googlenet doesn't do this per feature, but per channel, see train_val.prototxt)
mean = np.float32([104.0, 117.0, 123.0])
# define the neural network classifier
net = caffe.Classifier(net_fn, param_fn, caffe.TEST, channel_swap = (2,1,0), mean = mean)
elif netname=='alexnet':
# caffemodel paths
model_path = './Caffe_Models/bvlc_alexnet/'
net_fn = model_path + 'deploy.prototxt'
param_fn = model_path + 'bvlc_alexnet.caffemodel'
# get the mean
mean = np.load('./Caffe_Models/ilsvrc_2012_mean.npy')
# crop mean
image_dims = (227,227) # see deploy.prototxt file
excess_h = mean.shape[1] - image_dims[0]
excess_w = mean.shape[2] - image_dims[1]
mean = mean[:, excess_h:(excess_h+image_dims[0]), excess_w:(excess_w+image_dims[1])]
# define the neural network classifier
net = caffe.Classifier(net_fn, param_fn, caffe.TEST, channel_swap = (2,1,0), mean = mean)
elif netname == 'vgg':
# caffemodel paths
model_path = './Caffe_Models/vgg network/'
net_fn = model_path + 'VGG_ILSVRC_16_layers_deploy.prototxt'
param_fn = model_path + 'VGG_ILSVRC_16_layers.caffemodel'
mean = np.float32([103.939, 116.779, 123.68])
# define the neural network classifier
net = caffe.Classifier(net_fn, param_fn, caffe.TEST, channel_swap = (2,1,0), mean = mean)
else:
print 'Provided netname unknown. Returning None.'
net = None
return net
评论列表
文章目录