def compute_mean(input_list, plot_mean=False):
# If no data supplied, use mean supplied with pretrained model
if len(input_list) == 0:
net_root = '.'
net_dir = 'VGG_S_rgb'
mean_filename=os.path.join(net_root, net_dir, 'mean.binaryproto')
proto_data = open(mean_filename, "rb").read()
a = caffe.io.caffe_pb2.BlobProto.FromString(proto_data)
mean = caffe.io.blobproto_to_array(a)[0]
else:
x,y,c = 256,256,3
mean = np.zeros((c, x, y))
for img_file in input_list:
img = caffe.io.load_image(img_file)
img = mod_dim(img, x, y, c)
mean += img
mean /= len(input_list)
# Plot the mean image if desired:
if plot_mean:
plt.imshow(np.swapaxes(np.swapaxes(mean, 0, 1), 1, 2))
plt.show()
return mean
# Return VGG_S_Net from mean image and optional network type
caffe_functions.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录