Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MobileNetV2 with undefined backend, layers and models #54

Open
christian-rauch opened this Issue Nov 30, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@christian-rauch
Copy link

christian-rauch commented Nov 30, 2018

When instantiating MobileNetV2 without special kwargs I get the error:

Using TensorFlow backend.
Traceback (most recent call last):
[...]
  File "/usr/local/lib/python2.7/dist-packages/keras_applications/mobilenet_v2.py", line 267, in MobileNetV2
    if backend.image_data_format() == 'channels_first':
AttributeError: 'NoneType' object has no attribute 'image_data_format'

because backend is undefined (None).

Explicitly defining the backend via kwargs MobileNetV2(..., backend=keras.backend) solves the issue.

It is not obvious to me, why get_submodules_from_kwargs is not using the keras defaults (in this case keras.backend) since there is no reason to mix backends in one instance of keras.

Why does one have to set the backend, layers and models explicitly when using MobileNetV2?

@christian-rauch christian-rauch changed the title MobileNetV2 with undefined backend MobileNetV2 with undefined backend, layers and models Nov 30, 2018

@Luckick

This comment has been minimized.

Copy link

Luckick commented Dec 6, 2018

Thank you for your sharing!
Do you have any idea what would be appropriate to set up keras_utils in kwargs?
Thank you for your help!

@christian-rauch

This comment has been minimized.

Copy link
Author

christian-rauch commented Dec 6, 2018

Are there any other options than Keras?

Because get_submodules_from_kwargs uses the global variables _KERAS_BACKEND, _KERAS_LAYERS, _KERAS_MODELS and _KERAS_UTILS they should simply be set to keras.backend etc.

Currently they are define to None:

_KERAS_BACKEND = None
_KERAS_LAYERS = None
_KERAS_MODELS = None
_KERAS_UTILS = None

@Luckick

This comment has been minimized.

Copy link

Luckick commented Dec 7, 2018

By setting: backend=keras.backend,
layers = keras.layers, models = keras.models, utils = keras.utils as kwargs,
problem solved.
Thank you.

@taehoonlee

This comment has been minimized.

Copy link
Member

taehoonlee commented Dec 7, 2018

@christian-rauch, The keras-applications is designed to work with two backends: keras and tf.keras. Thus, if you want to use the keras-based applications, you should import modules from keras NOT keras-applications directly. The official example is:

from keras.applications.resnet50 import ResNet50
model = ResNet50(weights='imagenet')
@christian-rauch

This comment has been minimized.

Copy link
Author

christian-rauch commented Dec 7, 2018

@taehoonlee If the official keras applications use keras.applications as namespace, I don't see the reason why keras cannot be the default in keras_applications. Similar to how keras manages its backends (tensorflow, theano, cntk), keras_applications should have a user-configurable backend with a sensible default setting.

Using keras.applications for importing models that are defined in a different python package (that needs to be installed manually) also entails that the namespaces between both packages always need to be in sync. E.g. a new model in keras_applications will need its counterpart boilerplate definition in keras.applications before it can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.