在运行其他开源keras项目时,遇到了一些问题:

1、在导入_obtain_input_shape时

from keras.applications.imagenet_utils import _obtain_input_shape

出现错误如下:

ImportError: cannot import name '_obtain_input_shape'

原因是在keras 2.2.2中,keras.applications.imagenet_utils模块不再有_obtain_input_shape方法。解决方法:
将导入语句修改如下

from keras_applications.imagenet_utils import _obtain_input_shape
  • 重点:使用keras_applications代替keras.applications

2、在使用_obtain_input_shape方法时出现错误:

_obtain_input_shape() got an unexpected keyword argument 'include_top'

原因是我们的调用中使用了

input_shape = _obtain_input_shape(input_shape,
                                  default_size=224,
                                  min_size=32,
                                  data_format=K.image_data_format(),
                                  include_top=include_top or weights)

而在keras 2.2.2中函数 _obtain_input_shape() 的形式为:

def _obtain_input_shape(input_shape,
                        default_size,
                        min_size,
                        data_format,
                        require_flatten,
                        weights=None):

自然没有include_top属性。因此把调用中的include_top改为require_flatten即可

转载于:https://www.cnblogs.com/sssaltyfish/p/10656766.html

Logo

昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链

更多推荐