keras中遇到的错误

在运行其他开源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即可

  • 6
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值