fchollet / deep-learning-models

Keras code and weights files for popular deep learning models.
MIT License
7.32k stars 2.46k forks source link

preprocess_input() zero-centering channels are backwards #41

Open davidwhealey opened 7 years ago

davidwhealey commented 7 years ago

In ksimonyan/VGG_ILSVRC_16_layers_deploy.prototxt, it states:

The input images should be zero-centered by mean pixel (rather than mean image) subtraction. Namely, the following BGR values should be subtracted: [103.939, 116.779, 123.68].

preprocess_input() implements like so:

x[:, :, :, 0] -= 103.939
x[:, :, :, 1] -= 116.779
x[:, :, :, 2] -= 123.68
# 'RGB'->'BGR'
x = x[:, :, :, ::-1]

Since the values are subtracted before the channels are swapped, the (R) mean is subtracted from the (B) channel and vice versa.

Of course, it may be that this version is correct and ksimonyan/VGG_ILSVRC_16_layers_deploy.prototxt has the order backwards

gugarosa commented 7 years ago

It is fixed on main repository: https://github.com/fchollet/keras/blob/master/keras/applications/imagenet_utils.py

And yes, you were right!

adityapatadia commented 7 years ago

@fchollet can you confirm whether released models were trained with such erroneous preprocessing function? If so, releasing new pre-trained models for all nets will help a lot.