keras-applications icon indicating copy to clipboard operation
keras-applications copied to clipboard

MobileNetV3

Open CRosero opened this issue 4 years ago • 7 comments

I want to do transfer learning using MobileNetV3. I see on here that MobileNetV3 is available, but I don't see it either in the Keras website or on TF. Why is this?

CRosero avatar May 04 '20 16:05 CRosero

I think they haven't updated "mobilenet_v3.py" file in keras and TF. But I successsfully import MobileNetV3Small in my keras project.

  1. Copy "mobilenet_v3.py" file and put it in your local "keras_applications" folder. For example I use anaconda: C:\user\AppData\Local\conda\conda\envs\Your Environment Name\Lib\site-packages\keras_applications.

  2. from keras_applications.mobilenet_v3 import MobileNetV3Small

  3. model = = MobileNetV3Small( weights='imagenet', include_top=False, input_shape=(128, 128, 3), backend=keras.backend, layers=keras.layers, models=keras.models, utils=keras.utils)

Scottchou7 avatar May 11 '20 07:05 Scottchou7

Another way to do what @Scottchou7 does is:

  1. Uninstall your local keras-applications (pip uninstall keras-applications).
  2. Then install it via git (pip install git+https://github.com/keras-team/keras-applications.git@master).
  3. For an unknown reason, MobileNetV3 is only directly visible from keras_applications submodule:
from keras.applications.keras_applications import keras_applications
from keras_applications.mobilenet_v3 import MobileNetV3

espetro avatar May 11 '20 10:05 espetro

Mobilenetv3 is available in latest keras version; but it's not available officially with tf.keras as of now.

First install latest keras-applications as mentioned by @espetro . Now, to use mobilenetv3(large) with tf.keras/tf2 for transfer learning:

mnv3=keras.applications.keras_applications.mobilenet_v3.MobileNetV3Large(input_shape=(224, 224, 3),alpha=1.0, minimalistic=True, include_top=False, weights='imagenet', backend=tf.keras.backend, layers=tf.keras.layers, models=tf.keras.models, utils=tf.keras.utils)

anilsathyan7 avatar May 19 '20 08:05 anilsathyan7

Another way to do what @Scottchou7 does is:

  1. Uninstall your local keras-applications (pip uninstall keras-applications).
  2. Then install it via git (pip install git+https://github.com/keras-team/keras-applications.git@master).
  3. For an unknown reason, MobileNetV3 is only directly visible from keras_applications submodule:
from keras.applications.keras_applications import keras_applications
from keras_applications.mobilenet_v3 import MobileNetV3

I use you way, but is wrong

>>> from keras.applications.keras_applications import keras_applications
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'keras.applications.keras_applications'

lovejing0306 avatar Jun 03 '20 11:06 lovejing0306

Seeing as how sadly there has been no response from the Keras team regarding this, I contacted TF and this is the response I received

CRosero avatar Jun 10 '20 11:06 CRosero

For reference, the solution offered in the Tensforflow thread consists in:

!pip install tf-nightly

Then:

import tensorflow as tf

tf.keras.applications.MobileNetV3Small

returns <function tensorflow.python.keras.applications.mobilenet_v3.MobileNetV3Small>.

woctezuma avatar Aug 22 '20 22:08 woctezuma

Has anyone here tried to use MobileNetV3 in keras.applications with TimeDistributed?

I am having some challenges (Python 3.8.10, keras-nightly==2.10.x).

To reproduce error:

import keras
from keras.applications import MobileNetV2, MobileNetV3Small, ConvNeXtSmall

input_ = keras.layers.Input(shape=(8, 224, 224, 3))

# base_model  = MobileNetV2(include_top=True, input_shape=(224, 224, 3))
base_model = MobileNetV3Small(include_top=True, input_shape=(224, 224, 3))

output = keras.layers.TimeDistributed(base_model)(input_)
model = keras.Model(inputs=input_, outputs=output)

More details on error, logs, and other stuff can be seen here: https://github.com/keras-team/tf-keras/issues/575

andreped avatar Jun 05 '22 20:06 andreped