ToTensor and Normalize transforms

Hi,

About ToTensor you are right, it standardizes input. Please see this post.

About your questions:

  1. If you use mean=[0.5,...], std=[0.5,...] then a standardized input will be in [-1, 1] but this exactly true for ImanetNet mean and std. You can verify this by calculating (x - mean(x)) / std.

  2. This question is little bit tricky, but if I want to summarize my answer, it has almost similar effect when you do not standardize input. As you might know, when images are in range of [0-255] or in case of other data, when a feature has a bigger range than the other features, neural network tend to change based on that range so that particular feature will dominate other features. About [0, 1], still data is biased toward positive side of numbers. If you plot [-1, 1] data, all are gathered around mean like a circle which helps to have a better learning. Actually, it has more to do with statistics which you can find many good lectures about it.

  3. In summary, when your dataset is far from ImageNet, you need to define your own custom mean and std, for instance in medical image processing.
    The idea is that a subset of a set tends to have similar statistics to the original set and that is why sampling works. Now, if your dataset is similar to ImageNet, then it has similar mean and std to ImageNet because it is like you sampled ImageNet to get your own. In your example, probably, your style transfer network is working with images with similar structure to ImageNet.

Bests

2 Likes