Using pretrained model for test

If I use the pretrained resnet50 to train my own project, I need to convert image from BGR to RGB, normalize image range from [0, 255] to [0, 1], 1. use transformer: normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) to transform the image data.

But if I want to test an image, should I do the above steps? Or just convert image from BGR to RGB? I am confused…

Yes, except for those transformations that are meant for data-augmentation, all other transformation steps should be applied to the test data as well.

Specifically, this transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) applied to your training data will sort of mean-center and standardize the image channels. Therefore, if you do not apply this transformation to your test images, the train data and test data will have different data distributions.

Data augmentation transformations include RandomHorizontalFlip, RandomCrop and so on, which do not need to be applied in the evaluation phase.

Thanks~
But what is the function of transforms.Normalize ? Does it make data have mean=0.485, 0.456, 0.406, and std=0.229, 0.224, 0.225?

The function transform.Normalize will subtract the given mean from each input image, and then divide the results by the given std.

In mathematical terms, if X represent an image, then it will do the following: (X-mean)/std.

So, if the mean and std are the actual mean and std of the training data, it will basically mean-center and standardize the data.