I\'m using the Keras VGG16 model.
I\'ve seen it there is a preprocess_input method to use in conjunction with the VGG16 model. This method appears to call the prepr
The mode
here is not about the backend, but rather about on what framework the model was trained on and ported from. In the keras link to VGG16, it is stated that:
These weights are ported from the ones released by VGG at Oxford
So the VGG16 and VGG19 models were trained in Caffe and ported to TensorFlow, hence mode == 'caffe'
here (range from 0 to 255 and then extract the mean [103.939, 116.779, 123.68]
).
Newer networks, like MobileNet and ShuffleNet were trained on TensorFlow, so mode
is 'tf'
for them and the inputs are zero-centered in the range from -1 to 1.
Trying to use VGG16 myself again lately, i had troubles getting descent results by just importing preprocess_input
from vgg16 like this:
from keras.applications.vgg16 import VGG16, preprocess_input
Doing so, preprocess_input by default is set to 'caffe'
mode but having a closer look at keras vgg16 code, i noticed that weights name
'https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5'
is referring to tensorflow twice. I think that preprocess mode should be 'tf'
.
processed_img = preprocess_input(img, mode='tf')
In my experience in training VGG16 in Keras, the inputs should be from 0 to 255, subtracting the mean [103.939, 116.779, 123.68]
. I've tried transfer learning (freezing the bottom and stack a classifier on top) with inputs centering from -1
to 1
, and the results are much worse than 0..255 - [103.939, 116.779, 123.68]
.