titu1994 / DenseNet

DenseNet implementation in Keras
MIT License
707 stars 294 forks source link

preprocess scale 0.017 #26

Closed ahundt closed 6 years ago

ahundt commented 7 years ago

Looking at the preprocess function I see:

 x *= 0.017 # scale values

I thought it might be 1/128 but that is 0.0078125. I can't find anywhere else that something similar is done either in upstream implementations or in the keras preprocessing. Do you have information or reasoning regarding this scaling factor?

titu1994 commented 7 years ago

Primarily, incorrect classification if scaling is not performed. I referred to the Keras-Densenet repo for this right ? Or did I forget that when I rewrote the call

titu1994 commented 7 years ago

It's approximately 1/58.8 for some reason. I never could find out why this is the case.

titu1994 commented 7 years ago

Maybe try with 1/255 and see if it still classifies correctly?

vfdev-5 commented 7 years ago

Actually, the reason of 0.017 is the following: Originally, they preprocess normalized between [0.0; 1.0] RGB images by subtracting a mean value [0.485, 0.456, 0.406] and dividing each channel by a corresponding std value from [0.229, 0.224, 0.225], see here. But as @titu1994 says that the weights are ported from here and Felix says that the weights were ported from here, where the preprocessing is

and if you compute the inverse of 255 * mean(std), it gives 1.0 / (255.0 * 0.227) = 0.01727563272004837

HTH

titu1994 commented 6 years ago

Thank you very much for the explanation @vfdev-5 !

ahundt commented 6 years ago

@vfdev-5 good sleuthing, thanks!