Vehicle trajectory prediction method and system based on spatiotemporal attention mechanism
By representing the road network as a directed graph and combining it with the Transformer model to extract spatiotemporal features, the problem of inaccurate long-term sequence prediction in existing methods is solved, and high-precision vehicle trajectory prediction in urban road networks is achieved.
Patent Information
- Application Number
- CN202311106443.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-30
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2043-08-30
AI Technical Summary
Existing vehicle trajectory prediction methods have difficulty achieving long-term sequence prediction in urban road networks, and because they do not consider the connection relationship between different road sections, the prediction accuracy is low.
The road segments in the road network are represented as directed graphs. The spatial features are obtained through the graph attention network, and the temporal features are extracted by combining the Transformer model. A trajectory prediction model based on the spatiotemporal attention mechanism is constructed, and the embedding layer, graph attention encoding layer, Transformer encoding layer and decoding layer are used for feature extraction and prediction.
The accuracy and continuity of vehicle trajectory prediction are improved, and the future movement trajectory of the vehicle can be predicted more accurately, which is suitable for complex urban road networks.
Smart Images

Figure CN117171582B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of vehicle trajectory prediction, and specifically relates to a vehicle trajectory prediction method and system based on a spatiotemporal attention mechanism. Background Art
[0002] Vehicle trajectory prediction has wide applications in traffic management, autonomous driving, security monitoring, and other fields, and is a key technology for achieving intelligent transportation. In target tracking scenarios, vehicle trajectory prediction can be combined with target detection and tracking technologies to provide real-time predictions of the target vehicle's position, speed, acceleration, and other information, enabling automatic tracking of the target vehicle.
[0003] During target tracking, the target may escape from the monitoring range due to various reasons such as occlusion, changes in illumination, and sudden changes in movement patterns. Since tracking is based solely on sensors such as cameras and radars, the monitoring range is limited and the movement of the target vehicle cannot be fully understood. The present invention monitors the target vehicle based on GPS positioning technology, records a large amount of spatiotemporal trajectory data, and dynamically predicts the vehicle's future path. The present invention focuses on vehicle trajectory prediction on road networks. By monitoring the trajectory of target vehicles on the road in real time, its future trajectory is predicted based on historical trajectories, and target vehicles that have escaped the monitoring field of view are promptly retrieved to achieve continuous tracking of moving targets.
[0004] Vehicle trajectory prediction methods are typically based on traditional machine learning and deep learning methods. Traditional machine learning methods include support vector machines, decision trees, and random forests. These methods typically use features such as historical trajectories and environmental information as input to predict the future trajectory of the target vehicle. While they generally achieve high prediction accuracy, they require manual feature design and are not easily scalable to complex scenarios. With the advancement of deep learning technology, deep learning-based vehicle trajectory prediction methods have gradually become mainstream. These methods use models such as convolutional neural networks, long short-term memory networks, and self-attention networks to model historical trajectories and predict the future trajectory of the target vehicle. Compared with traditional methods, deep learning-based methods do not require manual feature design, can automatically learn feature representations, and achieve higher prediction accuracy.
[0005] Currently, existing methods primarily focus on predicting the next location, making such models unsuitable for long-term sequence prediction. Furthermore, because they fail to consider the connectivity between different road segments, the accuracy of the segment sequences predicted using existing methods is low. Therefore, vehicle trajectory prediction in urban road networks remains a challenging problem. Summary of the Invention
[0006] Based on the above-mentioned shortcomings and deficiencies in the prior art, the purpose of the present invention is to provide a vehicle trajectory prediction method and system based on a spatiotemporal attention mechanism. First, the road segments in the road network are represented as a directed graph, the vehicle trajectories are mapped into a sequence of road segments in the road network, and the sequence is divided and input into the model. Then, the embedding layer maps the road segments into spatial vectors, and the input segments and adjacent segments constitute a local road network graph. The spatial features in the road network are obtained through the graph attention network. Transformer assigns different weights to the input sequence and extracts the temporal features therein. Finally, combined with the local road network structure graph, the output sequence is filtered to obtain a continuous trajectory sequence to achieve vehicle trajectory prediction.
[0007] In order to achieve the above-mentioned object of the invention, the present invention adopts the following technical solutions:
[0008] A vehicle trajectory prediction method based on spatiotemporal attention mechanism includes the following steps:
[0009] S1, collecting a vehicle trajectory data set and preprocessing the vehicle trajectory data of the vehicle trajectory data set;
[0010] S2. Mapping the pre-processed vehicle trajectory data using a map matching algorithm to obtain a road segment sequence, and then segmenting the road segment sequence to obtain several sub-road segment sequences;
[0011] The length of each sub-segment sequence is L, the first K parts of the sub-segment sequence are used as the input sequence, and the last LK parts of the sub-segment sequence are used as the output sequence; all sub-segment sequences are randomly shuffled and divided into training set, validation set and test set;
[0012] S3. Use the training set and the validation set to train the trajectory prediction model to obtain the target trajectory prediction model;
[0013] The trajectory prediction model includes an embedding layer, a graph attention encoding layer, a first Transformer encoding layer, a second Transformer encoding layer, a Transformer decoding layer, a Linear layer, a Softmax layer, and a Filter layer. The input sequence is input into the embedding layer and converted into a feature vector. The feature vector is respectively input into the graph attention encoding layer and the first Transformer encoding layer to extract spatial features and temporal features. The spatial features and temporal features are aggregated and input into the second Transformer encoding layer to further obtain the features of the input sequence. The model is then input into the Transformer decoding layer to generate a trajectory prediction sequence. The prediction sequence passes through the Linear layer, the Softmax layer, and the Filter layer in sequence to obtain the output sequence.
[0014] S4. Using the test set, the vehicle trajectory data of the vehicle to be predicted is mapped through a map matching algorithm to obtain a target road section sequence, which is then input into the target trajectory prediction model for trajectory prediction.
[0015] As a preferred solution, in step S1, the preprocessing includes data cleaning, filtering and compression.
[0016] As a preferred solution, in step S2, the map matching algorithm adopts the Fast Map Matching algorithm;
[0017] The vehicle trajectory dataset and road network are used as input, and all shortest path pairs within a specific length in the road network are pre-calculated and stored in the UBODT table; each row in the UBODT table stores the number of shortest paths from the starting node n to the starting node n. o To the target node n d The shortest path includes the next node next_n and the next edge next_e of the starting node, the previous node pre_n of the target node, and the shortest path distance; the UBODT table provides connection information between each node.
[0018] When the starting node n of the i-th path o,i and the target node n of the j-th path d,j If they are the same, get the node's front and back adjacent nodes pre_n j and next_n i ;
[0019] When the starting node n of the i-th path o,i and the starting node n of the kth path o,k The next node next_n k If they are the same, get the next_e of the node’s front and back adjacent edges. k and next_e i ;
[0020] In this way, the neighboring road segment information of each road segment in the road network is obtained, and a directed graph of the road network, that is, a road segment sequence, is constructed.
[0021] As a preferred solution, in step S2, K>LK.
[0022] As a preferred solution, the graph attention encoding layer adopts an attention mechanism to assign different weights to different neighbor nodes and calculate the features of each graph node;
[0023] The input of the graph attention encoding layer is h = {h1, h2, ..., h N}, h i ∈R F, h is the feature representation set of the node, R is the real number space, N is the number of nodes, and F is the feature dimension of each node. The output is h′={h′1,h′2,...,h′ N}, h′ i ∈R F′ , F′ is the output dimension, F′ and F may not be equal. In the graph attention layer, the present invention considers the influence of neighbor node j on the calculated node i, and the attention coefficient α ij It represents the influence of neighbor node j on the calculated node i, and takes into account the distance between nodes. The calculation formula of the attention coefficient is as follows:
[0024]
[0025] Among them, LeakyReLU is a nonlinear activation function, a∈R 2F′ is the weight vector, N i Represents the set of nodes adjacent to node i, W∈R F′×F is the shared linear transformation weight matrix applied to each node, Wh i represents the eigenvector of node i after the matrix change, || represents the connection operation of the vector, T Represents a permutation operation on a vector.
[0026] After normalizing the attention coefficient, the output of node i in the graph attention layer is σ is a nonlinear function.
[0027] As a preferred solution, the first Transformer encoding layer includes two sublayers: a multi-head attention mechanism and a feedforward neural network. The multi-head attention mechanism layer is used to encode each position in the input sequence and capture the dependencies between different positions in the sequence.
[0028] In the multi-head attention mechanism layer, the input sequence is first transformed independently by multiple attention heads, and then the outputs of all attention heads are concatenated and the context representation of the position is generated through linear transformation;
[0029] The output of the multi-head attention mechanism layer is used as the input of the feedforward neural network layer, and is processed by the feedforward neural network layer containing two fully connected layers to obtain the final output of the feedforward neural network layer.
[0030] As a preferred solution, the Transformer decoding layer gradually outputs each target road segment through an internal attention mechanism, and the position information of each road segment is determined in the decoding layer by adding a position code; after determining the position code, the Transformer decoding layer outputs the decoding results one by one.
[0031] As a preferred solution, the Linear layer performs a linear transformation on the output vector of the Transformer decoding layer and maps it to the dimension of the number of road sections in the road network; the output result of the Linear layer is input into the Softmax layer for normalization; the Filter layer performs a directed graph G of the traffic network. vec Filter the output of the Softmax layer; generate the adjacency vector W based on the connection relationship of the directed graph c , to indicate the connection between different road sections;
[0032] Adjacency vector W c It is expressed as follows:
[0033]
[0034] When road segment i is connected to road segment j, the weight between i and j is 1, otherwise it is 0; the adjacency vector W c Each row of represents the connection between the road segment and other road segments. The Softmax layer outputs the probability that each road segment may be the next road segment. If the previous road segment of the output road segment is the i-th road segment, the output vector of the Softmax layer is connected to the adjacent vector W. c The probability of the disconnected road segment is set to 0, and the probability of the connected road segment remains unchanged, so that the final output result is a continuous road segment.
[0035] As a preferred solution, the vehicle trajectory data is collected by a GPS sensor.
[0036] The present invention further provides a vehicle trajectory prediction system based on a spatiotemporal attention mechanism, applying the vehicle trajectory prediction method described in any of the above solutions, the vehicle trajectory prediction system comprising:
[0037] An acquisition module, used to collect vehicle trajectory data sets and vehicle trajectory data of vehicles to be predicted;
[0038] A preprocessing module, used for preprocessing vehicle trajectory data;
[0039] A map matching module is used to map the pre-processed vehicle trajectory data using a map matching algorithm to obtain a road segment sequence;
[0040] A segmentation module is used to segment the road section sequence into several sub-road section sequences;
[0041] Partitioning module, used to divide the input sequence, output sequence, training set, validation set and test set;
[0042] The training module is used to train the trajectory prediction model using the training set and the validation set to obtain the target trajectory prediction model;
[0043] The prediction module is used to perform trajectory prediction by inputting the target road segment sequence into the target trajectory prediction model.
[0044] Compared with the prior art, the present invention has the following beneficial effects:
[0045] The vehicle trajectory prediction method and system based on the spatiotemporal attention mechanism of the present invention can predict vehicle trajectories with high accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 Execute the flow chart for the method;
[0047] Figure 2 Schematic diagram of the road segment neighbor information extraction process;
[0048] Figure 3 This is a partial road structure diagram;
[0049] Figure 4 This is the structure diagram of the Transformer encoding layer;
[0050] Figure 5 This is the result representation diagram after the Filter layer;
[0051] Figure 6 This is the Beijing road network map;
[0052] Figure 7 This is a road network map of Chengdu. DETAILED DESCRIPTION
[0053] To more clearly illustrate the embodiments of the present invention, specific embodiments of the present invention will be described below with reference to the accompanying drawings. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings and other embodiments can be obtained based on these drawings without inventive efforts.
[0054] For the execution flow chart of the vehicle trajectory prediction method based on the spatiotemporal attention mechanism according to the embodiment of the present invention, please refer to Figure 1 , including the following steps:
[0055] S1, collecting a vehicle trajectory data set and preprocessing the vehicle trajectory data of the vehicle trajectory data set;
[0056] S2. Mapping the pre-processed vehicle trajectory data using a map matching algorithm to obtain a road segment sequence, and then segmenting the road segment sequence to obtain several sub-road segment sequences;
[0057] The length of each sub-segment sequence is L, the first K parts of the sub-segment sequence are used as the input sequence, and the last LK parts of the sub-segment sequence are used as the output sequence; all sub-segment sequences are randomly shuffled and divided into training set, validation set and test set;
[0058] S3. Train the trajectory prediction model using the training set, validation set, and test set to obtain a target trajectory prediction model;
[0059] Among them, the trajectory prediction model includes an embedding layer, a graph attention encoding layer, a first Transformer encoding layer, a second Transformer encoding layer, a Transformer decoding layer, a Linear layer, a Softmax layer, and a Filter layer. The input sequence is input into the embedding layer to be converted into a feature vector. The feature vector is respectively input into the graph attention encoding layer and the first Transformer encoding layer to extract spatial features and temporal features. The spatial features and temporal features are aggregated and input into the second Transformer encoding layer to further obtain the features of the input sequence. The features of the input sequence are input into the Transformer decoding layer to generate a trajectory prediction sequence. The prediction sequence passes through the Linear layer, the Softmax layer, and the Filter layer in sequence to obtain the output sequence.
[0060] S4. Mapping the vehicle trajectory data of the vehicle to be predicted using a map matching algorithm to obtain a target road segment sequence, which is then input into a target trajectory prediction model for trajectory prediction.
[0061] Specifically, the execution process of the vehicle trajectory prediction method based on the spatiotemporal attention mechanism in an embodiment of the present invention is as follows:
[0062] Step (1): Trajectory preprocessing. In the original dataset, vehicle trajectory data is obtained through GPS sensors. The original data is GPS records containing noise. Some of these records have too large a distance between the front and back points, some vehicle trajectory records are too short, and some are stagnant. Most vehicles are on their way to their destination. During data processing, abnormal data with large deviations, data with too short trajectory time lengths, and data that do not meet the experimental requirements should be eliminated.
[0063] In order to obtain a sequence of road sections, the GPS records need to be mapped to the road network. The map matching algorithm can infer the path on the road network from the noisy GPS trajectory. To this end, the present invention uses an open source map matching framework, Fast Map Matching (FMM). This algorithm is a fast map matching algorithm that combines hidden Markov model and pre-calculation. It takes the GPS trajectory set and the road network as input, pre-calculates all the shortest path pairs within a specific length in the road network, and stores them in the UBODT (Upper Bounded Origin Destination Table) table. Each row in the UBODT table stores the number of shortest paths from the starting node n to the destination node n. o The shortest path to the target node nd includes the next node next_n and the next edge next_e of the starting node, the previous node pre_n of the target node, and related information about the shortest path distance. The UBODT table provides connection information between each node.
[0064] like Figure 2 As shown, when the starting node n of the i-th path o,i and the target node n of the j-th path d,j If they are the same, the node’s front and back adjacent nodes pre_n can be obtained. j and next_n i When the starting node n of the i-th path o,i and the starting node n of the kth path o,k The next node next_n k If they are the same, the next_e adjacent edges of the node can be obtained. k and next_e i In this way, the neighboring road segment information of each road segment in the road network can be obtained, and a directed graph of the road network can be constructed.
[0065] After GPS records are converted into a road segment sequence using a map matching algorithm, the segment sequence is segmented into multiple sub-segment sequences. Each sub-segment sequence is 12 in length, with the first 8 being the input sequence and the last 4 being the output sequence. These sub-segment sequences are randomly shuffled and divided into training, validation, and test sets.
[0066] Step (2): Spatiotemporal feature extraction. The road segment sequence obtained by map mapping cannot be directly input into the neural network, and the neural network cannot process it directly. After preprocessing the original trajectory, the embedding layer maps the input road sequence into a dense continuous feature space to capture the feature information in the sequence. Each road segment v in the road segment sequence i ∈V is transformed into a feature vector v through embedding layers n ∈RM , V represents the segment sequence space, R is the real number space, and M represents the vector dimension of the road segment. After obtaining the feature representation of the input sequence, the feature vector is input into the graph attention encoding layer and the Transformer encoding layer for feature learning.
[0067] The graph attention encoding layer aggregates neighbor information by assigning different importance to different nodes. It does not rely on the complete graph structure and can handle dynamic graphs. Figure 3 As shown, different roads have different adjacent road sections. The graph attention network processes the graph data structure and uses the attention mechanism to assign different weights to different neighbor nodes and calculate the features of each graph node. The input of the graph attention layer is h = {h1, h2, ..., h N}, h i ∈R F , N is the number of nodes, F is the feature dimension of each node. The output is h′={h′1,h′2,...,h′ N}, h′ i ∈R F′ , F′ is the output dimension, F′ and F may not be equal. In the graph attention layer, the present invention considers the influence of neighbor node j on the calculated node i, and the attention coefficient α ij It represents the influence of neighbor node j on the calculated node i, and takes into account the distance between nodes. The calculation formula of the attention coefficient is as follows:
[0068]
[0069] Among them, LeakyReLU is a nonlinear activation function, a∈R 2F′ is the weight vector, N i Represents the set of nodes adjacent to node i, W∈R F′×F is the shared linear transformation weight matrix applied to each node, Wh i represents the eigenvector of node i after the matrix change, || represents the connection operation of the vector, T Represents a permutation operation on a vector.
[0070] After normalizing the attention coefficient, the output of node i in the graph attention layer is σ is a nonlinear function. This approach effectively improves the accuracy and stability of the model.
[0071] Transformer encoding layer Figure 4As shown in the figure, it consists of two sublayers: the Multi-Head Attention mechanism and the Feed Forward neural network. The Multi-Head Attention mechanism is implemented based on the self-attention mechanism. It can encode each position in the input sequence and capture the dependencies between different positions in the sequence. In the Multi-Head Attention mechanism, the input sequence is first transformed independently by multiple attention heads. The outputs of all attention heads are then concatenated and a linear transformation is performed to generate a contextual representation of that position. The self-attention mechanism can perform parallel computations on all positions, effectively processing sequence features. The output of the Multi-Head Self-Attention mechanism layer serves as the input to the Feed Forward neural network layer. It is processed by a Feed Forward neural network consisting of two fully connected layers to obtain the final output of the Feed Forward neural network layer.
[0072] Step (3): Future trajectory prediction, the output sequence of the last layer of Transformer encoding layer is passed to the Transformer decoding layer for decoding. The decoding layer gradually outputs each target road segment through the internal attention mechanism. The position information of each road segment can be determined by adding position encoding in the decoding layer. After determining the position encoding, the decoding layer outputs the decoding results one by one. Although both the encoding layer and the decoding layer use the self-attention mechanism, their operation methods are slightly different. In order to be able to output the target sequence one by one, the self-attention of the decoding layer hides the subsequent positions. The decoding layer inputs the learned feature representation into the same feedforward neural network as the encoding layer to obtain a weighted feature vector of larger dimension.
[0073] The output of the decoding layer is processed by the Linear layer, Softmax layer and Filter layer to output the predicted sequence. The Linear layer performs a linear transformation on the output vector of the encoder and maps it to the dimension of the number of road sections in the road network. The output result is input into the Softmax layer for normalization. After the data preprocessing mentioned in step (1), we obtain the directed graph G representing the traffic network vec The filter layer is based on the directed graph G vec Filter the output of the Softmax layer. Based on the connection relationship of the graph, we can generate the adjacency vector W c , to represent the connection between different road segments. Adjacency vector W c is represented as follows:
[0074]
[0075] When segment i is connected to segment j, the weight between i and j is 1, otherwise it is 0. Adjacency vector W cEach row of represents the connection between the road segment and other road segments, and the Softmax layer outputs the probability that each road segment may be the next road segment. If the previous road segment of the output road segment is the i-th road segment, then the output vector of the Softmax layer is connected to the adjacent vector W c Multiply the corresponding position of the i-th row vector of , set the probability of the unconnected road segment to 0, and the probability of the connected road segment remains unchanged, such as Figure 5 In this way, the final output result can be a continuous road segment.
[0076] Based on the above vehicle trajectory prediction method, an embodiment of the present invention further provides a vehicle trajectory prediction system based on a spatiotemporal attention mechanism, including the following functional modules:
[0077] An acquisition module, used to collect vehicle trajectory data sets and vehicle trajectory data of vehicles to be predicted;
[0078] A preprocessing module, used for preprocessing vehicle trajectory data;
[0079] A map matching module is used to map the pre-processed vehicle trajectory data using a map matching algorithm to obtain a road segment sequence;
[0080] A segmentation module is used to segment the road section sequence into several sub-road section sequences;
[0081] Partitioning module, used to divide the input sequence, output sequence, training set, validation set and test set;
[0082] The training module is used to train the trajectory prediction model using the training set and the validation set to obtain the target trajectory prediction model;
[0083] The prediction module is used to use the test set to input the target road segment sequence into the target trajectory prediction model for trajectory prediction.
[0084] The specific process of the above functional modules can refer to the specific description of the above vehicle trajectory prediction method, which will not be repeated here.
[0085] In order to verify the performance of the model proposed in this paper, a large number of experiments were conducted on two real vehicle trajectory datasets, namely the Beijing taxi trajectory dataset and the Chengdu taxi trajectory dataset. The dataset structures are shown in Tables 1 and 2 below.
[0086] Table 1 Beijing dataset
[0087]
[0088] Table 2 Chengdu dataset
[0089]
[0090]
[0091] Beijing Taxi Trajectory Dataset: This project contains the trajectory data of 10,357 taxis in Beijing from February 2, 2008 to February 8, 2008. Each data record includes vehicle ID, time, longitude, and latitude. This paper obtained the road network structure with a boundary range of [39.74, 40.10, 116.14, 116.80] from OpenStreetMap, which consists of 46,859 intersection nodes and 109,314 road segments, such as Figure 6 shown.
[0092] Chengdu Taxi Trajectory Dataset: This dataset contains 11 days of data collected from 13,605 taxi drivers in Chengdu using their smartphones from August 3, 2014 to August 13, 2014. Each GPS data record describes the taxi load at a specific time and location, including information such as time, vehicle ID, occupancy status, longitude, and latitude. In the experiment, we used [30.29, 31.04, 103.26, 104.61] as the boundary range to obtain the road network structure on OpenStreetMap, which consists of 83,483 intersection nodes and 203,578 road segments, such as Figure 7 shown.
[0093] In the experiment, the present invention uses distance error (DE) and average match ratio (AMR) as evaluation indicators to evaluate the prediction performance of the vehicle trajectory prediction model.
[0094] Distance Error (DE): The average edit distance between the predicted and actual trajectories. Edit distance is often used to quantify the similarity between two sequences by calculating the minimum number of operations required to transform one sequence into another. The formula of DE is defined as:
[0095]
[0096] Among them, N t represents the number of trajectory records in the test set, L out represents the length of the output trajectory, P′ i represents the predicted trajectory sequence, P i Represents the real trajectory sequence. Edit(P′ i ,P i ) represents P′ i With P i The Edit Distance between two sequences is used to calculate the difference between them. The larger the Edit Distance, the greater the difference between the two sequences.
[0097] Average Match Rate (AMR): The average ratio of the number of correctly predicted road segments to the length of the predicted trajectory. The AMR formula is defined as:
[0098]
[0099] Among them, v′ i,j and v i,j They represent the predicted road segment and the actual road segment at the jth position of the i-th trajectory sequence. i,j ,v i,j ) represents v′ i,j and v i,j The degree of matching. When v′ i,j and v i,j When the same, Match(v′ i,j ,v i,j )=1, otherwise Match(v′ i,j ,v i,j )=0.
[0100] The deep learning framework used in this paper is Pytorch. The input trajectory sequence length of the model is 8, and the output sequence length is 4. During the experiment, this paper uses the Adam optimizer to optimize the training process, with an initial learning rate set to 0.5, a linear learning rate decay, a weight decay value set to 0.01, a batch size of 100, a dropout rate of 0.1, and an epoch size of 40 iterations.
[0101] The main experimental results of this model are shown in Table 3 below.
[0102] Table 3 Comparative experimental results of different models
[0103]
[0104] This paper uses the LSTM Encoder-Decoder and Transformer as baseline models and evaluates the performance of the proposed method by comparing them with the baseline models. On the Beijing dataset, TPred (the abbreviation of this method, the same below) achieves an AMR value of 73.07%, which is 37.45% higher than the LSTM Encoder-Decoder and 6.38% higher than the Transformer. On the Chengdu dataset, TPred achieves an AMR value of 78.93%, which is 36.06% higher than the LSTM Encoder-Decoder and 10.55% higher than the Transformer. It can be observed that for both datasets, the proposed method outperforms the baseline model.
[0105] The above description is only a detailed description of the preferred embodiments and principles of the present invention. For ordinary technicians in this field, based on the ideas provided by the present invention, there may be changes in the specific implementation methods, and these changes should also be considered as the scope of protection of the present invention.
Claims
1. A vehicle trajectory prediction method based on spatiotemporal attention mechanism, characterized in that: The following steps are involved: S1, collecting a vehicle trajectory data set and preprocessing the vehicle trajectory data of the vehicle trajectory data set; S2. Mapping the pre-processed vehicle trajectory data using a map matching algorithm to obtain a road segment sequence, and then segmenting the road segment sequence to obtain several sub-road segment sequences; The length of each sub-segment sequence is L, the first K parts of the sub-segment sequence are used as the input sequence, and the last LK parts of the sub-segment sequence are used as the output sequence; all sub-segment sequences are randomly shuffled and divided into training set, validation set and test set; S3. Train the trajectory prediction model using the training set, validation set, and test set to obtain a target trajectory prediction model; The trajectory prediction model includes an embedding layer, a graph attention encoding layer, a first Transformer encoding layer, a second Transformer encoding layer, a Transformer decoding layer, a Linear layer, a Softmax layer, and a Filter layer. The input sequence is input into the embedding layer to be converted into a feature vector. The feature vector is respectively input into the graph attention encoding layer and the first Transformer encoding layer to extract spatial features and temporal features. The spatial features and temporal features are aggregated and input into the second Transformer encoding layer to obtain the features of the long sequence. The features of the long sequence are input into the Transformer decoding layer to generate a trajectory prediction sequence. The prediction sequence passes through the Linear layer, the Softmax layer, and the Filter layer in sequence to obtain the output sequence. The Linear layer performs a linear transformation on the output vector of the Transformer decoding layer and maps it to the dimension of the number of road sections in the road network; the output result of the Linear layer is input into the Softmax layer for normalization; the Filter layer performs a linear transformation on the directed graph G of the traffic network. vec Filter the output of the Softmax layer; generate the adjacency vector W based on the connection relationship of the directed graph c , to indicate the connection between different road sections; Adjacency vector W c It is expressed as follows: When road segment i is connected to road segment j, the weight between i and j is 1, otherwise it is 0; the adjacency vector W c Each row of represents the connection between the road segment and other road segments. The Softmax layer outputs the probability that each road segment may be the next road segment. If the previous road segment of the output road segment is the i-th road segment, the output vector of the Softmax layer is connected to the adjacent vector W. c Multiply the corresponding position of the i-th row vector of , set the probability of the unconnected road segment to 0, and keep the probability of the connected road segment unchanged, so that the final output result is a continuous road segment; S4. Mapping the vehicle trajectory data of the vehicle to be predicted using a map matching algorithm to obtain a target road segment sequence, which is then input into a target trajectory prediction model for trajectory prediction.
2. The vehicle trajectory prediction method according to claim 1, characterized in that: In step S1, the preprocessing includes data cleaning, filtering and compression.
3. The vehicle trajectory prediction method according to claim 1, characterized in that: In step S2, the map matching algorithm adopts the Fast Map Matching algorithm; The vehicle trajectory dataset and road network are used as input, and all shortest path pairs within a specific length in the road network are pre-calculated and stored in the UBODT table; each row in the UBODT table stores the number of shortest paths from the starting node n to the starting node n. o To the target node n d The shortest path includes the next node next_n and the next edge next_e of the starting node, the previous node pre_n of the target node, and the shortest path distance; the UBODT table provides connection information between each node; When the starting node n of the i-th path o,i and the target node n of the j-th path d,j If they are the same, get the node's front and back adjacent nodes pre_n j and next_n i ; When the starting node n of the i-th path o,i and the starting node n of the kth path o,k The next node next_n k If they are the same, get the next_e of the node's front and back adjacent edges. k and next_e i ; In this way, the neighboring road segment information of each road segment in the road network is obtained, and a directed graph of the road network, that is, a road segment sequence, is constructed.
4. The vehicle trajectory prediction method according to claim 1, characterized in that In step S2, K>LK.
5. The vehicle trajectory prediction method according to claim 1, characterized in that: The graph attention encoding layer uses the attention mechanism to assign different weights to different neighbor nodes and calculate the features of each graph node; The input of the graph attention encoding layer is h={h1,h2,…,h N }, h i ∈R F , N is the number of nodes, h is the feature representation set of the node, R is the real number space, F is the feature dimension of each node; the output is h′={h′1,h′2,…,h′ N }, h i ′∈R F′ , F′ is the output dimension, F′ and F may not be equal; Considering the influence of neighbor node j on the calculated node i, the attention coefficient a ij Indicates the degree of influence of neighbor node j on the calculated node i. The calculation of the attention coefficient is: Among them, LeakyReLU is a nonlinear activation function, a∈R 2F′ is the weight vector, W∈R F′×F is the shared linear transformation weight matrix applied to each node, N i represents the set of nodes adjacent to node i, Wh i represents the eigenvector of node i after the matrix change, || represents the connection operation of the vector, a T represents the transpose of the weight vector; After normalizing the attention coefficient, the output of node i in the graph attention layer is σ is a nonlinear function.
6. The vehicle trajectory prediction method according to claim 1, characterized in that: The first Transformer encoding layer includes two sublayers: a multi-head attention mechanism and a feedforward neural network. The multi-head attention mechanism layer is used to encode each position in the input sequence and capture the dependencies between different positions in the sequence. In the multi-head attention mechanism layer, the input sequence is first transformed independently by multiple attention heads, and then the outputs of all attention heads are concatenated and the context representation of the position is generated through linear transformation; The output of the multi-head attention mechanism layer is used as the input of the feedforward neural network layer, and is processed by the feedforward neural network layer containing two fully connected layers to obtain the final output of the feedforward neural network layer.
7. The vehicle trajectory prediction method according to claim 1, characterized in that: The Transformer decoding layer gradually outputs each target road segment through the internal attention mechanism. The position information of each road segment is determined by adding a position code in the decoding layer. After determining the position code, the Transformer decoding layer outputs the decoding results one by one.
8. The vehicle trajectory prediction method according to claim 1, characterized in that: The vehicle trajectory data is collected by a GPS sensor.
9. A vehicle trajectory prediction system based on a spatiotemporal attention mechanism, applying the vehicle trajectory prediction method according to any one of claims 1 to 8, characterized in that: The vehicle trajectory prediction system includes: An acquisition module, used to collect vehicle trajectory data sets and vehicle trajectory data of vehicles to be predicted; A preprocessing module, used for preprocessing vehicle trajectory data; A map matching module is used to map the pre-processed vehicle trajectory data using a map matching algorithm to obtain a road segment sequence; A segmentation module is used to segment the road section sequence into several sub-road section sequences; Partitioning module, used to divide the input sequence, output sequence, training set, validation set and test set; The training module is used to train the trajectory prediction model using the training set, validation set, and test set to obtain the target trajectory prediction model; The prediction module is used to input the target road segment sequence into the target trajectory prediction model for trajectory prediction.
Citation Information
Patent Citations
Urban scale taxi track prediction method based on attention mechanism
CN110163439A
Vehicle track prediction method based on graph attention interaction mechanism
CN114692762A