【问题标题】:ImportError: cannot import name '_obtain_input_shape' when using Keras in ColabImportError:在 Colab 中使用 Keras 时无法导入名称“_obtain_input_shape”
【发布时间】:2020-09-14 02:46:57
【问题描述】:

我正在尝试在 Colab 中实施 Inception v3,但这个问题不断出现。这是一个常见问题,我知道,但没有的建议似乎解决了这个错误。一些值得一提的:

改变 from keras.applications.imagenet_utils import _obtain_input_shapefrom keras_applications.imagenet_utils import _obtain_input_shape 或将 Keras 从 2.2.2 降级到 2.2.0 或坦率地说任何其他版本,我就是无法击败这个东西。 有没有人知道可能导致这种情况的最新信息?

【问题讨论】:

    标签: python keras import


    【解决方案1】:

    请看下面的解决方案。

    1.修改导入语句

    更改导入语句

    from keras.applications.imagenet_utils import _obtain_input_shape
    

    以下语句

    from keras_applications.imagenet_utils import _obtain_input_shape
    

    2。使用 require_flatten=include_top 的参数替换 include_top=include_top

      # Determine the proper input shape
        input_shape = _obtain_input_shape(
            input_shape,
            default_size=299,
            min_size=139,
            data_format=K.image_data_format(),
            # -include_top=include_top
            require_flatten=include_top)
    

    3.将 keras_applications 库放入你的工作目录。您可以通过以下链接下载库。

    https://github.com/keras-team/keras-applications/tree/master/keras_applications

    干杯!

    【讨论】:

      猜你喜欢
      • 2018-08-13
      • 2019-04-16
      • 2020-11-28
      • 1970-01-01
      • 2018-01-19
      • 2018-05-31
      • 1970-01-01
      • 2021-05-24
      • 2017-02-23
      相关资源
      最近更新 更多