keras-team / keras-applications

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

MobileNetV3 #183

Open CRosero opened 4 years ago

CRosero commented 4 years ago

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?

Scottchou7 commented 4 years ago

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)

espetro commented 4 years ago

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
anilsathyan7 commented 4 years ago

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)

lovejing0306 commented 4 years ago

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'
CRosero commented 4 years ago

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

woctezuma commented 4 years ago

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>.

andreped commented 2 years ago

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