在使用"二进制交叉熵"作为损失的同时,通过具有形状(687、809)的目标阵列以获得形状(无,25)



我在使用CNN时出现了这个错误。

r = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=50)

这是代码

下面是错误,plz帮我解决它。

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-82-0b7c2e7fa2ce> in <module>()
----> 1 r = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=50)
6 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training_utils.py in check_loss_and_target_compatibility(targets, loss_fns, output_shapes)
808           raise ValueError('A target array with shape ' + str(y.shape) +
809                            ' was passed for an output of shape ' + str(shape) +
--> 810                            ' while using as loss `' + loss_name + '`. '
811                            'This loss expects targets to have the same shape '
812                            'as the output.')
ValueError: A target array with shape (687, 809) was passed for an output of shape (None, 25) while using as loss `binary_crossentropy`. This loss expects targets to have the same shape as the output.
此类问题的主要原因是数据维度与模型输出维度不匹配。

要解决此问题,请检查您是否正确创建了数据,并且它是否与模型的最后一个(最终/输出(图层尺寸相匹配。

最新更新