deep-learning-models
deep-learning-models copied to clipboard
preprocess_input() zero-centering channels are backwards
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
It is fixed on main repository: https://github.com/fchollet/keras/blob/master/keras/applications/imagenet_utils.py
And yes, you were right!
@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.