Normalising images in Cityscapes using mean and std of Imagenet

Hi, I am working with Cityscapes dataset. For normalising the images I used the mean and std of Imagenet. After normalising I computed mean and std for some images in the dataset. They are roughly close to 0 and 1 but not very close.

For example mean and std of one image after normalisation is equal to

mean = [-0.14200746, -0.07835515, -0.09254397]
std = [0.84492135, 0.8451715,  0.849345  ]

Are these values for mean and std of a normalised image acceptable?

I also computed the mean and std over the whole dataset using the following snippet:

def compute_mean_std(dataloader):
    
    pop_mean = []
    
    pop_std = []
    
    for i, (img,mask, rgb_mask) in enumerate(dataloader):
        
        numpy_image = img.cpu().numpy()
        
        batch_mean = np.mean(numpy_image,axis=(0,2,3))
        pop_mean.append(batch_mean)
    
        batch_std = np.mean(numpy_image, axis=(0,2,3))
        pop_std.append(batch_std)
    pop_mean = np.array(pop_mean).mean(axis=0)
    pop_std = np.array(pop_std).std(axis=0)
    return(pop_mean, pop_std)

And I obtained values:

MEAN = [0.28660315, 0.32426634, 0.28302112]
STD = [0.00310452, 0.00292714, 0.00296411]

But again when I normalised images using these values and calculated the mean and std of each image the mean and std was something like this:

[-7.8684726 -4.747944  -5.4215384]
[47.001762 51.33731  50.00176 ]

I do not know which point I missed. I only know these two ways to normalise images.

The ImageNet normalization is used as:

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])

While your mean is a bit different, the STD seems to be quite off and it also seems that you are indeed calculating the stddev of the mean of the samples, which would explain the small STD values and the large outputs.

So, dose it mean for normalising images I should use the mean and std of ImageNet?

Not necessarily and you could use your custom stats after fixing the calculation.

Ok, thank you for your answer.