chenxi116 / DeepLabv3.pytorch

PyTorch implementation of DeepLabv3
Other
253 stars 47 forks source link

Normalization of input images in scratch trainings #9

Open SorourMo opened 5 years ago

SorourMo commented 5 years ago

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.

chenxi116 commented 5 years ago

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

SorourMo commented 5 years ago

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.

chenxi116 commented 5 years ago

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

SorourMo commented 5 years ago

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