Reputation: 141
I had a question about input preprocessing in Keras.
If you look at the pre-processing source code
https://github.com/keras-team/keras/blob/master/keras/applications/imagenet_utils.py#L149
the default preprocessing mode appears to be Caffe. Their snippet of code uses it directly too
https://github.com/fchollet/deep-learning-models
My question is, why is Keras not checking Keras.backend() to find the correct mode and do the pre-processing appropriately? Is this likely a bug?
My backend is tensorflow, so I am wondering if running the code directly as provided in their example is a good idea.
Thanks
Upvotes: 1
Views: 583
Reputation: 86600
Each model has its own preprocessing.
Some take the preprocessing from the code you've shown (where it's clearly declared with mode='caffe'
). Some models declare its own preprocessing. Always import the preprocessing function from the same module as the model you're trying to instance, so you import the right function.
The mode is suited to how the model was built. If a model was built with the caffe
mode, then it will only work well with input following that specification.
The same is valid for all other modes.
Tensorflow or Theano?
It doesn't really matter. Keras does handle those formats properly.
As you can see in that source code, keras has the K.image_data_format()
, that is taken from your default configurations (you find your default configuration, which is usually channels_last
, in the keras.json
file).
Keras will handle the format correctly, no matter if you're using Theano or Tensorflow. I suggest, unless you have a reason or a clear preference, that you leave the configs as they are with channels_last
. This makes it easier to integrate convolution layers with others and with loss functions. Everything in keras tend to work on the last axis, so, leave the channels at the last position as well to avoid extra work.
Upvotes: 1