利用build/tools/compute_image_mean产生mean.binaryproto
文件后,利用如下代码产生mean.npy
文件,给pycaffe调用:
#!/usr/bin/env python
MEAN_BIN = 'mean.binaryproto'
MEAN_NPY = 'mean.npy'
from caffe.proto import caffe_pb2
from caffe.io import blobproto_to_array
print('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...')