deep-learning-models icon indicating copy to clipboard operation
deep-learning-models copied to clipboard

preprocess_input() zero-centering channels are backwards

Open davidwhealey opened this issue 8 years ago • 2 comments

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

davidwhealey avatar Feb 24 '17 21:02 davidwhealey

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

And yes, you were right!

gugarosa avatar Mar 20 '17 15:03 gugarosa

@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.

adityapatadia avatar Sep 28 '17 10:09 adityapatadia