How to preprocess input for pre trained networks?

@smth I have confusion regarding the use of same mean and std for all data. Why can’t we use per image in that way each image is independent for nomalization?

you can do that if you want, it depends on what one wants to do. I feel more comfortable with a single mean / std for the whole dataset – or else i think it amplifies artificacts in high-noise images

1 Like

Hi,
What is best way to transform a tensor back to NumPy?
When it is scaled with 0.5,0.50.5 it is clear but how would you recommend it to do when scaling with:
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])

What about grey scale images, what should the mean and SD be?

@qianguih / @mattmacy,

Do you mean we need to normalize to [0,1] set mean to 0 and std deviation 1 respectively before we AGAIN apply the following? Thanks

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                     std=[0.229, 0.224, 0.225])

Yes, this transform has to be applied after the ToTensor() transform

How about mean/std value of RGBD input

During transfer learning using these pretrained models like VGG16, do all the images need to be resized to 224*224 before applying this normalization?

I was just rescaling the pixel intensities to [0, 1] and not resizing or applying normalization to the images in my dataset when training with pretrained VGG16 model from Pytorch. But the loss and accuracy is staying approximately constant in this situation. While trying to find out the reason for this problem, I came across this post. So, this resizing to (224 * 224) size, scaling the pixel intensities to [0, 1] and applying normalization using these mean/std values are the prerequisites for training using these Pytorch pretrained models?

I am very new to Pytorch. Please help. Thank you in advance.