Keras:model.fit函数将y_train读取为(类,样本)而不是(样本,类)

时间:2019-01-16 04:38:16

标签: python-3.x keras deep-learning

我正在使用具有y_train(目标标签)形状(400,14)的keras运行DL模型,其中400是batch_size,而14是类数。

Keras正在将我的输入示例读取为(400,1)而不是(1,14)

model.fit(x_train, [y_l1_train,y_l2_train,y_l3_train,y_l4_train,y_l5_train,y_l6_train,y_l7_train,y_l8_train], validation_data=(x_val, [y_l1_val,y_l2_val,y_l3_val,y_l4_val,y_l5_val,y_l6_val,y_l7_val,y_l8_val]), epochs=1, batch_size=50)

#shapes of my arrays
x_train : (400, 10, 50)
y_l1_train shape : (400, 14)
y_l1_train first element [0 0 0 0 0 0 0 1 0 0 0 0 0 0]

错误消息

You are passing a target array of shape (400, 1) while using as loss `categorical_crossentropy`. `categorical_crossentropy` expects targets to be binary matrices (1s and 0s) of shape (samples, classes).

我已尽一切努力,但无法理解我的错误。请帮忙。

0 个答案:

没有答案