DeepLabv3.pytorch icon indicating copy to clipboard operation
DeepLabv3.pytorch copied to clipboard

Normalization of input images in scratch trainings

Open SorourMo opened this issue 5 years ago • 4 comments

Hi there, Thanks you for sharing the code. It seems the preprocess in utils.py automatically normalizes the images using Imagenet mean and std values regardless of the state of training. If the training is started from scratch (no pretrained weights are required), still the mean and std of images are gonna used for normalization.

https://github.com/chenxi116/DeepLabv3.pytorch/blob/046818d755f91169dbad141362b98178dd685447/utils.py#L73

A simple flag could be added to prevent this. I'd be happy to pull request for that. Please let me know if you are interested in adding that flag.

SorourMo avatar Nov 09 '19 01:11 SorourMo

I don't understand why this should be prevented? Under what circumstance should we not normalize like this?

Are you saying the PyTorch ImageNet training script is also wrong? https://github.com/pytorch/examples/blob/master/imagenet/main.py#L202

chenxi116 avatar Nov 09 '19 01:11 chenxi116

No no, I am not saying training script over Imagenet is wrong. I think when we are training a CNN like deeplab on say cityscapes training set "from scratch", we do not have to normalize the images before training using imagenet's mean and std, instead we need to normalize them using cityscapes's mean and std. Of course if the training was started from pretrained weights of Imagenet, normalizing by Imagenet's mean and std would make sense.

SorourMo avatar Nov 09 '19 23:11 SorourMo

Yes using Cityscapes mean and std should be better. Do you have those values calculated?

chenxi116 avatar Nov 10 '19 16:11 chenxi116

Here are the values for cityscapes training on 2975 images:

mean: [0.29866842 0.30135223 0.30561872]
std: [0.23925215 0.23859318 0.2385942 ] 

The code for calculating is https://github.com/SorourMo/Useful-statistics-on-public-datasets/blob/master/mean_std_cityscapes.py

SorourMo avatar Nov 15 '19 03:11 SorourMo