Proper Classifer setup for GoogleNet - Cannot reproduce test accuracy

1,206 views
Skip to first unread message

echeng

unread,
May 8, 2015, 6:50:17 PM5/8/15
to caffe...@googlegroups.com
What is the proper way to modify the Classifying Imagenet (http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/classification.ipynb) example to use the BVLC GoogleNet model?

Following the Flickr style example, I fine-tuned the BVLC GoogleNet model for my application and am seeing test accuracy of about 95%.  However, when I modify the Imagenet example above to use my fine-tuned GoogleNet model and actually classify images, it seems to be performing much worse.

Per this topic: https://groups.google.com/forum/#!topic/caffe-users/Xze-SMvYCvs it looks like it might be due to a mismatch in preprocessing, but as far as I can tell, the means, channel swapping, and image sizes in the example are correct for GoogleNet.

Any suggestions?  What are the common ways I might be misusing the model?

Thanks.

echeng

unread,
May 9, 2015, 3:06:46 AM5/9/15
to caffe...@googlegroups.com
Turns out I had a bug.  To fine-tune, I renamed the classifier layers in train_val.prototxt, but forgot to modify the name of the corresponding deploy.prototxt layer.  Once I fixed this, I was able to reproduce the test accuracy reported by Caffe during training using the default preprocessing parameters specified in the Classifying Imagenet ipython notebook example. 

S.Majid Azimi

unread,
Jul 24, 2015, 2:30:59 PM7/24/15
to Caffe Users, echen...@gmail.com
how to did you do that?

I get the error that i can't be broadcast from 3,224,224 to 3,227,227 which I can't understand because the size of cat image is 360 480 3 which should be converted by transformer.preprocess to 1,3,227,227. I don't know from 224 is coming from?

auro tripathy

unread,
Sep 17, 2015, 1:07:26 PM9/17/15
to Caffe Users, echen...@gmail.com
I'm getting the same error. I switched the models and the prototxt file for GoogLeNet (from the reference model). 

net = caffe.Net(caffe_root + 'models/bvlc_googlenet/deploy.prototxt',
                caffe_root + 'models/bvlc_googlenet/bvlc_googlenet.caffemodel',
                caffe.TEST)

Error is the same as yours.

Help in understanding this is deeply appreciated. 

Thank you.

--------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-0b9723a6825b> in <module>()
      1 print(caffe_root)
----> 2 net.blobs['data'].data[...] = transformer.preprocess('data', caffe.io.load_image(caffe_root + 'examples/images/cat.jpg'))
      3 #net.blobs['data'].data[...] = caffe.io.load_image(caffe_root + 'examples/images/taj-mahal.jpg')
      4 out = net.forward()
      5 print("Predicted class is #{}.".format(out['prob'].argmax()))

ValueError: could not broadcast input array from shape (3,224,224) into shape (50,3,227,227)
----------------------------------------------------------------------------

auro tripathy

unread,
Sep 18, 2015, 2:19:00 PM9/18/15
to Caffe Users, echen...@gmail.com

matching the dimensions seems to fix it. 

old

# set net to batch size of 50
net.blobs['data'].reshape(50,3,227,227)

new
# set net to batch size of 50
net.blobs['data'].reshape(50,3,224,224)

johnn...@gmail.com

unread,
Nov 6, 2015, 9:54:20 AM11/6/15
to Caffe Users, echen...@gmail.com
I get the same error that I can't classify that cat.jpg, because the size is not right. The cat.jpg is 480*360*3, but in bvlc_googlenet/deploy.prototxt, the input_shape is 10*3*224*224. I do not know the details. Do you find any solutions? 

Thanks!

Giulia

unread,
Dec 22, 2015, 5:51:29 AM12/22/15
to Caffe Users
Thanks ekc, I had EXACTLY the same problem, and browsing I found your post which saved me from days of debugging!!!!

Giulia
Reply all
Reply to author
Forward
0 new messages