BVLC / caffe

Caffe: a fast open framework for deep learning.
http://caffe.berkeleyvision.org/
Other
34.13k stars 18.68k forks source link

Resized Image Prediction Problem #4364

Open gungorbasa opened 8 years ago

gungorbasa commented 8 years ago

Hello guys,

I saw a similar post on https://github.com/NVIDIA/DIGITS/issues/62 but it is not completely same.

Here is the situation, whenever I use 256x256 image in my caffe model (I run caffe on vm with Ubuntu, host computer is Mac OS and convert all images to smaller sizes in MacOS) it works good, and predict a class with confidence score around 0.6. This is good. However, when I try to resize my image in the python code both the accuracy and prediction changes.

While the 256x256 image predicts class X, resized version of 2400x2400 image predicts class Y with different confidence (0.2 around).

Direct 256x256 image input code input_image = caffe.io.load_image(image_path) prediction = net.predict([input_image], oversample=False) data = net.blobs[layer_name].data[0].reshape(1,-1)[0] print os.path.basename(image_path), ' : ' , labels[prediction[0].argmax()].strip() , ' (', prediction[0][prediction[0].argmax()] , ')'

Image Resized Code input_image = caffe.io.load_image(image_path) input_image = caffe.io.resize_image( input_image, (256,256), interp_order=3 ) prediction = net.predict([input_image], oversample=False) data = net.blobs[layer_name].data[0].reshape(1,-1)[0] print os.path.basename(image_path), ' : ' , labels[prediction[0].argmax()].strip() , ' (', prediction[0][prediction[0].argmax()] , ')'

Also I am using GoogleNet model from Caffe Zoo. I feel like this might be an issue of the library.

seanbell commented 8 years ago

This looks like a preprocessing/resizing issue, not an issue BVLC/caffe. You could try using PIL to do the image resizing, using Image.ANTIALIAS mode which is a fairly high quality filter.

gungorbasa commented 8 years ago

I tried with both OpenCV and PIL and neither of them worked. I don't know what causing the problem.