question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot import name relu6

See original GitHub issue
Using TensorFlow backend.
Traceback (most recent call last):
  File "train.py", line 9, in <module>
    from mobilenet_v2 import MobileNetv2
  File "/home/wq/MobileNetV2/mobilenet_v2.py", line 13, in <module>
    from keras.applications.mobilenet import relu6, DepthwiseConv2D
ImportError: cannot import name relu6

There seems to be some name changes since you write the script.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveIbcommented, Oct 25, 2018

I have tried with CustomObjectScope({‘relu6’: keras.layers.ReLU(6.),‘DepthwiseConv2D’: keras.layers.DepthwiseConv2D}): model = load_model(‘****.hdf5’)

but I got the following error: ValueError: axes don’t match array

my TF is 1.11 my keras is 2.2.4, python 2.7. Im trying to convert the model on the same machine and environment i have trained on. any suggestions?

1reaction
jmherrmanncommented, Jul 23, 2018

Had the same issue, this worked for me:

from keras import models from keras_applications import mobilenet_v2

model = models.load_model(path_model_checkpoint, custom_objects={‘relu6’: mobilenet_v2.relu6}) model.summary()

Had the idea for the fix from here: https://github.com/keras-team/keras/commit/468f080c98f06780c950e5a78c9eeeaf9fff002e

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: cannot import name 'relu6' - Stack Overflow
See this answer from GitHub. You need to use a CustomObjectScope to import relu6 .
Read more >
How to use mobilenet layer/module in the new version of Keras
from keras.applications.mobilenet import _conv_block. Then I have the problem that : ImportError: cannot import name '_conv_block'
Read more >
tf.keras.applications.mobilenet_v2.MobileNetV2 - TensorFlow
Float, larger than zero, controls the width of the network. This is known as the width multiplier in the MobileNetV2 paper, but the...
Read more >
Source code for torchvision.models.mobilenetv2 - PyTorch
import warnings from typing import Callable, Any, Optional, List import torch from torch import Tensor from torch import nn from .
Read more >
Running Keras models on iOS with CoreML - PyImageSearch
Apple's CoreML development team really couldn't have made it any easier ... import necessary packages from keras.models import load_model ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found