ValueError: Error when checking target: expected (keras Sequence model layer) to have n dimensions, but got array with shape

ValueError: Error when checking target: expected (keras Sequence model layer) to have n dimensions, but got array with shape

我已经加载图像来训练我的模型识别这些图像中的一个特征。

当我训练我的模型 (model.fit(Xtrain,Ytrain)) 时,我似乎在每个层上都出现了值错误。就好像输入既是 Xtrain 然后是 Ytrain...

ValueError: Error when checking target: expected batch_normalization_24 to have 4 dimensions, but got array with shape (1380, 2)

图片:

Keras 的批量标准化层输出的形状与其输入相同。由于您只有两个标签,因此顺序模型中的最后一层应该生成两个输出。您可以考虑添加一个 Dense 图层,例如:

model.add(Dense(2), activation='relu')

我还建议使用 print(model.summary()) 检查您的模型架构,并确保输入和输出与您的数据集匹配,反之亦然。