本文主要是介绍Caffe学习:使用pycaffe生成mean_file.py文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
利用build/tools/compute_image_mean产生mean.binaryproto
文件后,利用如下代码产生mean.npy
文件,给pycaffe调用:
#!/usr/bin/env pythonMEAN_BIN = 'mean.binaryproto'
MEAN_NPY = 'mean.npy'from caffe.proto import caffe_pb2
from caffe.io import blobproto_to_arrayprint('generating mean file...')mean_blob = caffe_pb2.BlobProto()
mean_blob.ParseFromString(open(MEAN_BIN, 'rb').read())import numpy as np
mean_npy = blobproto_to_array(mean_blob)
mean_npy_shape = mean_npy.shape
mean_npy = mean_npy.reshape(mean_npy_shape[1], mean_npy_shape[2], mean_npy_shape[3])np.save(file(MEAN_NPY, 'wb'), mean_npy)print('done...')
这篇关于Caffe学习:使用pycaffe生成mean_file.py文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!