Caffe: ValueError: Mean shape incompatible with input shape.

Created on 12 Jun 2015  路  4Comments  路  Source: BVLC/caffe

Hello all, I am using caffe in python to classify. I just use simple code such as

plt.rcParams['figure.figsize'] = (10, 10)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
mean_filename='./mean.binaryproto'
proto_data = open(mean_filename, "rb").read()
a = caffe.io.caffe_pb2.BlobProto.FromString(proto_data)
mean = caffe.io.blobproto_to_array(a)[0]
age_net_pretrained='./age_net.caffemodel'
age_net_model_file='./deploy_age.prototxt'
age_net = caffe.Classifier(age_net_model_file, age_net_pretrained,
mean=mean,
channel_swap=(2,1,0),
raw_scale=255,
image_dims=(256, 256))

However, I got error such as

Traceback (most recent call last):
File "cnn_age_gender_demo.py", line 25, in
image_dims=(256, 256))
File "/home/john/Downloads/caffe/python/caffe/classifier.py", line 34, in init
self.transformer.set_mean(in_, mean)
File "/home/john/Downloads/caffe/python/caffe/io.py", line 255, in set_mean
raise ValueError('Mean shape incompatible with input shape.')
ValueError: Mean shape incompatible with input shape.

Could you help me to reslove it? Thanks

Most helpful comment

Just edit deploy_gender.prototxt and set the input_dims to 256.
input_dim: 1
input_dim: 3
input_dim: 256
input_dim: 256

instead of 227 ;)

All 4 comments

I have the same issue :cry: If you have found a solution please tell me how you did it.
Cheers! :beers:

Let see the solution in http://stackoverflow.com/questions/30808735/error-when-using-classify-in-caffe . Please upvote his answer.

The solution did not work. I think. Or more likely I messed up. I have a question...do I have to remove this line?(its directly after where i inserted the mod):
self.mean[in_] = mean
Thanks!!

Just edit deploy_gender.prototxt and set the input_dims to 256.
input_dim: 1
input_dim: 3
input_dim: 256
input_dim: 256

instead of 227 ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamhankai picture iamhankai  路  3Comments

kelvinxu picture kelvinxu  路  3Comments

vladislavdonchev picture vladislavdonchev  路  3Comments

dfotland picture dfotland  路  3Comments

FreakTheMighty picture FreakTheMighty  路  3Comments