Incompatible shapes: [32,7] vs. [32,24,7] [[{{node mean_absolute_error/sub}}]]

Hi guys, I want to ask my model have an issues when I trying to train the model.

Epoch 1/10

InvalidArgumentError Traceback (most recent call last)
in <cell line: 3>()
3 if name == ‘main’:
----> 5 model = solution_C5()

2 frames
/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/ in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 for t in inputs
59 ]
—> 60 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
61 inputs, attrs, num_outputs)
62 except core._NotOkStatusException as e:

InvalidArgumentError: Graph execution error:

Detected at node mean_absolute_error/sub defined at (most recent call last):
File “/usr/lib/python3.10/”, line 196, in _run_module_as_main
… etc
Incompatible shapes: [32,7] vs. [32,24,7]
[[{{node mean_absolute_error/sub}}]] [Op:__inference_train_function_1291]

This is my code: Google Colab

Hi @Latifaharums, The error message indicates that there is an incompatible shape between the output of your model ( [32, 7]) and target labels ([32, 24, 7]). I have added a few layer to your model to get the desired output.

    model = tf.keras.models.Sequential([
        # Whatever your first layer is, the input shape will be (N_PAST = 24, N_FEATURES = 7)
        # YOUR CODE HERE
        tf.keras.layers.Flatten(input_shape=(N_PAST, N_FEATURES)),
        tf.keras.layers.Dense(128, activation='relu'),
        tf.keras.layers.Dense(128, activation='relu'),
        tf.keras.layers.Dense(N_FUTURE * N_FEATURES),
        tf.keras.layers.Reshape([N_FUTURE, N_FEATURES]),

please refer to this gist for working code example. Thank You.

1 Like

Thank you, It’s works!
*) because my cased is solved, I changed my google collabs access