keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.97k stars 19.47k forks source link

Preprocessing layer for MobileNetV3 is hidden when looking at the summary of the model #14637

Closed KapitanKabzon closed 3 years ago

KapitanKabzon commented 3 years ago

When using the Preprocess layer for MobilenetV2 the layer is showing up in the .summary() of the model. If using the Preprocess layer for MobilenetV3 the layer is not showing up in the .summary() of the model. Here is a link to the Notebook showcasing the problem: https://github.com/KapitanKabzon/EiT_Metal/blob/master/MobileNet3Problem.ipynb .

v-tuenv commented 3 years ago

I have had a problem too. Have you sloved yet?

ymodak commented 3 years ago

The tf.keras.applications.mobilenet_v3.preprocess_input function is just a placeholder and does not do anything. See https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/keras/applications/mobilenet_v3.py#L555-L574

The preprocessing logic has been included in the mobilenet_v3 model implementation.

yingshaoxo commented 3 months ago

Have you guys considered those people who uses tensorflowhub?

They do things like:

import tensorflow as tf
import tensorflow_hub as hub

version_fn = getattr(tf.keras, "version", None)
if version_fn and version_fn().startswith("3."):
  import tf_keras as keras
else:
  keras = tf.keras

def get_mobilenet_model():
    mobilenet_model = keras.models.Sequential([
            hub.KerasLayer("https://www.kaggle.com/models/google/mobilenet-v3/TensorFlow2/small-075-224-feature-vector/1", trainable=False),
    ])
    mobilenet_model.build([None, 224, 224, 3])
    return mobilenet_model

They have to manally call a function before they feed a image to model now:

def the_tf_mobile_net_image_preprocess(data):
    # to 0 and 1, a float, it seems like
    data /= 127.5
    data -= 1.
    return data

Otherwise, they would get wrong result.


The document page for mobilenet has wrong example code:

https://www.kaggle.com/models/google/mobilenet-v3/tensorFlow2/large-100-224-feature-vector