1

Keras application has pretrained models with saved weights. These weights are independent of the nature of "preprocessing_input" on images it was trained with. Now when I submit my set of images for feature extraction depending upon my backend and mode, imagenet_utils will preprocessing_input and the iamge array processed will be either pixels scaled between -1 and 1 OR each color channel zero-centered with respect to the ImageNet dataset. Wouldn't prediction/feature extraction result in different results if I followed process outlined as say "Extract features with VGG16" in https://keras.io/applications/ ???

  • I do believe so... and I'm not sure the preprocessing should change depending on your backend, only on the mode you select. The default is 'caffe', from [their code](https://github.com/fchollet/keras/blob/master/keras/applications/imagenet_utils.py). So, I think you should do some tests before going for real cases. Up to now I used to think these models would take values from 0 to 1. – Daniel Möller Oct 02 '17 at 17:49
  • I would love to know which is the right preprocessing to be used. – Daniel Möller Oct 02 '17 at 21:00

1 Answers1

1

No, weights are not independent from how inputs are preprocessed. If you use different preprocessing methods, the final weights will be different.

And as you say, if you use different preprocessing, then the features would be different. You should only use the preprocessing that was used for training the network.

This is why each network's python module contains a preprocess_input method that you can import to perform preprocessing. Each method might do different things depending on how the network is trained and what kind of preprocessing was used.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140
  • Maybe you misunderstood me. I am not training the model from scratch. I am using VGG16 with weights='vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5'. My dilemma is: These weights 'vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5' will work with preprocessing_input = **pixels scaled between -1 and 1** OR **each color channel zero-centered** which depends on keras.backend of my installation and mode that I may choose. – Shirish Ranade Oct 03 '17 at 10:55
  • @ShirishRanade That is not what your question is asking,you also introduced new information, if you are using keras.applications then you have to use the appropriate preprocess_input method from the same module. It does not depend on your keras backend. – Dr. Snoopy Oct 03 '17 at 13:46
  • I guess I will conduct some tests to see if by specifying mode='tf' and mode='caffe' I get the same results. – Shirish Ranade Oct 03 '17 at 18:27