Issue
I have started working with PyTorch and cannot figure it how I am supposed to find mean and std as the input parameters of normalise.
I have seen this
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)) #https://pytorch.org/vision/stable/transforms.html#
and in another example:
transformation = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(mean=[0.5,0.5,0.5],std=[0.5,0.5,0.5])
]) #https://github.com/MicrosoftDocs/ml-basics/blob/master/challenges/05%20%20-%20Safari%20CNN%20Solution%20(PyTorch).ipynb
so, how am I supposed to know or get these values if I have a set of images? Are these three parameters are related to R G B also?
Solution
suppose you have already X_train which is a list of numpy matrix eg. 32x32x3:
X_train = X_train / 255 #normalization of pixels
train_mean = X_train.reshape(3,-1).mean(axis=1)
train_std = X_train.reshape(3,-1).std(axis=1)
then you can pass this last 2 variables in your normalizer transformer :
transforms.Normalize(mean = train_mean ,std = train_std)
Answered By - Salvatore Pannozzo Capodiferro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.