How to do normalization on pretrained imagenet models?

1,277 views
Skip to first unread message

Felix

unread,
Dec 6, 2015, 8:02:19 AM12/6/15
to torch7
Dear all

can anyone tell me how to best normalize the images when using pre-trained overfeat or googlenet models? It seems common to multiply the jpg image by 255 and then bubtract the mean of about 117. What about std deviation?

img:mul(255):add(-118.380948):div(61.896913)

img:mul(255):clamp(0, 255):add(-117)
Why is there no term for the std-deviation?

Regards, Felix

Vislab

unread,
Dec 6, 2015, 11:26:23 AM12/6/15
to torch7
There's 2 cheap ways to do image normalization.

You can do pixel-wise normalization for all channels by computing the pixel intensity average for a N number of samples and subtracting to the input images (like the pre-trained caffe models usually do).

Or you can compute the average pixel intensity (per channel) and the average standard deviation (per channel) and subtract+divide the input with the computed mean+std, respectively.

There's not much of a difference between the two methods from my experience (I use the second one).

Felix

unread,
Dec 6, 2015, 5:07:18 PM12/6/15
to torch7
Hi Vislab

thanks for the answer. Sorry for not being clear enough: I am aware of the two general options. I rather meant more specifically for the two pre-trained models (overfeat, googlenet mentioned above) how to normalize the images.
I acutally used these 2 pre trained models and subtracted the image mean and divided by the std-deviation but I did not multiply by 255 (that is the image values are roughly between +-0.5. The accuracy of the models lookes ok but I am not sure if I shall normalize the images as follows:

Vislab

unread,
Dec 6, 2015, 7:08:58 PM12/6/15
to torch7
Ah, it seems the normalization is wrt to a 0-255 pixel range instead of 0-1. You can load images in 'byte' format, avoiding the extra multiplication with 255 here.

The second link, probably soumith simplified the normalization to mean = 117 and std = 1 just to keep things simple (that's why you don't see a division for the std part because :div(1) its kinda pointless).

There's not a whole lot models in the torch format, but you can use the ones here, just need to download the right protofiles and reshape images from RGB to BGR format (img= image.load(filename):transpose(1,3)). I've tested some and i've got good results.

Reply all
Reply to author
Forward
0 new messages