4

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.

Florida Man
  • 2,021
  • 3
  • 25
  • 43
  • 3
    you can import MobileNetV2 like this, `from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2`. And which tensorflow version you are using? – Krunal V May 02 '19 at 13:05
  • Hy kruxx, thanks. ... apparently it cannot find the `tensorflow.keras.applications.mobilenet_v2` module. I googled this but could not find this import. do you maybe have a link for me? thanks a lot for your help. (TF:1.1) – Florida Man May 02 '19 at 13:13

2 Answers2

4

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.

Krunal V
  • 1,255
  • 10
  • 23
  • 1
    Dear krux, thanks a lot. I use anaconda. And updated tensorflow not noticing that it did not update to the latest version of TF. Thanks for pointing this out. – Florida Man May 02 '19 at 13:33
2

For Google Colab and latest version of tensorflow, Use: !pip install keras_applications .. will install keras-applications >= 1.0.8 For tensorflow version >= 2.5.0, use from keras.applications.mobilenet_v2 import MobileNetV2

Kaushik
  • 21
  • 1