AttributeError: ‘tuple‘ object has no attribute ‘layer‘
程序员文章站
2022-04-14 09:31:15
...
AttributeError: 'tuple' object has no attribute 'layer'
报错显示:
inbound_layers = nest.map_structure(lambda t: t._keras_history.layer,
AttributeError: ‘tuple’ object has no attribute ‘layer’
而你测试数据的输入输出是正确的,
可能原因:代码中同一个模型添加的网络层来自tensorflow.keras,和keras两个地方。
建议:1.如果使用tensorflow2.0以上版本,使用tenorflow自带的keras来建模。
其中keras相应模块对应在tensorflow.keras的位置参考tf.keras。找到它们,全部更换成tenorflow自带的。
常用的有:
from tensorflow.keras.layers import (
Input, Dense, Conv2D, MaxPooling2D, AveragePooling2D, ZeroPadding2D,
Flatten, Activation, GlobalAveragePooling2D, GlobalMaxPooling2D, add)
# from keras.layers.normalization import BatchNormalization
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.models import Model
from tensorflow.keras import initializers
# from keras.engine import Layer, InputSpec
from tensorflow.keras.layers import Layer, InputSpec
# from keras.engine.topology import get_source_inputs
from tensorflow.keras.utils import get_source_inputs
2. 如果问题没解决,请检查是否更换彻底了。还可以参考论坛*:
上一篇: AttributeError: 'str' object has no attribute 'ecode'
下一篇: AttributeError: 'Series' object has no attribute 'sortlevel'
推荐阅读
-
python编程排除163邮箱发送邮件报错(AttributeError: ‘tuple‘ object has no attribute ‘encode‘)
-
AttributeError: module ‘community‘ has no attribute ‘best_partition‘ 问题解决方法
-
【python】解决AttributeError: module ‘scipy.misc‘ has no attribute ‘toimage‘问题
-
【Tensorflow】Linux下Tensorflow报错:AttributeError: module ‘tensorflow‘ has no attribute ‘xxxx‘
-
AttributeError: 'module' object has no attribute 'main'
-
AttributeError: module 'sklearn' has no attribute 'linear_model'
-
解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
-
解决'DataFrame' object has no attribute 'sort'
-
‘MyObject‘ object has no attribute ‘***‘
-
AttributeError: ‘NoneType‘ object has no attribute ‘origin‘解决办法