The model was fuctioinnal with only one output, now I try to use multi output forcasting one timestep, but got this error:
Epoch 1/10
2025-11-04 16:20:09.341769: W tensorflow/core/framework/op_kernel.cc:1844] INVALID_ARGUMENT: required broadcastable shapes
InvalidArgumentError: Graph execution error:
Detected at node compile_loss/mse/sub defined at (most recent call last):
File "/databricks/python_shell/scripts/db_ipykernel_launcher.py", line 52, in <module>
My input data are build this way from a pandas df:
train_data = features.loc[0 : train_split - 1]
val_data = features.loc[train_split:]
train_data.shape
(500000, 10)
x_train = train_data.iloc[:, :6].values
y_train1 = train_data.iloc[:,6].values
y_train2 = train_data.iloc[:,7].values
y_train3 = train_data.iloc[:,8].values
y_train4 = train_data.iloc[:,9].values
combined_targets_train = np.stack([y_train1, y_train2, y_train3, y_train4], axis=-1)
dataset_train = keras.preprocessing.timeseries_dataset_from_array(
x_train,
combined_targets_train,
sequence_length=sequence_length,
sampling_rate=step,
batch_size=batch_size,
shuffle=True,
)
for batch in dataset_train.take(1):
inputs, targets = batch
print("Input shape:", inputs.numpy().shape)
print("Target shape:", targets.numpy().shape)
Input shape: (16, 120, 6)
Target shape: (16, 4)
In the same way, validation set was build and got this shape Input shape: (16, 120, 6) Target shape: (16, 4)
The model simplify version:
inputs_seq = keras.layers.Input(shape=(120, 6), name='meteo')
lstm_out = LSTM(10, return_sequences=True)(inputs_seq )
...
output_surfrun = Dense(1, activation='linear', name='pred_surf_runoff')(lstm_out )
output_subsurf = Dense(1, activation='linear', name='pred_sub_surf_runoff')(lstm_out )
output_evap = Dense(1, activation='linear', name='pred_evapo')(lstm_out )
output_een = Dense(1, activation='linear', name='pred_een')(lstm_out )
model = keras.Model(inputs=inputs_seq, outputs=[output_surfrun, output_subsurfacerun, output_evap, output_een], name='model_multi_heads')
model.compile(optimizer=keras.optimizers.Adam(learning_rate=learning_rate), loss="mse")
history = model.fit(
dataset_train,
epochs=10,
validation_data=dataset_val
)
I make many shape validation but don't find what the problem.