Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use mean.binaryproto with blobFromImage(s) ?

I’m using dnn::readNetFromCaffe to load this model published in the caffe model zoo:

https://github.com/BVLC/caffe/wiki/Model-Zoo#models-for-age-and-gender-classification

Apart from the standard .prototxt and .caffemodel files, a third file is provided: mean.binaryproto.

I know I should use it to perform the mean subtraction. But I couldn't figure out whether its a cv::subtract I should apply before invoking blobFromImage or is it something I'd use to somehow infer the mean and scalefactor parameters.

Mat mean = readMeanFromBinary(); // How to read a binaryproto into a Mat ?
Mat img = imread(imgFile);
// How to use mean ?
Mat inputBlob = blobFromImage(img, 1.0f, Size(227, 227), Scalar(), false);
net.setInput(inputBlob, "data");
Mat prob = age.forward("prob");

So I have basically two questions:

  • How to read the mean.binaryproto file into a Mat ?
  • Once I have the mean, can I use it with blobFromImage ?

thanks Fábio