I'm trying to train an LSTM network with some sequential data with vehicle trajectories, in order to get driver's intention. Here is how I have structures my data:
- 3 positional features per vehicle, with 5 vehicles for each entry. Each one of this features consists of an array of 50 elements.
- The output of my model would be a classification for each individual vehicle intention, which is coded in 3 intentions (turn left, turn right, keep straight). This way we have 3x5=15 (5 vehicles) output columns. This columns are one hot encoded.
In case this clears it up:
The code I'm trying to execute to build and train my model is the following:
input_columns = ['Local_X_0', 'Local_X_dot_0', 'Local_X_ddot_0', 'Local_X_1', 'Local_X_dot_1', 'Local_X_ddot_1', 'Local_X_2', 'Local_X_dot_2', 'Local_X_ddot_2',
'Local_X_3', 'Local_X_dot_3', 'Local_X_ddot_3', 'Local_X_4', 'Local_X_dot_4', 'Local_X_ddot_4']
output_columns = ['Left_Change_0', 'Right_Change_0', 'No_Change_0', 'Left_Change_1', 'Right_Change_1', 'No_Change_1', 'Left_Change_2', 'Right_Change_2', 'No_Change_2',
'Left_Change_3', 'Right_Change_3', 'No_Change_3', 'Left_Change_4', 'Right_Change_4', 'No_Change_4']
X = np.array(df_id_arr[input_columns])
Y = np.array(df_id_arr[output_columns])
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=0)
print ('X_train shape: ', X_train.shape)
print ('X_test shape: ', X_test.shape)
model = tf.keras.Sequential([
tf.keras.layers.LSTM(64, input_shape=(50, 15)), # Assuming 50 timesteps
tf.keras.layers.Dense(15, activation='softmax') # 15 output categories
])
# Compile the model
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# Train the model
history = model.fit(X_train, Y_train, epochs=10, batch_size=32, validation_data=(X_test, Y_test))
But when trying to execute model.fit I get the the following error:
ValueError Traceback (most recent call last)
c:\Users\peroanjo\OneDrive - Universidad Politécnica de Cartagena\Master IA\TFM\Code\LSTM.ipynb Cell 88 in ()
23 model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
25 # Train the model
---> 26 history = model.fit(X_train, Y_train, epochs=10, batch_size=32, validation_data=(X_test, Y_test))
File c:\Users\peroanjo\anaconda3\envs\tf\lib\site-packages\keras\utils\traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.__traceback__)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File c:\Users\peroanjo\anaconda3\envs\tf\lib\site-packages\tensorflow\python\framework\constant_op.py:102, in convert_to_eager_tensor(value, ctx, dtype)
100 dtype = dtypes.as_dtype(dtype).as_datatype_enum
101 ctx.ensure_initialized()
--> 102 return ops.EagerTensor(value, ctx.device_name, dtype)
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).
Any idea on what I'm missing? I think I'm not reshaping my input columns correctly, but I can't seem to get it right. Thank you for your help!
I tried reshaping or converting the dataframe column into a numpy array, but this hasn't helped.
