def load_mean_file(mean_file):
if mean_file.endswith('.npy'):
return np.load(mean_file)
with open(mean_file, 'rb') as infile:
blob = caffe_pb2.BlobProto()
blob.MergeFromString(infile.read())
if blob.HasField('shape'):
blob_dims = blob.shape
assert len(blob_dims) == 4, 'Shape should have 4 dimensions - shape is "%s"' % blob.shape
elif blob.HasField('num') and blob.HasField('channels') and \
blob.HasField('height') and blob.HasField('width'):
blob_dims = (blob.num, blob.channels, blob.height, blob.width)
else:
raise ValueError('blob does not provide shape or 4d dimensions')
#pixel = np.reshape(blob.data, blob_dims[1:]).mean(1).mean(1)
#print pixel.shape
#t.set_mean('data', pixel)
mean=np.reshape(blob.data, blob_dims[1:])
#mean=mean[:,(256-224)//2:(256-224)//2+224,(256-224)//2:(256-224)//2+224]
return mean
评论列表
文章目录