Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalization of input images in scratch trainings #9

Open
SorourMo opened this issue Nov 9, 2019 · 4 comments
Open

Normalization of input images in scratch trainings #9

SorourMo opened this issue Nov 9, 2019 · 4 comments

Comments

@SorourMo
Copy link

SorourMo commented Nov 9, 2019

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.

transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])

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
Copy link
Owner

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
Copy link
Author

SorourMo commented Nov 9, 2019

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
Copy link
Owner

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

@SorourMo
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants