Traffic flow prediction method based on deep learning

By using a Transformer fusion model enhanced with memory tensors, combining temporal self-attention, spatial self-attention, and memory self-attention mechanisms, the adaptability problem of existing traffic flow prediction methods in irregular road networks and sparse data scenarios is solved, achieving high-precision traffic flow prediction and accurate characterization of dynamic traffic networks.

CN121281279AActive Publication Date: 2026-01-06UNIV OF ELECTRONICS SCI & TECH OF CHINA

Patent Information

Application Number
CN202511852270.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-10
Publication Date
2026-01-06
Estimated Expiration
2045-12-10

AI Technical Summary

Technical Problem

Existing traffic flow prediction methods are not suitable for irregular traffic network structures, making it difficult to accurately depict the interaction between remote nodes in dynamic traffic networks. Furthermore, data sparsity leads to a decline in model performance in small cities or newly deployed sensor sections.

Method used

We employ a Transformer fusion model enhanced with memory tensors, combining temporal self-attention, spatial self-attention, and memory self-attention mechanisms. We preprocess and predict traffic flow data through data embedding, feature extraction, and output layers, and utilize global memory tensors to optimize historical pattern information, reducing our reliance on large-scale training data.

Benefits of technology

It improves prediction accuracy and model adaptability under sparse data conditions, can accurately identify vehicle traffic status in traffic networks and predict future traffic flow trends, supports the adaptability and accuracy of multi-factor coupled traffic flow, and is applicable to traffic networks of different sizes and topologies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121281279A_ABST
    Figure CN121281279A_ABST
Patent Text Reader

Abstract

The invention provides a traffic flow prediction method based on deep learning, and belongs to the field of intelligent traffic systems and traffic management. The method comprises the following steps: collecting traffic flow data of a road, and obtaining regional road network map data; constructing a memory tensor enhanced Transform fusion model, wherein the memory tensor enhanced Transform fusion model comprises a data embedding layer, a feature extraction layer, a jump connection layer and an output layer; inputting the traffic flow data and the regional road network map data into a data embedding layer for preprocessing to obtain preprocessed data; inputting the preprocessed data into a feature extraction layer for space-time memory triple attention and multi-layer perceptron processing to obtain a plurality of space-time memory feature extraction layer outputs; accumulating the output and input jump connection layers of each space-time memory feature extraction layer to obtain a jump connection result; and inputting the jump connection result into an output layer, and carrying out convolution operation twice to obtain a traffic flow prediction result. According to the method, a more accurate traffic prediction basis can be provided for decision making, and the method has a remarkable engineering application prospect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of intelligent transportation systems and traffic management, and particularly relates to a traffic flow prediction method based on deep learning. Background Technology

[0002] Traffic flow perception and real-time prediction are key technologies for urban intelligent transportation systems. They aim to accurately identify vehicle traffic status in traffic networks such as roads and intersections, and precisely predict traffic flow trends in future time periods. Traffic flow prediction methods dynamically model the spatiotemporal dependencies of traffic flow by analyzing historical and current traffic flow data, temporal and spatial characteristics in real time, and achieve multi-step forward prediction. This provides decision support for traffic management, route planning, and signal control, effectively improving road utilization efficiency and urban traffic operation levels.

[0003] In recent years, with the development of deep learning, neural network-based traffic flow prediction methods have shown significant advantages in modeling complex nonlinear relationships. Early studies mostly used convolutional neural networks to model traffic networks, utilizing two-dimensional convolutional structures to characterize the spatial dependencies of traffic networks and enhancing the expression of long-term dependencies through residual structures. Subsequently, researchers proposed using graph neural networks combined with sequence modeling methods to achieve joint modeling of spatiotemporal features. Graph convolutions are used to extract spatial structural features of traffic networks, and time series models are combined to describe the dynamic changes in traffic flow. Building on this, some methods have further introduced attention mechanisms to improve the ability to model complex spatiotemporal dependencies. Meanwhile, some studies have also attempted to improve the generalization performance and prediction accuracy of models by training or pre-training on large-scale historical data.

[0004] These methods have application value under their respective specific conditions, but they still have the following shortcomings:

[0005] (1) CNN-based prediction methods usually rely on regular grid partitioning or fixed convolution kernels. Their neighborhood relationship settings are relatively rigid and not suitable for irregular traffic network structures. Furthermore, they have limited ability to model long-distance dependencies and complex dynamic changes.

[0006] (2) Prediction methods based on GNN generally rely on static adjacency matrices, which can only reflect local spatial dependence under a fixed topology and are difficult to accurately characterize the interaction relationship between remote nodes in a dynamic transportation network.

[0007] (3) Most current methods require a large amount of historical data as training support. When the application scenario is a small city or a newly deployed sensor road section, the data is often limited or sparse, which leads to a significant decrease in model performance.

[0008] Therefore, there is an urgent need for an intelligent traffic flow prediction method that can integrate temporal dynamic modeling and spatiotemporal feature extraction, combine attention mechanisms, and possess high adaptability and interpretability. Summary of the Invention

[0009] The purpose of this invention is to provide a traffic flow prediction method based on deep learning, so as to solve the technical problems that existing prediction methods are not suitable for irregular traffic network structures and are difficult to accurately depict the interaction relationship between remote nodes in dynamic traffic networks.

[0010] To solve the above-mentioned technical problems, the specific technical solution of the present invention is as follows:

[0011] A traffic flow prediction method based on deep learning, the method comprising the following steps:

[0012] Step S1: Collect real-time traffic flow data from roads using traffic sensor nodes to obtain regional road network map data;

[0013] Step S2: Construct a memory tensor-enhanced Transformer fusion model. This model includes a data embedding layer, a feature extraction layer, a skip connection layer, and an output layer. The feature extraction layer includes... A spatiotemporal memory feature extraction layer;

[0014] Step S3: Input traffic flow data and regional road network map data into the data embedding layer for preprocessing to obtain preprocessed data;

[0015] Step S4: Input the preprocessed data into the feature extraction layer for spatiotemporal memory triple attention and multilayer perceptron processing to obtain multiple spatiotemporal memory feature extraction layer outputs;

[0016] Step S5: Accumulate the output of each spatiotemporal memory feature extraction layer into the skip connection layer to obtain the skip connection result;

[0017] Step S6: Perform two convolution operations on the input and output layers of the skip connection results to map them to traffic flow prediction results in the node channel dimension.

[0018] Furthermore, the preprocessing of the data embedding layer in step S3 includes numerical feature embedding, time-location encoding, daily cycle embedding, weekly cycle embedding, and spatial location encoding, ultimately yielding preprocessed data; the preprocessing process of the data embedding layer is represented as follows:

[0019]

[0020] in, This indicates preprocessed data; Indicates numerical feature embedding; This represents a time position code generated based on a sine-cosine function; Indicates daily cycle embedding; Indicates a periodic embedding; This represents spatial location encoding based on the graph Laplacian matrix.

[0021] Furthermore, each spatiotemporal memory feature extraction layer includes a temporal self-attention module, a first residual connection and layer normalization module, a spatial self-attention module, a second residual connection and layer normalization module, a memory self-attention module, a third residual connection and layer normalization module, a feedforward neural network module, and a fourth residual connection and layer normalization module; each spatiotemporal memory feature extraction layer performs the following operations:

[0022] Step S41: The temporal self-attention module performs temporal self-attention processing on the preprocessed data to obtain a temporal attention score; the temporal attention score and the preprocessed data are connected through the first residual and processed by layer normalization to obtain the temporal attention output;

[0023] Step S42: The spatial self-attention module learns the interaction relationship between different nodes from the temporal attention output to obtain the spatial attention score; the spatial attention score and the temporal attention output are processed by the second residual connection and layer normalization to obtain the spatial attention output;

[0024] Step S43: The memory self-attention module performs memory-enhanced multi-head attention calculation on the spatial attention output to obtain the memory attention score; the memory attention score and the spatial attention output are connected by the third residual and processed by layer normalization to obtain the memory attention output;

[0025] Step S44: The feedforward neural network module performs a fully connected transformation and nonlinear activation on the memory attention output to obtain the feedforward network output features; the feedforward network output features and the memory attention output are processed by the fourth residual connection and layer normalization to obtain the spatiotemporal memory feature extraction layer output.

[0026] Furthermore, the preprocessed data is mapped using a two-dimensional convolution to generate a time query vector, a time key vector, and a time value vector, as shown below:

[0027]

[0028] in, Represents a time-based query vector; Represents the time key vector; Represents a time value vector; This indicates preprocessed data; Represents a time-based linear projection matrix; Represents the time-key linear projection matrix; Represents the linear projection matrix of time values;

[0029] The time query vector, time key vector, and time value vector are processed by a multi-head attention mechanism to obtain a time attention score, as shown below:

[0030]

[0031]

[0032]

[0033] in, Indicates attentional time score; Indicates the first The query projection matrix of each time attention head; Indicates the first The key projection matrix of a time attention head; Indicates the first The projection matrix of the values ​​of each time attention head; This represents the temporal attention output projection matrix; Indicates the first A moment of attention; Indicates the number of attention points over time; Indicates the time-based output projection matrix; This represents the head dimension of temporal attention; This represents the normalization exponential function, which transforms any real vector into a probability distribution. This represents the concatenation function, which concatenates the outputs of multiple attention heads along the feature dimension.

[0034] Time Attention Score With preprocessed data After the first residual connection and layer normalization, the temporal attention output is obtained, as shown below:

[0035]

[0036] in, Indicates time-based attention output; The representation layer normalization function.

[0037] Furthermore, the temporal attention output is mapped via a two-dimensional convolution to generate a spatial query vector, a spatial key vector, and a spatial value vector, as shown below:

[0038]

[0039] in, Represents a spatial query vector; Represents a spatial key vector; Represents a spatial value vector; Represents a spatial query linear projection matrix; Represents the linear projection matrix of the space bond; Represents the linear projection matrix of spatial values;

[0040] The spatial query vector, spatial key vector, and spatial value vector are processed by a multi-head attention mechanism to obtain a spatial attention score, which is represented as follows:

[0041]

[0042]

[0043]

[0044] in, Indicates spatial attention score; Indicates the first A spatial attention head; Indicates the number of spatial attention heads; Indicates the spatial output projection matrix; Indicates the first The query projection matrix of each spatial attention head; Indicates the first The key projection matrix of a spatial attention head; Indicates the first The value projection matrix of each spatial attention head; This indicates the spatial attention head dimension; Represents a geographic topological constraint mask;

[0045] Spatial attention score With time attention output After the second residual connection and layer normalization, the spatial attention output is obtained, as shown below:

[0046]

[0047] in, This indicates spatial attention output.

[0048] Furthermore, the memory self-attention module introduces a global memory tensor, which maps the spatial attention output through a two-dimensional convolution to generate a memory query vector, a memory key vector, and a memory value vector, as shown below:

[0049]

[0050]

[0051]

[0052] in, Represents the global memory tensor. , Indicates the number of nodes. Represents the dimension of the memory tensor; Represents a linear mapping function; Represents the memory query vector; Represents the memory key vector; Represents a memory value vector; This represents the linear projection matrix used for memorizing queries; Represents the linear projection matrix of the memory bond; Represents the linear projection matrix of the memory value;

[0053] The memory query vector, memory key vector, and memory value vector are processed by a multi-head attention mechanism to obtain a memory attention score, which is represented as follows:

[0054]

[0055]

[0056]

[0057] in, Indicates memory attention score; Indicates the first One memory attention point; Indicates the number of attention points during memory; This represents the memory output projection matrix; Indicates the first The query projection matrix of a memory attention head; Indicates the first The key projection matrix of the memory attention head; Indicates the first The projection matrix of the values ​​of each memory attention head; This represents the head dimension of memory attention;

[0058] Memory Attention Score Spatial attention output After processing the third residual connection and layer normalization, the memory attention output is obtained, as shown below:

[0059]

[0060] in, This indicates the output of memory and attention.

[0061] Furthermore, the operation performed in step S44 is represented as follows:

[0062]

[0063] in, This represents the output of the spatiotemporal memory feature extraction layer. This represents a feedforward neural network.

[0064] Furthermore, the first The output of each spatiotemporal memory feature extraction layer is represented as follows: , No. The values ​​of each spatiotemporal memory feature extraction layer participating in skip connections are calculated as follows:

[0065]

[0066] in, Indicates the first The values ​​of the spatiotemporal memory feature extraction layer involved in the skip connection; This represents a convolution of size 1×1;

[0067] The result of the skip join is obtained by summing all the values ​​involved in the skip join, as shown below:

[0068]

[0069] in, This indicates the result of a skip connection.

[0070] Compared with the prior art, the present invention has the following beneficial technical effects:

[0071] (1) This invention discloses a traffic flow prediction method based on deep learning, which aims to accurately identify the vehicle traffic status in traffic networks such as roads and intersections, and accurately predict the traffic flow change trend in future time periods. This method introduces a time attention mechanism in the time dimension, which can automatically allocate the importance of different time slices according to the dynamic changes of traffic flow, thereby effectively capturing complex time dependencies such as peak periods and sudden events. In the spatial dimension, the spatial attention mechanism is used to adaptively adjust the influence weights between different road segments, so as to better reflect the non-uniform dependencies and dynamic topological relationships existing in the real traffic network.

[0072] (2) By introducing a global memory tensor, the model continuously accumulates and optimizes historical pattern information during training, so that it can not only refer to the recent state when making predictions, but also utilize long-term evolution laws, thereby improving the robustness and generalization ability of the model when facing sparse data or sudden traffic conditions.

[0073] (3) This invention supports the fusion of multimodal features such as traffic flow, periodic patterns, and time information, avoiding the limitations of single-modal features. Through location coding and graph structure modeling mechanisms, it can flexibly adapt to traffic networks of different sizes and topologies. This improves the adaptability and accuracy of the prediction results to traffic flow coupled by multiple factors. This invention takes into account the expressive power of periodic traffic patterns, dynamic spatial topology, and long-term historical patterns, enhancing the adaptability of the prediction model in large-scale urban road networks and data-sparse environments.

[0074] (4) In small cities or in scenarios where sensors are newly deployed, data is often limited. This invention reduces the dependence on large-scale training data by using global memory tensors and attention mechanisms, thereby improving prediction accuracy under data-scarce conditions.

[0075] (5) The model structure of this invention has good scalability and can be easily ported to transportation systems of different cities or different scales. In scenarios such as intelligent transportation, urban planning, and emergency dispatch, this invention can provide more accurate traffic flow prediction basis for decision-making and has significant engineering application prospects. Attached Figure Description

[0076] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0077] Figure 1 This is a schematic diagram of the traffic flow prediction method based on deep learning according to the present invention.

[0078] Figure 2 This is a schematic diagram of the traffic flow prediction structure based on deep learning according to the present invention.

[0079] Figure 3 This is a schematic diagram of the spatiotemporal memory feature extraction process of the present invention. Detailed Implementation

[0080] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0081] This invention proposes a traffic flow prediction method based on deep learning, such as... Figure 1-2 As shown, the method includes the following steps:

[0082] Step S1: Collect real-time traffic flow data of roads through traffic sensor nodes to obtain regional road network map data.

[0083] The collected traffic flow data includes traffic outflow and traffic inflow, with traffic inflow and outflow together constituting traffic flow; and timestamps are recorded in a uniform format.

[0084] The collected traffic flow data is represented as ,in, For batch size, The time window length, This refers to the number of road sensor nodes. The feature dimensions for each node.

[0085] Step S2: Construct a memory tensor-enhanced Transformer fusion model. This model includes a data embedding layer, a feature extraction layer, a skip connection layer, and an output layer. The feature extraction layer includes... A spatiotemporal memory feature extraction layer.

[0086] Step S3: Input traffic flow data and regional road network map data into the data embedding layer for preprocessing to obtain preprocessed data.

[0087] The preprocessing of the data embedding layer includes numerical feature embedding, temporal location encoding, daily periodic embedding, weekly periodic embedding, and spatial location encoding, ultimately yielding preprocessed data. The data embedding layer achieves a unified representation of multi-source features, providing high-quality input for subsequent processing.

[0088] Numerical feature embedding maps raw traffic data from a low-dimensional scalar space to a high-dimensional semantic space, enabling the additive fusion of data content features and spatiotemporal context features in a unified representation space, providing nonlinear transformation capabilities, and allowing the model to capture complex traffic patterns.

[0089] Traffic flow data is time-location encoded to characterize the sequential information between time steps, thereby enhancing the ability to distinguish different time steps in traffic flow data.

[0090] Daily and weekly periodic embeddings are performed on traffic flow data to characterize the daily and weekly periodic traffic patterns.

[0091] Spatial location codes are generated by using the Laplace matrix of regional road network map data, and different road nodes are embedded and mapped, so that the data can represent the topology of the traffic network and the spatial relationships between nodes.

[0092] The preprocessing process of the data embedding layer is as follows:

[0093]

[0094] in, This indicates preprocessed data; Indicates numerical feature embedding; This represents a time position code generated based on a sine-cosine function; Indicates daily cycle embedding; Indicates a periodic embedding; This represents spatial location encoding based on the graph Laplacian matrix.

[0095] The calculation of spatial location encoding based on the graph Laplacian matrix includes the following steps:

[0096] Step S31: Construct an adjacency sparse matrix based on the regional road network map data, as shown below:

[0097]

[0098] in, Represents regional road network map data; The adjacency matrix is ​​a... Array; This represents the total number of nodes in the road network; express OK The space of real matrices in columns; adjacency sparse matrix elements Represents a node To the node The edge weights are the actual distance or time for sensor networks, and 0 or 1 for grid data.

[0099] Step S32: Calculate the degree matrix of the adjacency sparse matrix, represented as follows:

[0100]

[0101] in, The degree matrix is ​​a diagonal matrix; Represents a node The degree; This represents the constructor for a diagonal matrix, converting a vector into diagonal elements; for an undirected graph, Equal to node The sum of the weights of all connected edges; for grid data, Indicates the number of neighbors.

[0102] Step S33: Based on the adjacency sparse matrix and the degree matrix, the symmetric normalized Laplace matrix is ​​expressed as follows:

[0103]

[0104] in, Represents a symmetric normalized Laplace matrix; express Unit matrix; The inverse square root of the degree matrix is ​​denoted as . Matrix multiplication Symmetric normalization is applied to the adjacency sparse matrix to make nodes with different degrees comparable; It is a positive semi-definite symmetric matrix with eigenvalues ​​in the range [0,2], which encodes the structural information of the graph.

[0105] Step S34: Eigenvalue decomposition, represented as follows:

[0106]

[0107] in, Denotes the first Laplace matrix One eigenvalue; This represents the corresponding eigenvector; the eigenvalues ​​are arranged in ascending order: ; It is a unit vector that satisfies Different eigenvectors are orthogonal: ; This represents the total number of eigenvectors that need to be solved, where This indicates the dimension size of the Laplace positional encoding. This represents the number of isolated nodes in the graph; the minimum value is efficiently calculated using the sparse eigenvalue decomposition algorithm. Each eigenvalue and eigenvector.

[0108] Step S35: Extract the Laplacian encoding matrix, as shown below:

[0109]

[0110] in, Represents the Laplace position encoding matrix; Indicates the starting index, skipping the eigenvectors and constant eigenvectors corresponding to outliers. ; Indicates the dimension of the Laplace encoding; Indicates the first feature vectors, containing Each element corresponds to One node; Represents a node The Laplace position code is a 3D vectors; these feature vectors capture low-frequency structural information of the graph, where adjacent nodes are close to each other in the feature space.

[0111] Step S36: By linearly mapping to the embedding dimension, it can be represented as follows:

[0112]

[0113] in, The result is a Laplacian embedding. This represents a learnable weight matrix that is automatically optimized through training. Represents a learnable bias vector; Representing the embedding dimension of the model; matrix multiplication Each node Dimensional encoding mapping to Dimension; Output shape is After being expanded by adding tensor dimensions, it becomes To match batch and time dimensions.

[0114] Step S4: Input the preprocessed data into the feature extraction layer for spatiotemporal memory triple attention and multilayer perceptron processing to obtain multiple spatiotemporal memory feature extraction layer outputs.

[0115] Feature extraction layer includes A spatiotemporal memory feature extraction layer, such as Figure 3 As shown, each spatiotemporal memory feature extraction layer includes a temporal self-attention module, a first residual connection and layer normalization module, a spatial self-attention module, a second residual connection and layer normalization module, a memory self-attention module, a third residual connection and layer normalization module, a feedforward neural network module, and a fourth residual connection and layer normalization module.

[0116] The temporal self-attention module, spatial self-attention module, and memory self-attention module represent multi-head self-attention computation at different dimensional levels. The basic formula for multi-head self-attention computation is expressed as follows:

[0117]

[0118]

[0119]

[0120] in, This represents the attention mechanism; These represent the query vector, key vector, and value vector, respectively. This represents the normalization exponential function, which transforms any real vector into a probability distribution. Indicates transpose; Indicates the dimension of the key vector; This represents the multi-head attention mechanism; This indicates a concatenation operation, which concatenates the outputs of multiple attention heads along the feature dimension. Indicates the first One point of attention; Indicates the number of attention heads; Indicates the output projection matrix; Indicates the first The query projection matrix of each attention head; Indicates the first The key projection matrix of each attention head; Indicates the first The value projection matrix of each attention head.

[0121] Each spatiotemporal memory feature extraction layer performs the following operations:

[0122] Step S41: The temporal self-attention module performs temporal self-attention processing on the preprocessed data to obtain a temporal attention score; the temporal attention score and the preprocessed data are connected through the first residual and processed by layer normalization to obtain the temporal attention output.

[0123] The time attention module maps preprocessed data to generate time query vectors, time key vectors, and time value vectors. Through multi-head query and matching, and with the parallel action of multiple attention heads, it adaptively captures the global dependencies between traffic flow data at different historical moments. By implementing dynamic weighting of key temporal features through the multi-head attention mechanism, it can characterize the temporal dynamics such as peak periods and sudden events, thereby modeling the dynamic evolution trend of traffic flow in the time dimension.

[0124] The preprocessed data is mapped using a two-dimensional convolution to generate a time query vector, a time key vector, and a time value vector, as shown below:

[0125]

[0126] in, Represents a time-based query vector; Represents the time key vector; Represents a time value vector; This indicates preprocessed data; Represents a time-based linear projection matrix; Represents the time-key linear projection matrix; This represents the linear projection matrix of time values.

[0127] The time query vector, time key vector, and time value vector are processed by a multi-head attention mechanism to obtain a time attention score, as shown below:

[0128]

[0129]

[0130]

[0131] in, Indicates attentional time score; Indicates the first The query projection matrix of each time attention head; Indicates the first The key projection matrix of a time attention head; Indicates the first The projection matrix of the values ​​of each time attention head; This represents the temporal attention output projection matrix; Indicates the first A moment of attention; Indicates the number of attention points over time; Indicates the time-based output projection matrix; This represents the time attention head dimension.

[0132] Time Attention Score With preprocessed data After the first residual connection and layer normalization, the temporal attention output is obtained, as shown below:

[0133]

[0134] in, Indicates time-based attention output; The representation layer normalization function.

[0135] Step S42: The spatial self-attention module learns the interaction relationship between different nodes from the temporal attention output to obtain the spatial attention score; the spatial attention score and the temporal attention output are processed by the second residual connection and layer normalization to obtain the spatial attention output.

[0136] Building upon the temporal attention output, the spatial attention module performs multi-head queries and matching on the spatial features of road network nodes, learning the traffic correlations between different roads. It can identify potential interactions between remote nodes under topological constraints. The spatial attention module adaptively assigns correlation weights between road nodes based on the traffic network structure, enabling the modeling of complex spatial topological dependencies in the road network. This overcomes the limitations of static adjacency matrix modeling, achieving the modeling of irregular topologies and long-range dependencies.

[0137] The temporal attention output is mapped via a two-dimensional convolution to generate a spatial query vector, a spatial key vector, and a spatial value vector, as shown below:

[0138]

[0139] in, Represents a spatial query vector; Represents a spatial key vector; Represents a spatial value vector; Represents a spatial query linear projection matrix; Represents the linear projection matrix of the space bond; This represents the linear projection matrix of spatial values.

[0140] The spatial query vector, spatial key vector, and spatial value vector are processed by a multi-head attention mechanism to obtain a spatial attention score, which is represented as follows:

[0141]

[0142]

[0143]

[0144] in, Indicates spatial attention score; Indicates the first A spatial attention head; Indicates the number of spatial attention heads; Indicates the spatial output projection matrix; Indicates the first The query projection matrix of each spatial attention head; Indicates the first The key projection matrix of a spatial attention head; Indicates the first The value projection matrix of each spatial attention head; This indicates the spatial attention head dimension; This represents a geographic topology constraint mask, used to limit the mutual influence between nodes that are too far apart.

[0145] Spatial attention score With time attention output After the second residual connection and layer normalization, the spatial attention output is obtained, as shown below:

[0146]

[0147] in, This indicates spatial attention output.

[0148] Step S43: The memory self-attention module performs memory-enhanced multi-head attention calculation on the spatial attention output to obtain the memory attention score; the memory attention score and the spatial attention output are processed by the third residual connection and layer normalization to obtain the memory attention output.

[0149] The memory self-attention module introduces a global memory tensor, which, as a learnable parameter, is continuously updated through backpropagation during training. This global memory tensor is constantly optimized and injected with long-term historical pattern information, thereby gradually containing pattern information related to the long-term evolution of traffic flow. This enhances the model's ability to model long-term dependencies and abnormal traffic dynamics. Furthermore, combined with the attention mechanism, it interacts with the current features during attention calculation, enhancing the model's ability to express long-term dependencies and improving its modeling capabilities for long-term dependencies and potential traffic interactions.

[0150] The memory self-attention module introduces a global memory tensor, and maps the spatial attention output through a two-dimensional convolution to generate a memory query vector, a memory key vector, and a memory value vector, as shown below:

[0151]

[0152]

[0153]

[0154] in, Represents the global memory tensor. , Indicates the number of nodes. The memory tensor dimension is used as an adjustable network hyperparameter. Represents a linear mapping function; Represents the memory query vector; Represents the memory key vector; Represents a memory value vector; This represents the linear projection matrix used for memorizing queries; Represents the linear projection matrix of the memory bond; This represents the linear projection matrix of the memory value.

[0155] Linear mapping function global memory tensor Aligning with node features and enhancing memory query vectors after linear mapping alignment. With memory key vector .

[0156] The memory query vector, memory key vector, and memory value vector are processed by a multi-head attention mechanism to obtain a memory attention score, which is represented as follows:

[0157]

[0158]

[0159]

[0160] in, Indicates memory attention score; Indicates the first One memory attention point; Indicates the number of attention points during memory; This represents the memory output projection matrix; Indicates the first The query projection matrix of a memory attention head; Indicates the first The key projection matrix of the memory attention head; Indicates the first The projection matrix of the values ​​of each memory attention head; This represents the head dimension of memory attention.

[0161] Memory Attention Score Spatial attention output After processing the third residual connection and layer normalization, the memory attention output is obtained, as shown below:

[0162]

[0163] in, This indicates the output of memory and attention.

[0164] Step S44: The feedforward neural network module performs a fully connected transformation and nonlinear activation on the memory attention output to obtain the feedforward network output features; the feedforward network output features and the memory attention output are processed by the fourth residual connection and layer normalization to obtain the spatiotemporal memory feature extraction layer output.

[0165] The memory attention output is transformed and nonlinearly activated by the feedforward neural network module, and then processed by the fourth residual connection and layer normalization to obtain the spatiotemporal memory feature extraction layer output, as shown below:

[0166]

[0167] in, This represents the output of the spatiotemporal memory feature extraction layer. This represents a feedforward neural network.

[0168] The temporal self-attention module, spatial self-attention module, memory self-attention module, and feedforward neural network module all employ residual connections and layer normalization structures to ensure stable training of the deep network and consistency of feature representations. Through the step-by-step fusion of the temporal, spatial, and memory self-attention modules, a high-dimensional comprehensive representation that simultaneously incorporates temporal dynamic features, spatial topological dependencies and long-term dependencies, and potential traffic interaction associations is obtained and used to generate traffic flow prediction results for future time periods.

[0169] Step S5: The output of each spatiotemporal memory feature extraction layer is accumulated into the skip connection layer to obtain the skip connection result.

[0170] Perform a convolution operation on each of the outputs of the spatiotemporal memory feature extraction layers to obtain the values ​​of the spatiotemporal memory feature extraction layers participating in the skip connections. The output of each spatiotemporal memory feature extraction layer is represented as follows: , No. The values ​​of each spatiotemporal memory feature extraction layer participating in skip connections are calculated as follows:

[0171]

[0172] in, Indicates the first The values ​​of the spatiotemporal memory feature extraction layer involved in the skip connection; This represents a 1×1 convolution, used for channel mapping and dimension compression.

[0173] The result of the skip join is obtained by summing all the values ​​involved in the skip join, as shown below:

[0174]

[0175] in, This indicates the result of a skip connection.

[0176] Step S6: Perform two convolution operations on the input and output layers of the skip connection results, mapping them to traffic flow prediction results in the node channel dimension, as shown below:

[0177]

[0178]

[0179] in, This represents the result of the first convolution; Represents the ReLU nonlinear activation function; This indicates the first convolution, which is a 1×1 convolution; This indicates the second convolution, which is a 1×1 convolution; This indicates the traffic flow forecast results. ,in, Indicates the time step of the prediction. This indicates the dimension of the predicted output features.

[0180] This invention achieves feature convergence and prediction generation through skip connections and convolutional output, which can avoid the gradient vanishing problem while ensuring deep expressive power.

[0181] Step S7: Divide the traffic flow data into training and test sets in a 7:3 ratio, design a loss function, use the training set for regression training, and finally obtain the trained memory tensor-enhanced Transformer fusion model.

[0182] The loss function uses the mean absolute error (MAE), and is expressed as follows:

[0183]

[0184] in, Indicates the mean absolute error. Indicates the total number of samples; Indicates the first The true value of each sample; Indicates the first Predicted values ​​for each sample; This represents absolute value operations.

[0185] The model's prediction accuracy for traffic flow values ​​is optimized using a loss function. The prediction error on the test set is calculated in each training round to evaluate its stability and generalization ability. After training, a well-trained Transformer fusion model with memory tensor augmentation is obtained.

[0186] Step S8: Input the test data into the trained memory tensor-enhanced Transformer fusion model to predict traffic flow data for future time steps.

[0187] Use a trained memory tensor-enhanced Transformer fusion model to predict traffic flow data for future time steps to identify abnormal congestion or sudden changes in traffic flow.

[0188] This invention can be applied to real-time prediction and scheduling optimization of urban traffic flow. It continuously collects multi-dimensional traffic flow, speed, and road occupancy data through traffic flow detectors, video surveillance, and vehicle-mounted sensors deployed on key road sections of the road network. The collected time-series data, after standardization and time alignment preprocessing, is combined with historical time window data to form an input sequence, which is then fed into a trained memory tensor-enhanced Transformer fusion model for real-time prediction. The prediction results are dynamically compared with actual monitored values. When the prediction error exceeds a preset threshold, a traffic congestion or abnormal event identification mechanism is triggered, and scheduling decisions are provided based on the predicted trends for traffic signal control, congestion mitigation, and public transport priority strategies. The entire delay from data acquisition to prediction output is controlled within seconds, ensuring that the memory tensor-enhanced Transformer fusion model can meet the real-time requirements of intelligent transportation, achieving minute-level congestion warnings and dynamic interventions.

[0189] Furthermore, this invention supports historical traffic data analysis and trend mining, allowing the import of historical traffic data for any time period. First, data integrity checks, spatial topology mapping, and time window segmentation are performed. Then, a trained Transformer fusion model with enhanced memory tensors is used to perform batch predictions and bias analysis on the historical data. By comparing the prediction results with actual traffic flow, potential abnormal traffic events in historical periods are identified. Further, a spatial self-attention module is incorporated to analyze the interaction relationships between road network nodes, generating timelines, impact ranges, and propagation paths of abnormal events, providing in-depth insights for traffic management departments. The output analysis results are presented in a visual format, including time-series prediction curves, road segment heatmaps, and anomaly propagation network diagrams, helping users evaluate the effectiveness of traffic control measures and develop future optimization plans.

[0190] This invention has broad application prospects and can be used in smart city traffic management. In large cities, road traffic conditions are complex and dynamically changing frequently, making it difficult for traditional statistical models to meet the needs of refined management. This invention's deep learning-based traffic flow prediction method can achieve minute-level congestion trend prediction and cross-regional traffic migration analysis, and can be widely used in urban smart traffic management platforms, providing scientific decision support for traffic light control optimization, road resource allocation, and emergency response.

[0191] Furthermore, this invention can also be applied to public transportation scheduling and capacity optimization. In public transportation systems such as buses and subways, passenger flow fluctuates greatly and exhibits distinct time-of-day characteristics. This invention can be applied to public transportation scheduling and capacity prediction systems, enabling the early identification of peak passenger flows through intelligent analysis of real-time and historical passenger flow data. This assists in formulating flexible scheduling plans and vehicle deployment strategies, thereby improving the efficiency of public transportation services.

[0192] Furthermore, this invention can also be applied to highways and smart mobility services. In highway and long-distance transportation scenarios, the accuracy of traffic flow prediction directly affects toll collection strategies, road safety, and travel experience. This invention can combine spatial topology and historical pattern memory to model long-distance dependencies between road segments, support cross-regional traffic migration prediction, and assist highway operators in congestion management, emergency response, and smart mobility services.

[0193] Furthermore, this invention can also be applied to intelligent navigation and vehicle-to-everything (V2X) applications. With the development of V2X and autonomous driving, the demand for real-time traffic prediction is becoming increasingly urgent. This invention can serve as the core prediction engine of an intelligent navigation system, deployed via edge computing in in-vehicle terminals or roadside units, providing users with high-precision traffic prediction and optimal route recommendations, thereby improving travel efficiency and driving safety.

[0194] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A deep learning-based traffic flow prediction method, characterized in that, The method comprises the following steps: Step S1: Real-time collection of traffic flow data of a road by a traffic sensor node, and acquisition of regional road network map data; Step S2: constructing a memory tensor enhanced Transformer fusion model, the memory tensor enhanced Transformer fusion model comprising a data embedding layer, a feature extraction layer, a skip connection layer, and an output layer; the feature extraction layer comprising a spatiotemporal memory feature extraction layer; Step S3: Input of the traffic flow data and the regional road network map data into a data embedding layer for preprocessing, to obtain preprocessed data; Step S4: Input of the preprocessed data into a feature extraction layer for spatiotemporal memory triple attention and multilayer perception processing, to obtain a plurality of spatiotemporal memory feature extraction layer outputs; Step S5: Input of each spatiotemporal memory feature extraction layer output into a skip connection layer for accumulation to obtain a skip connection result; Step S6: Input of the skip connection result into an output layer for twice convolution operations, to be mapped into a traffic flow prediction result in a node channel dimension. 2.The deep learning based traffic flow prediction method according to claim 1, characterized in that, The preprocessing of the data embedding layer in step S3 comprises numerical feature embedding, time position encoding, day period embedding, week period embedding, and spatial position encoding, to finally obtain the preprocessed data; the preprocessing process of the data embedding layer is represented as follows: wherein, denotes pre-processed data; denotes numerical feature embeddings; denotes temporal position encoding generated based on a sine-cosine function; denotes day-of-week embedding; denotes week-of-year embedding; denotes spatial position encoding based on a graph Laplacian matrix. 3.The deep learning based traffic flow prediction method according to claim 2, characterized in that, Each spatiotemporal memory feature extraction layer comprises a time self-attention module, a first residual connection and layer normalization module, a spatial self-attention module, a second residual connection and layer normalization module, a memory self-attention module, a third residual connection and layer normalization module, a feedforward neural network module, and a fourth residual connection and layer normalization module; each spatiotemporal memory feature extraction layer performs the following operations: Step S41: The time self-attention module performs self-attention processing in a time dimension on the preprocessed data, to obtain time attention scores; the time attention scores and the preprocessed data are subjected to first residual connection and layer normalization processing, to obtain time attention output; Step S42: The spatial self-attention module learns interaction relationships between different nodes from the time attention output, to obtain spatial attention scores; the spatial attention scores and the time attention output are subjected to second residual connection and layer normalization processing, to obtain spatial attention output; Step S43: The memory self-attention module performs multi-head attention calculation processing on the spatial attention output for memory enhancement, to obtain memory attention scores; The memory attention scores and the spatial attention output are subjected to third residual connection and layer normalization processing, to obtain memory attention output; Step S44: The feedforward neural network module performs fully connected transformation and nonlinear activation processing on the memory attention output, to obtain feedforward network output features; The feedforward network output features and the memory attention output are subjected to fourth residual connection and layer normalization processing, to obtain the spatiotemporal memory feature extraction layer output. 4.The deep learning based traffic flow prediction method according to claim 3, characterized in that, In step S41, the preprocessed data is mapped into a time query vector, a time key vector, and a time value vector by two-dimensional convolution, and is represented as follows: wherein, denotes a time query vector; denotes a time key vector; denotes a time value vector; denotes pre-processed data; denotes a time query linear projection matrix; denotes a time key linear projection matrix; denotes a time value linear projection matrix; The time query vector, the time key vector, and the time value vector are subjected to multi-head attention mechanism to obtain time attention scores, and are represented as follows: wherein, denotes the temporal attention score; denotes the query projection matrix of the th temporal attention head; denotes the key projection matrix of the th temporal attention head; denotes the value projection matrix of the th temporal attention head; denotes the temporal attention output projection matrix; denotes the th temporal attention head; denotes the number of temporal attention heads; denotes the temporal output projection matrix; denotes the temporal attention head dimension; denotes the normalization exponential function; denotes the concatenation function; temporal attention score with pre-processed data After the first residual connection and layer normalization, the temporal attention output is obtained, which is represented as follows: wherein, denotes a temporal attention output; denotes a layer normalization function. 5.The deep learning based traffic flow prediction method according to claim 4, characterized in that, In step S42, the time attention output is mapped into a space query vector, a space key vector, and a space value vector by two-dimensional convolution, and is represented as follows: wherein, denotes a spatial query vector; denotes a spatial key vector; denotes a spatial value vector; denotes a spatial query linear projection matrix; denotes a spatial key linear projection matrix; denotes a spatial value linear projection matrix; The space query vector, the space key vector, and the space value vector are subjected to multi-head attention mechanism to obtain spatial attention scores, and are represented as follows: wherein, denotes a spatial attention score; denotes a th spatial attention head; denotes the number of spatial attention heads; denotes a spatial output projection matrix; denotes a th query projection matrix of a spatial attention head; denotes a th key projection matrix of a spatial attention head; denotes a th value projection matrix of a spatial attention head; denotes a spatial attention head dimension; denotes a geographical topology constraint mask; spatial attention score temporal attention output the spatial attention output is obtained through the second residual connection and the layer normalization processing, and is represented as follows: wherein, represents the spatial attention output. 6.The deep learning based traffic flow prediction method according to claim 5, characterized in that, In step S43, the memory self-attention module introduces a global memory tensor, and maps the spatial attention output to generate a memory query vector, a memory key vector and a memory value vector by two-dimensional convolution, and is expressed as follows: wherein, represents a global memory tensor, , represents a number of nodes, represents a memory tensor dimension; represents a linear mapping function; represents a memory query vector; represents a memory key vector; represents a memory value vector; represents a memory query linear projection matrix; represents a memory key linear projection matrix; represents a memory value linear projection matrix; The memory query vector, the memory key vector and the memory value vector are subjected to a multi-head attention mechanism to obtain a memory attention score, and is expressed as follows: wherein, represents a memory attention score; represents a th memory attention head; represents a number of memory attention heads; represents a memory output projection matrix; represents a th memory attention head query projection matrix; represents a th memory attention head key projection matrix; represents a th memory attention head value projection matrix; represents a memory attention head dimension; memory attention score spatial attention output the memory attention output is obtained through the third residual connection and layer normalization processing, and is represented as follows: wherein, represents the memory attention output. 7.The deep learning based traffic flow prediction method according to claim 6, characterized in that, The operations performed in step S44 are expressed as follows: wherein, denotes the spatio-temporal memory feature extraction layer output, denotes the feedforward neural network. 8.The deep learning based traffic flow prediction method according to claim 7, characterized in that, In step S5, the first spatio-temporal memory feature extraction layer outputs a value represented as , and the second spatio-temporal memory feature extraction layer participates in the calculation of the value of the skip connection in the following manner: wherein, represents the value of the i-th spatio-temporal memory feature extraction layer participating in the skip connection; represents the value of the i-th spatio-temporal memory feature extraction layer participating in the skip connection; represents a convolution with a size of 1x1; All values participating in the skip connection are accumulated to obtain a skip connection result, and is expressed as follows: wherein represents a jump connection result.

Citation Information

Patent Citations

  • A text classification method based on a local and global mutual attention mechanism

    CN109902293A

  • Traffic flow prediction method based on space-time attention mechanism

    CN117972633A

  • U-Net pathological cell segmentation method and device based on multi-scale Transform multi-attention

    CN118379303A

  • DSTMAN-based traffic prediction method

    CN119028127A

  • Traffic flow prediction method based on space-time frequency adaptive embedding and multi-scale trend perception attention

    CN119380541A

Cited By

  • Expressway section traffic flow prediction method and system

    CN121904995A