how to work with ilsvrc_2012_mean.npy

1,267 views
Skip to first unread message

Yasser Souri

unread,
Dec 15, 2014, 3:15:02 AM12/15/14
to caffe...@googlegroups.com
Salam

I want to replace some portion of my images with the ilsvrc mean, before feeding them into the network. For example say that I have an image called `img` (256 x 256) and I want to replace some pixels from it with the mean file:

img = caffe.io.load_image('caffe/examples/images/cat.jpg') # loading the image
img
= cv2.resize(img, (256, 256)) # resizing it to 256x256
ilsvrc_mean
= numpy.load('caffe/python/caffe/imagenet/ilsvrc_2012_mean.npy') #loading the mean file

print ilsvrc_mean.shape, img.shape #(3, 256, 256) (256, 256, 3)

As you see since the ilsvrc has different shape than my image I have to convert them to the same shape so I do this:

mean_file = ilsvrc_mean.reshape((256,256,3))

Now I can do what I want (replace some portions of my image with ilsvrc mean file):

img[50:170, 100:170, :] = mean_file[50:170, 100:170, :]
plt
.imshow(img)

And I get this:

I was expecting something grayish without such textures, so I think I'm doing something wrong. In fact if I display the mean file:

plt.imshow(mean_file)

I get this:

I wonder what is that I'm doing wrong.


Thanks,

ngc...@gmail.com

unread,
Aug 4, 2015, 11:41:45 PM8/4/15
to Caffe Users
To convert shape to (256,256,3), should use numpy.swapaxes instead of numpy.reshape.
I also normalized the values to [0,1].
The mean image turns out to be a light bluish blob which is darker at the lower centre portion.
Do you guys get the same?

ngc...@gmail.com

unread,
Aug 5, 2015, 3:40:41 AM8/5/15
to Caffe Users
Oh, I normalized wrongly.... I think the right way to normalize is just to divide every pixel by 255.
Then the mean image is just grayish.
Now my doubt is what is the channel order in the array obtained from the ilsvrc_2012_mean.npy or binaryproto file... RGB or BGR?
Someone familiar with the compute image mean code please help enlighten.
Thanks!
Reply all
Reply to author
Forward
0 new messages