ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 6 but here input with shape (None, 8)
ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 6 but here input with shape (None, 8)
编译模型
model.compile(loss="mse", loss_weights=[0.9, 0.1], optimizer=keras.optimizers.SGD(lr=1e-3))
history = model.fit((x_train_A, x_train_B), (y_train, y_train), epochs=10,
validation_data=((x_valid_A, x_valid_B), (y_valid, y_valid)))
total_loss, main_loss, aux_loss = model.evaluate((x_test_A, x_test_B), (y_test, y_test))
y_pred_main, y_pred_aux = model.predict((x_new_A, x_new_B))
最后一行报错:
ValueError: Input 0 of layer dense_4 is incompatible with the layer: expected axis -1 of input shape to have value 6 but received input with shape (None, 8)
x_new_B 的形状是错误的,修复它:
x_new_A, x_new_B = x_test_A[:3], x_test_B[:3]
编译模型
model.compile(loss="mse", loss_weights=[0.9, 0.1], optimizer=keras.optimizers.SGD(lr=1e-3))
history = model.fit((x_train_A, x_train_B), (y_train, y_train), epochs=10,
validation_data=((x_valid_A, x_valid_B), (y_valid, y_valid)))
total_loss, main_loss, aux_loss = model.evaluate((x_test_A, x_test_B), (y_test, y_test))
y_pred_main, y_pred_aux = model.predict((x_new_A, x_new_B))
最后一行报错:
ValueError: Input 0 of layer dense_4 is incompatible with the layer: expected axis -1 of input shape to have value 6 but received input with shape (None, 8)
x_new_B 的形状是错误的,修复它:
x_new_A, x_new_B = x_test_A[:3], x_test_B[:3]