AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

错误信息:

Keras AttributeError 'NoneType' object has no attribute '_inbound_nodes'

原因:

只要使用Model,就必须保证该函数内全为layer而不能有其他函数,如果有其他函数必须用Lambda封装为layer。

比如现在用到concat这个很基本的操作:

model = Model(inputs=input, outputs=output)  # 提示报错
def model()
    ……
    concat_sc = tf.concat([sc1, sc2], axis=-1)  # 意图使用concat拼接sc1和sc2
    ……

会提示报错,这是因为tf.concat是函数而不是layer,点进去以后的在array_ops.py文件中的定义如下

@tf_export("concat")
@dispatch.add_dispatch_support
def concat(values, axis, name="concat"):
  """Concatenates tensors along one dimension.

又因为model函数中不允许除了layer以外的其他函数出现,所以报错。以concat为例,可改为如下形式

concat_sc = Concatenate(axis=-1)([sc1, sc2])

成功运行,这是因为Concatenate本身是tf定义的layer,点进去以后merge.py文件中如下:

class Concatenate(_Merge):
    """Layer that concatenates a list of inputs.

    It takes as input a list of tensors,
    all of the same shape except for the concatenation axis,
    and returns a single tensor, the concatenation of all inputs.

    # Arguments
        axis: Axis along which to concatenate.
        **kwargs: standard layer keyword arguments.
    """

 

 

参考文献:

[1] https://www.bbsmax.com/A/B0zqbZxQJv/

[2] https://tieba.baidu.com/p/6126995344?red_tag=3008239076

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值