classification probability not match
All my images are 480 *480 grayscale. I used default "half_crop" resize mode to fit images to 256 *256.
Then I downloaded the last epoch model and used caffe out-of-box classifier to predict the label for an image. However, the predicted probability does not match DIGIT'S classify one image top 5 probability. I suspect that the resize approach in caffe is different than "half_crop". Any suggestion to resize my input images?
net = caffe.Classifier(MODEL_FILE, PRETRAINED, mean=np.load('/my/meanfile.npy').mean(1).mean(1), raw_scale=255, image_dims=(256, 256))
imagefile='my/image/file' input_image = caffe.io.load_image(imagefile,False) input_image=caffe.io.resize_image(input_image,(256,256)) prediction = net.predict([input_image]) print prediction
Indeed! I think caffe is using squash by default.
Apart from half_crop mode, the actual resizing algorithm is different for DIGITS and caffe.
In the case, I experience feeding the DIGITS and the caffe the same big pic, they will predict different probability, however, if you do resize the big picture to match the input size(let's say 224), then, the result will be the same。 (Notice: be sure #59 is fixing in your testing to see this).
@cmis91, in the future this is a question better suited for the digits-users google group. But I'll go ahead and answer your question for anyone else who runs across this page:
I suspect that the resize approach in caffe is different than "half_crop"
That's true. "half_crop" is unique to DIGITS. If you're comparing results with models trained using CLI caffe, then you should probably choose "squash" in DIGITS.
And another problem you'll have is that DIGITS doesn't use oversampling when testing. When you use caffe.Classifier.predict() (and the Classifier module is not recommended anymore - see BVLC/caffe#2058), the default is oversampling=True (see here). That will give you different results.
@lukeyeager, thanks for the explanation. I did not find a user group for general question when I posted. A follow up question: is it possible to zip the data pre-process python script into the files when users download the model to ease the deployment? Currently, I have to dig into your source codes to see how digits does the half-crop, squash, etc. and write corresponding scripts to process the images to work with the model i downloaded. Well, it works, but a bit hustle.
is it possible to zip the data pre-process python script into the files when users download the model to ease the deployment?
That's certainly an option. For now, I think the script at tools/resize_image.py is probably all you need.
@lukeyeager, thanks for the suggestion.