Python Keras ValueError:登录和标签必须具有相同的形状((无,32,17)与(无,17))
我正在培训一个多标签分类器(IAM数据集上的手写数字识别器) 以下是我的所有拆分的形状:Python Keras ValueError:登录和标签必须具有相同的形状((无,32,17)与(无,17)),python,tensorflow,keras,tf.keras,Python,Tensorflow,Keras,Tf.keras,我正在培训一个多标签分类器(IAM数据集上的手写数字识别器) 以下是我的所有拆分的形状: >>> X_train.shape, X_val.shape, X_test.shape, Y_train.shape, Y_val.shape, Y_test.shape ((86583, 32, 128, 1), (4558, 32, 128, 1), (4797, 32, 128, 1), (86583, 17), (4558, 17), (4797, 17)) 以下是
>>> X_train.shape, X_val.shape, X_test.shape, Y_train.shape, Y_val.shape, Y_test.shape
((86583, 32, 128, 1),
(4558, 32, 128, 1),
(4797, 32, 128, 1),
(86583, 17),
(4558, 17),
(4797, 17))
以下是目标变量的5个示例:
>>> Y_val[5:10]
array([[68, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0],
[28, 67, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0],
[42, 59, 59, 62, 56, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0],
[73, 61, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0],
[73, 61, 54, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0]], dtype=int32)
(在上面的数组中,每个数字对应于字符和字母表列表中的索引。所有目标向量都填充了零,以匹配最大目标字的大小。)
我在输出层使用“sigmoid”激活,有17个单元,每个单元对应一个可能的输出字符/字母,如下所示
from tensorflow.keras import layers
.
.
layers.Dense(units=17, activation='sigmoid', kernel_initializer='he_uniform', kernel_regularizer='l2')
以“二进制交叉熵”作为损失,用于我的多标签分类问题
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['categorical_accuracy'])
这是我的错误:
编辑1:我的模型的体系结构:
从第二个LSTM层中删除
return\u sequences=True
,这样就可以了你的错误可能来自模型的另一部分,你能完整地显示它吗?你想看我模型的架构吗?是的,请分析它我已经添加了它。查看代码会更简单,但是问题来自第二个LSTM层,您是否设置了return\u sequences=True
?