caffe icon indicating copy to clipboard operation
caffe copied to clipboard

problem about using mnist

Open lusnaow opened this issue 12 years ago • 1 comments

When I test mnist with python,an error arise: Traceback (most recent call last): File "1.py", line 16, in prediction = net.predict([input_image]) File "/root/Desktop/train/caffe/classifier.py", line 85, in predict caffe_in[ix] = self.preprocess(self.inputs[0], in_) File "/root/Desktop/train/caffe/pycaffe.py", line 307, in _Net_preprocess caffe_in -= mean ValueError: non-broadcastable output operand with shape (1,28,28) doesn't match the broadcast shape (3,28,28)

Here is the code:

import caffe import numpy as np MODEL_FILE = 'lenet.prototxt' PRETRAINED = 'lenet_iter_10000' IMAGE_FILE = 'charblk_11.jpg' net = caffe.Classifier(MODEL_FILE, PRETRAINED, mean=np.load('caffe/imagenet/ilsvrc_2012_mean.npy'), channel_swap=None, raw_scale=255, image_dims=(28, 28)) net.set_phase_test() net.set_mode_cpu() input_image = caffe.io.load_image(IMAGE_FILE,False) prediction = net.predict([input_image])

lenet_iter_10000 and lenet.prototxt are from the example. charblk_11.jpg is a gray image.

lusnaow avatar Sep 04 '14 04:09 lusnaow

Please ask on caffe-users. Issues are for development discussion. Thanks!

The issue here is that you are mismatching input dimensionality: the model needs the right number of channels.

shelhamer avatar Sep 15 '14 16:09 shelhamer