Normalizing pixel Values in PyTorch
I am currently working with the CORnet-Z neural network and I am training it on an alternative version of the ImageNet image dataset.
I looked through the code and noticed this image value normalization method:
normalize = torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                             std=[0.229, 0.224, 0.225])
...


And then implemented later in the train, val, and test class:

torchvision.transforms.Compose([
    torchvision.transforms.RandomResizedCrop(256),
    torchvision.transforms.RandomHorizontalFlip(),
    torchvision.transforms.ToTensor(),
    normalize]))

I was wondering if I could rewrite this to just take the RGB pixel values and divide them by 255 to have a scale of 0-1 to work with.
According to the torchvision.transforms documentation this is not an implemented approach.

What you found in the code is statistics standardization, you're looking to normalize the input. These are two different operations but can be carried out with the same operator: under torchvision.transforms by the name of Normalize. It applies a shift-scale on the input:

Normalize a tensor image with mean and standard deviation. This transform does not support PIL Image. Given mean: (mean[1],...,mean[n]) and std: (std[1],..,std[n]) for n channels, this transform will normalize each channel of the input torch.*Tensor i.e., output[channel] = (input[channel] - mean[channel]) / std[channel].

&gt;&gt;&gt; normalize = T.Normalize(mean=0, std=255)

Your transformation pipeline is then:
&gt;&gt;&gt; T.Compose([T.RandomResizedCrop(256),
               T.RandomHorizontalFlip(),
               T.ToTensor(),
               normalize]))

where torchvivision.transforms is imported as T.
