ImportError: cannot import name '_obtain_input_shape' from keras

前端 未结 5 2239
猫巷女王i
猫巷女王i 2020-12-16 10:05

In Keras,

I\'m trying to import _obtain_input_shape as follows:

from keras.applications.imagenet_utils import _obtain_input_shape


        
相关标签:
5条回答
  • 2020-12-16 10:42

    keras_applications.imagenet_utils is deprecated

    Traceback (most recent call last): File "inception_v3.py", line 36, in from keras_applications.imagenet_utils import _obtain_input_shape ModuleNotFoundError: No module named 'keras_application

    0 讨论(0)
  • 2020-12-16 10:46

    You don't have to downgrade Keras 2.2.2.

    In Keras 2.2.2 there is no _obtain_input_shape method in the keras.applications.imagenet_utils module. You can find it under keras-applications with the modul name keras_applications (underscore).

    So you don't have to downgrade your Keras to 2.2.0 just change:

    from keras.applications.imagenet_utils import _obtain_input_shape
    

    to

    from keras_applications.imagenet_utils import _obtain_input_shape
    
    0 讨论(0)
  • 2020-12-16 10:49

    I have found a method that works well. You just use

    from keras_applications.imagenet_utils import _obtain_input_shape 
    

    Notice: It is keras_applications instead of keras.application.

    0 讨论(0)
  • 2020-12-16 10:56

    This issue occured because of the version of keras.

    In my case, I was downgrade keras 2.2.2 to 2.2.0, and the problem was solved.

    0 讨论(0)
  • for keras 2.2.4: Change the line like below to make it work.

    from keras_applications.imagenet_utils import _obtain_input_shape
    

    Note: It is importing from keras_applications and does not from keras.applications as before.

    0 讨论(0)
提交回复
热议问题