我试图用车辆轨迹的一些连续数据来训练LSTM网络,以了解驾驶员的意图。以下是我的数据结构:
-
每辆车有3个位置特征,每个入口有5辆车。每个特征都由50个元素组成。
-
我的模型的输出将是每个单独车辆意图的分类,该分类编码为3个意图(左转、右转、直行)。这样我们就有3x5=15(5辆车)输出列。这些列是热编码的。
若此情况得以解决:
我试图执行的构建和训练模型的代码如下:
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))
但是在尝试执行model.fit时,我得到了以下错误:
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).
知道我错过了什么吗?我认为我没有正确地重塑我的输入列,但我似乎无法做到正确。谢谢你的帮助!
我尝试将dataframe列重新整形或转换为numpy数组,但这没有帮助。