我正在使用CNN并收到此错误。
r = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=50)
这是代码
以下是错误,请帮助我解决。
---------------------------------------------------------------------------
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.
答案 0 :(得分:0)
这类问题的主要原因是当数据尺寸与模型输出尺寸不匹配时。
要解决此问题,请检查是否正确创建了数据,并且数据是否与模型的最后(最终/输出)图层尺寸匹配。