keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 907 forks source link

Does the mode need to be explicitly set in preprocess_input ? #21

Closed whatdhack closed 6 years ago

whatdhack commented 6 years ago

Wondering if the mode needs to be explicitly set to the backend I am using. For example in VGG16, preprocess_input () seems to pick the 'caffe' mode if I leave it unset , even if though my backend is Tensorflow. How would choosing one over the other would impact inference of the pre-trained VGG16 model ?

taehoonlee commented 6 years ago

@whatdhack, The mode of preprocess_input is not related to the backend. It stands for the library used in the original repository (e.g., VGG: caffe).

whatdhack commented 6 years ago

@taehoonlee , that is a good start. Can put more details in your answers. Your answers are cryptic ( and incomplete) . Looks like you are closing these issues for the sake of closing.

taehoonlee commented 6 years ago

@whatdhack, The mode of preprocess_input is originated from each model's original repository:

If you are trying to deploy the pretrained networks, it is not an option to modify the mode designated for each model. Otherwise, you can choose another mode but it is not so recommended.

whatdhack commented 6 years ago

@taehoonlee , for the pre-trained models (e.g. VGG16) , it needs to be documented what modes are applicable. otherwise it takes time to run experiments and figure out what modes are available. For VGG16 it looks like, the pre-trained model can only handle 'caffe' mode.

A related question is the support across different backend uniform (i.e. does the 'caffe' mode work across TF, PyTorch , CNTK , etc . ) ?

taehoonlee commented 6 years ago

@whatdhack, It doesn't need to be documented because end-users will not directly call imagenet_utils.preprocess_input. And, the mode of preprocess_input is about only normalization and orthogonal to the backend (i.e., caffe mode works on all the backends).

whatdhack commented 6 years ago

@taehoonlee Really ? All the Keras applications examples use preprocess_input . See for yourself - vgg16

taehoonlee commented 6 years ago

@whatdhack, Users will use a wrapper function preprocess_input(x) rather than a imagenet_utils.preprocess_input(x, data_format, mode). The example also presents x = preprocess_input(x).

whatdhack commented 6 years ago

@taehoonlee , I am not sure I can take your word on this one as you did not even know usage of process_input() before I pointed that out. Documentation on preprocess_input() will clarify the confusion.

taehoonlee commented 6 years ago

:)

itsnamgyu commented 3 years ago

Seems legit, but the naming is awfully confusing for someone looking into the code (for exploration or debugging purposes)

@whatdhack, The mode of preprocess_input is originated from each model's original repository:

  • caffe: 'RGB'->'BGR' followed by x -= [103.939, 116.779, 123.68] (e.g., VGG16 and VGG19),
  • tf: x /= 127.5 followed by x -= 1 (e.g., InceptionV3 and InceptionResNetV2),
  • torch: x /= 255. followed by x -= [0.485, 0.456, 0.406] and x /= [0.229, 0.224, 0.225] (e.g., DenseNet121 and DenseNet169).

If you are trying to deploy the pretrained networks, it is not an option to modify the mode designated for each model. Otherwise, you can choose another mode but it is not so recommended.