ImportError:在Colab中使用Keras时,无法导入名称“ _obtain_input_shape”

问题描述

我正在尝试在Colab中实现Inception v3,并且这个问题不断出现。我知道这是一个普遍的问题,但是其中的 one 个似乎都无法解决错误。一些值得一提的:

改变 from keras.applications.imagenet_utils import _obtain_input_shapefrom keras_applications.imagenet_utils import _obtain_input_shape 或将Keras从2.2.2降级到2.2.0或坦率地说其他任何版本,我都无法胜过。 有谁知道可能导致此问题的最新信息?

解决方法

请查看以下解决方案。

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

干杯!