我已经创建了一个模型,但由于目标数组的形状和输出形状不匹配,无法运行。我只是想训练它,但不确定如何解决这个错误。
错误信息:
---------------------------------------------------------------------------ValueError Traceback (most recent call last)<ipython-input-9-4c7f3cb9ee70> in <module>() 44 y_train = train_data[10000:] 45 ---> 46 fitModel = model.fit(x_train, y_train, epochs=5, batch_size=512, validation_data=(x_val, y_val), verbose=1) 47 48 result = model.evaluate(test_data, test_labels)3 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) 739 raise ValueError('A target array with shape ' + str(y.shape) + 740 ' was passed for an output of shape ' + str(shape) +--> 741 ' while using as loss `' + loss_name + '`. ' 742 'This loss expects targets to have the same shape ' 743 'as the output.')ValueError: A target array with shape (15000, 250) was passed for an output of shape (None, 1) while using as loss `binary_crossentropy`. This loss expects targets to have the same shape as the output.
我应该得到准确率和执行时间的输出。我尝试更改输出层的数值,但对我来说完全不起作用。
我的代码:
回答:
更改
y_val = train_data[:10000]y_train = train_data[10000:]
为
y_val = train_labels[:10000]y_train = train_labels[10000:]