Search code examples
reshapevalueerror

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)


compiling the model

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))

An error is reported in the last line:

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)

here is the colab cell link


Solution

  • shape of x_new_B was wrong, fix it with:

    x_new_A, x_new_B = x_test_A[:3], x_test_B[:3]