Hello all, I am using resnet-50 pretrain model from pytorch vision. Before using the pretrained model, my input data is as below for training from scratch
Is the above normalization way correct for input of resnet 50 pretrained model? I found that it take a lot of time in comparsion with my first way (div by 255)
You should subtract the mean and divide by the std.
Have a look at this formula in torchvision.transforms.Normalize.
Could you try that and report, if it helps training?
For normalization I would do as @ptrblck suggests.
If you just need to transfer your values between 0 and 1 encoding for a black and white image for example, dividing by 255 is enough I guess.
but you then pass the transform to your custom Dataset as a parameter and after getting the image you
just apply the transform on it. here is a simple example:
class CustomDataset(data.Dataset):
def __init__(self, transforms=None):
self.transforms = transforms
def get_image(self, index):
raise implement!
def __getitem__(self, index):
image, target = self.get_image(index)
#perform transform
if self.transforms is not None:
image = self.transforms(image)
return image, target
def __len__(self):
return len(self.dataset)
I notice that the Totensor Converts a PIL.Image or numpy.ndarray (H x W x C) in the range
[0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0].
but My array has been float and not in the [0,255]. for example, I have implemented rgb2lab and the results are float and not in the [0,255]. so how to carry out the Totensor or Normalize method?