transforms.Normalize() between 0 and 1 when using Lab
which mean, std should I use when I want to normalize a tensor to a range of 0 to 1? But I work with images with 2 channels (a, b channel -&gt; -128 to 127) only instead of 3 channels. Thus, the usual mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225] will not do the job.
transform = transforms.Compose([
   transforms.ToTensor(),
   transforms.Normalize(mean=[0.485, 0.456, 0.406],
                        std=[0.229, 0.224, 0.225])
])

This leads to this error message:

tensor.sub_(mean[:, None, None]).div_(std[:, None, None])
RuntimeError: The size of tensor a (2) must match the size of tensor b
(3) at non-singleton dimension 0


As you can see, PyTorch complains about the Tensor size, since you lack a channel.

Additionally, the "usual" mean and std values are computed on ImageNet dataset, and are useful if the statistics of your data match the ones of that dataset.

As you work with two channels only, I assume that your domain might be fairly different from 3-channels natural images. In that case I would simply use 0.5 for both mean and std, such that the minimum value 0 will be converted to (0 - 0.5) / 0.5 = -1 and the maximum value of 1 to (1 - 0.5) / 0.5 = 1.

transform = transforms.Compose([
   transforms.ToTensor(),
   transforms.Normalize(mean=[0.5, 0.5],
                        std=[0.5, 0.5])
])




Edit: I would recommend zero-centering of the input. 

However, if for some reason you must have it in range [0, 1], calling only ToTensor() would suffice.

In this case, a word of caution. I think ToTensor() assumes your input to lie in range [0, 255] prior to the transform, so it basically divides it by 255. If that is not the case in your domain (e.g. your input is always in range [1, 50] for some reason) I would simply create a custom transform to divide for the actual upper bound for your data.
