Search code examples
tensorflowkerastf.kerasmobilenet

MobileNetV2 in tf.keras. Many links but no useful information


I want to use mobileNetV2 with tf.keras.

If look on the tensorflow website for keras applications I find

mobilenet = tf.keras.applications.MobileNetV2()

If I try to import MobileNetV2 from tensorflow.keras.applications import MobileNetV2

I get an error:

ImportError: cannot import name 'MobileNetV2'

If I check the Keras2 webside I do find only a handful of applications. The mobileNetV2 (or V1) is not one of them. But the V1 model can be loaded and used.

If I follow the link on the tensorflow.keras website, it brings me to the classic keras webside which in my opinion is Keras1 not keras2, am I wrong? Also stating MobileNetV2, which apparently is not implemented. So I guess the link is wrong.

This is all confusing to me. Probably, this is all due to due to the switch to tf.keras, or am mixing things up?

To formulate my question more concrete: Is there a predefined, usable MobileNetV2 application with tf.keras or do I have to implement it by hand?

Thanks

edit: TF version 1.10.


Solution

  • You are using this link for your reference for MobileNetV2 but that is documented for tensorflow version 1.13. And you are using tensorflow version 1.10. In this you can only find MobileNet not MobileNetV2.

    For tensorflow version 1.10, you can import like this,

    from tensorflow.keras.applications.mobilenet import MobileNet

    or

    model = tf.keras.applications.MobileNet()

    If you want to check what are the model are included in tf.keras.applications, you can check github repo with appropriate tensorflow version.

    If you want to use MobileNetV2, please upgrade your tensorflow version and you can use as it mentioned in the documentation.