Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@fabito, Besides .binaryproto contains a blob with pixel-wise mean values, Caffe uses a global mean values for each channel (https://github.com/BVLC/caffe/blob/master/examples/cpp_classification/classification.cpp#L144). So you need to compute them once and use a regular way to subtract means by blobFromImage.

In case of Age and Gender classification model, they are (78.4263377603, 87.7689143744, 114.895847746) for blue, green and red channels correspondingly.

import caffe
import numpy as np

blob = caffe.proto.caffe_pb2.BlobProto()
with open('mean.binaryproto', 'rb') as f:
    blob.ParseFromString(f.read())
    data = np.array(blob.data).reshape([blob.channels, blob.height, blob.width])
    print np.mean(data[0]), np.mean(data[1]), np.mean(data[2])