Search code examples
pythontensorflowkeras

ImportError: cannot import name '_obtain_input_shape' in keras


When I try to import keras_squeezenet I get this error:

Traceback (most recent call last):
  File "C:/Users/belog/drone_sees/train_model.py", line 3, in <module>
    from keras_squeezenet import SqueezeNet
  File "C:\Users\belog\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_squeezenet\__init__.py", line 1, in <module>
    from keras_squeezenet.squeezenet import SqueezeNet
  File "C:\Users\belog\AppData\Local\Programs\Python\Python36\lib\site-packages\keras_squeezenet\squeezenet.py", line 1, in <module>
    from keras.applications.imagenet_utils import _obtain_input_shape
ImportError: cannot import name '_obtain_input_shape'

Here is the import code:

import tensorflow as tf
from keras_squeezenet import SqueezeNet
from keras.optimizers import Adam
from keras.utils import np_utils
from keras.layers import Activation, Dropout, Convolution2D, GlobalAveragePooling2D
from keras.models import Sequential

How to fix it? (I'm using tensorflow==2.6.2, keras==2.6.0, keras-squeezenet==0.4).


Solution

  • Did you tried the new version ? (see : https://github.com/rcmalli/keras-squeezenet)

    you can install it with :
    pip install git+https://github.com/rcmalli/keras-squeezenet.git