解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
程序员文章站
2022-07-13 11:57:15
...
背景
在用Keras的时候遇到了这个报错
AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
原因
原来是对Tensor操作的方法用错了,做了一个扩展操作,将一个2D的张量扩展成一个3D的张量
使用了K.repeat()的方法,这个方法返回的是一个Tensor,而不是一个Layer,当然没有入节点inbound_nodes这个属性
正确使用
这里应该用RepeatVector这个层,具体用法是
RepeatVector层keras.layers.core.RepeatVector(n)
RepeatVector层将输入重复n次
参数
n:整数,重复的次数
输入shape
形如(nb_samples, features)的2D张量
输出shape
形如(nb_samples, n, features)的3D张量
扩展
同样如果要对Tensor的某一个维做sum操作,也不能用K.sum,而应该用一个Lambda层
推荐阅读
-
解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
-
AttributeError: ‘NoneType‘ object has no attribute ‘origin‘解决办法
-
AttributeError: ‘set‘ object has no attribute ‘append‘解决办法
-
使用torchsummary时报错AttributeError: ‘list‘ object has no attribute ‘size‘
-
运行sqlmap提示AttributeError: 'module' object has no attribute 'HTTPSHandler'解决方法
-
Python 爬取网页信息 AttributeError :’NoneType’ object has no attribute ’attrs’
-
python报错:AttributeError: 'module' object has no attribute 'xfeatures2d'
-
wsgiref报错AttributeError: 'NoneType' object has no attribute 'split'
-
解决 ERROR oslo_service.periodic_task AttributeError: ‘ComputeNode‘ object has no attribute ‘nodename‘
-
反向关联报错AttributeError: ‘ForeignKey‘ object has no attribute ‘rel‘从django源码找答案~