A method for predicting traffic flow at multiple intersections

By combining deep learning methods such as Transformer and CNN, the spatial and temporal features of traffic flow at multiple intersections are extracted, which solves the problems of difficulty in mining nonlinear spatiotemporal relationships and inefficiency due to long-term dependence in existing technologies for traffic flow prediction at multiple intersections. This achieves more efficient traffic flow prediction and overall traffic system optimization.

CN115358462BActive Publication Date: 2026-04-28HANGZHOU DIANZI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU DIANZI UNIV
Filing Date
2022-08-18
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing traffic flow prediction methods are difficult to effectively uncover the nonlinear spatiotemporal correlations between multiple intersections, and traditional models are inefficient in handling long-term dependencies, failing to comprehensively improve the overall traffic efficiency of cities.

Method used

We employ a deep learning approach based on Transformer and CNN to construct a traffic flow prediction model for multiple intersections. We extract spatial features using CNN and capture temporal correlations using Transformer. We combine this with an average pooling layer to learn the periodic characteristics of traffic flow, thereby reducing the performance degradation caused by long-term dependencies.

Benefits of technology

It improves the accuracy and efficiency of traffic flow prediction at multiple intersections, reduces training time, better captures the overall trend of traffic flow, avoids congestion problems at adjacent intersections caused by single intersection improvements, and enhances the overall operational efficiency of the urban transportation system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115358462B_ABST
    Figure CN115358462B_ABST
Patent Text Reader

Abstract

The application discloses a kind of associated multi-intersection traffic flow prediction methods.The steps of the present application are as follows:1, collect the traffic flow data of associated intersections, and divide the intersection traffic data into training set, validation set and test set after preprocessing;2, use CNN to extract spatial features from the input intersection traffic data;3, use Transformer to extract time features by inputting spatial features;4, after the Decoder layer is fully executed, the three time window data are finally input into three vectors, and the three vectors are stacked and input into the average pooling layer;5, set the model parameters;6, train the model until the maximum training period, and use the final model to predict the traffic flow of associated multi-intersections.The application uses CNN and Transformer to extract the spatial and temporal features of associated multi-intersections.Learning time encoding is used to embed the position encoding of Transformer, which injects position information and time information into the model together, helping the model to better learn the time features of traffic volume.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of deep learning. It provides a method for predicting traffic flow at associated multi-intersections, specifically a deep learning method based on Transformer and CNN for predicting traffic flow at associated multi-intersections. Background Technology

[0002] In the face of complex traffic environments, predicting traffic flow parameters can improve the utilization rate of urban road resources, provide insights into parameter trends over the next few days, weeks, and months, and offer data support and accurate traffic guidance information for urban traffic signal control. Traffic flow prediction is a spatiotemporal sequence problem, utilizing the temporal and spatial information contained in data to predict future traffic flow at different intersections within a region.

[0003] Intersections are the most complex parts of road networks because they involve various objects, such as vehicles and pedestrians. With increasing traffic demand, traffic congestion at urban intersections is becoming increasingly serious. Numerous studies have been conducted on traffic flow prediction at intersections. For example, Wenrui Qu et al. established a two-layer superposition model for short-term traffic flow prediction at intersections by integrating k-nearest neighbor (KNN) and Elman neural network modeling methods. While this method can improve prediction accuracy to some extent, traditional methods struggle to uncover the deep relationships between different traffic time series data due to the complex nonlinear spatiotemporal correlations between them. Therefore, deep learning methods are a good choice for traffic flow prediction tasks. Daeho Kim et al. proposed a cooperative traffic signal control method (TFP-CTSC) based on multi-intersection traffic flow prediction. This method uses an LSTM model for traffic flow prediction. Although it uses the LSTM sequence model to extract the temporal features of traffic flow, it does not consider the spatial information present in the multi-intersection traffic flow data. Wan Li et al. proposed a novel Deep Inter-Spatiotemporal Network (DISTN) for traffic flow prediction. It considers using Convolutional Neural Networks (CNN) and Long Short-Term Memory Networks (LSTM) to extract the spatial and temporal features of traffic flow, applying deep learning methods to intersection traffic volume prediction. Although this method analyzes the spatiotemporal features of the data, the LSTM model has the disadvantages of not being able to be trained in parallel and being unable to handle particularly long dependencies. Summary of the Invention:

[0004] The purpose of this invention is to propose a novel method for predicting traffic flow at multiple intersections, addressing the aforementioned problems. The technical solution adopted by this invention to solve its technical problems includes the following steps:

[0005] Step 1: Create a dataset of traffic flow at associated intersections.

[0006] This invention collects traffic flow data from relevant intersections based on the specific traffic area of ​​the application, i.e., intersection vehicle flow data. Simultaneously, the collected intersection vehicle flow data is preprocessed and divided into training, validation, and test sets in a 2:2:1 ratio.

[0007] This invention uses min-max normalization for data preprocessing, and the specific processing procedure is as follows:

[0008] When data x is centered by its minimum value and then scaled by its range (maximum value - minimum value), the data converges to the range [0, 1]. Normalization reduces the optimization range, making the optimization process smoother and more likely to converge correctly to the optimal solution. The calculation formula is shown below:

[0009]

[0010] Step 2: Use CNN to extract spatial features.

[0011] The model proposed in this invention takes intersection traffic flow data from three time windows as input: traffic flow data from the previous time window, traffic flow data from the week preceding the previous time window, and traffic flow data from the month preceding the previous time window. Each time window contains H time steps, and the traffic flow data for each time step is described as a two-dimensional matrix.

[0012] The input is processed separately for each of the three time windows, that is, the H two-dimensional matrices from each time window are stacked and input into a CNN (Convolutional Neural Network). Two-dimensional convolutional layers are used to extract the spatial features of the associated intersections. The output of the nth convolutional layer at time t is shown. It will go through a residual connection. Finally, it goes through a fully connected layer and is transformed into a one-dimensional feature vector Y. t The spatial feature vector Y t It is used as input to the Transformer network to capture temporal correlations.

[0013] Step 3: Use the Transformer network to extract temporal features.

[0014] The input to the Transformer network is a sequence of spatial feature vectors containing H time steps, denoted as (Y t-H Y t-H+1 , ..., Y t ), where Y tIt is a spatial feature vector output from the traffic flow data at time step t, after passing through n convolutional layers. This network is used to train the network to predict the traffic flow of all associated intersections in the next H time steps.

[0015] The input data has the shape [H, M], where M represents the total number of traffic flow directions at all associated intersections at each time step, and H represents the number of time steps.

[0016] Transformer is a Seq2Seq model that receives input from the Encoder layer and obtains output from the Decoder layer.

[0017] Step 4: After the Decoder layer has finished executing, the final outputs of the three time windows are Z... now Z week Z month These three vectors are stacked and then fed into an average pooling layer. Average pooling averages the values ​​of neighboring feature points, integrating these points to obtain new features. Compared to fully connected layers, average pooling significantly reduces network parameters, thereby reducing overfitting.

[0018] Step 5: Set model parameters.

[0019] Set the number of training epochs and the learning rate α. Set a loss function to measure the model's performance. The loss function formula is shown below:

[0020]

[0021] Where α represents the learning rate, and Loss represents the loss function. q represents the predicted traffic data. t+1 This represents the actual traffic flow data. The loss function measures how close the predicted output value is to the actual value, that is, the error between the predicted traffic flow in the next time window and the actual traffic flow in the next time window.

[0022] To more comprehensively evaluate the algorithm's predictive performance, this invention uses two loss functions, mean squared error (MSE) and mean absolute error (MAE), to measure the model's predictive effectiveness. These are both commonly used regression loss functions and can effectively quantify the model's predictive performance.

[0023] Finally, an optimization algorithm needs to be set. Using a suitable optimization algorithm can effectively improve the training speed of the model. Gradient descent is a method for finding the objective function, i.e., minimizing the loss function. It uses gradient information to iteratively adjust parameters to find a suitable target value and is one of the most widely used optimization algorithms in neural networks. This invention uses Adam as the optimization algorithm for the model.

[0024] Step 6: Stop training when the algorithm reaches its maximum training cycle. Use the final traffic flow prediction model to perform traffic flow prediction tasks on associated multi-intersections.

[0025] The beneficial effects of this invention are:

[0026] (1) The traffic flow prediction of this invention is aimed at interconnected multi-intersections. Many existing studies are focused on single intersections. Improving traffic congestion at a single intersection may worsen congestion at adjacent intersections and cannot accurately improve overall traffic efficiency.

[0027] (2) This invention proposes a novel traffic flow prediction method for associated multi-intersections based on Transformer and CNN. The traffic flow data of associated multi-intersections is constructed as a two-dimensional matrix of shape (number of intersections × number of lanes), and then CNN is used to extract the spatial features of the associated multi-intersections. Innovatively, the Transformer model is used for intersection traffic flow prediction. Compared to LSTM, Transformer avoids recursion, allowing for parallel computation, reducing training time, and minimizing performance degradation due to long-term dependencies, while also exhibiting superior prediction accuracy. Furthermore, this invention considers the weekly and monthly cyclical trends of traffic volume, using average pooling layers to learn the cyclical characteristics of traffic flow.

[0028] In summary, addressing the shortcomings of the aforementioned models, this invention proposes a traffic flow prediction method for associated multi-intersections based on Transformer and CNN, specifically for traffic flow prediction at associated intersections. Convolutional Neural Networks (CNNs) and Transformers have achieved significant success in image processing and sequence modeling, respectively. Compared to LSTM, the Transformer model avoids recursion, allows for parallel computation to reduce training time, and minimizes performance degradation due to long-term dependencies. Furthermore, compared to LSTM, it offers greater structural flexibility and versatility, capturing a wider range of information correlations. In addition, this invention considers the weekly and monthly cyclical trends of traffic flow, using average pooling layers to learn the periodic characteristics of traffic flow. Attached Figure Description

[0029] Figure 1 This is a schematic diagram of a model provided in an embodiment of the present invention;

[0030] Figure 2 This is a schematic diagram of a CNN model provided in an embodiment of the present invention;

[0031] Figure 3This is a diagram of the Encoder layer structure of the Transformer provided in an embodiment of the present invention;

[0032] Figure 4 This is a diagram of the Decoder layer structure of the Transformer provided in an embodiment of the present invention;

[0033] Figure 5 This is a diagram of the average pooling layer structure provided in an embodiment of the present invention. Detailed Implementation

[0034] To enable those skilled in the art to better understand the technical content of this invention, the following embodiments will be used to describe it in detail. This invention proposes a novel method for predicting traffic flow at multiple intersections. The main work includes the following two aspects: 1) Based on various nonlinear spatial relationships at associated multiple intersections and the potential temporal dependencies in traffic volume, a traffic flow prediction method for associated multiple intersections based on Transformer and CNN (Convolutional Neural Network) is proposed. CNN and Transformer are used respectively to extract the spatial and temporal features of the associated multiple intersections. A learnable temporal encoding is used to embed the Transformer's positional encoding, injecting both positional and temporal information into the model to help the model better learn the temporal characteristics of traffic volume. Furthermore, this invention also considers the impact of traffic flow cycle trends on traffic flow prediction, using an average pooling layer to extract traffic flow cycle features.

[0035] The implementation of this embodiment of the invention includes the following steps:

[0036] Step 1: Create a dataset of traffic flow at associated intersections.

[0037] Traffic flow data from associated intersections is collected based on the specific traffic area where this method is applied, i.e., intersection vehicle flow data. This data is preprocessed and divided into training, validation, and test sets in a 2:2:1 ratio. This method uses min-max normalization as a data preprocessing technique. Specifically, after centering the data x by its minimum value, it is scaled by its range (maximum value - minimum value), converging the data to the range [0,1]. Normalization reduces the optimization range, making the optimization process smoother and more likely to converge to the optimal solution correctly. The calculation formula is shown below:

[0038]

[0039] The model takes into account external factors such as morning rush hour, weekends, and holidays, which enhances the randomness.

[0040] Step 2: Use CNN to extract spatial features.

[0041] The model structure of this invention is as follows Figure 1 As shown. The model input contains traffic flow data for three time windows, namely the traffic flow data of the previous time window (X). t-H X t-H+1 , ..., X t ), the data at the same time one week before the previous time window (X) t-H-week X t-H-week+1 , ..., X t-week ), the data at the same time one month before the previous time window (X) t-H-month X t-H-month+1 , ..., X t-month Each time window contains H time steps, and the traffic flow data at each time step can be described as a two-dimensional matrix. The three input time windows are processed separately, that is, the H two-dimensional matrices from each time window are stacked and input into the CNN.

[0042] Since intersections are often interconnected, upstream and downstream intersections can affect traffic flow prediction at the target intersection. This invention uses a CNN to extract spatial features of associated intersections. The input to the CNN is a time window containing traffic flow data over H time steps.

[0043] At time step t, the historical traffic data of a given road network can be described as a matrix:

[0044]

[0045] In this matrix, the superscript for each element is formatted as (intersection number - traffic direction number), and the subscript represents the time step t. Each row of the matrix represents the traffic flow for all traffic directions at the Nth target intersection at time t. As shown in the figure, each intersection has 12 traffic directions. Therefore, the traffic flow data has 12 columns, and each column of the matrix represents the traffic volume for a specific traffic direction from intersection 1 to intersection N.

[0046] When the data at a time step can be described as a matrix, it is easy to think of using that matrix as input to a CNN.

[0047] The convolution model of this invention is as follows: Figure 2 As shown, spatial features of the associated intersection are extracted using a two-dimensional convolutional layer with a kernel size of (2, 2) and a padding size of (2, 1). A ReLU and Dropout layer is then added after the convolution.

[0048] The output of the nth convolutional layer at time t It will go through a residual connection. Finally, it goes through a fully connected layer and is transformed into a one-dimensional feature vector Y. tThis vector is used as input to the Transformer network to capture temporal correlations.

[0049] Step 3: Use Transformer to extract time features.

[0050] The input to the Transformer is a sequence of spatial feature vectors containing H time steps, denoted as (Y t-H Y t-H+1 , ..., Y t ), where Y t It is a spatial feature vector output from traffic flow data at time step t, after passing through n convolutional layers, where H is the historical time step. This network is trained to predict traffic flow at all associated intersections in the next H time steps.

[0051] The input data has the shape [H, M], where M represents the total number of traffic flow directions at all associated intersections at each time step, and H represents the number of time steps.

[0052] Transformer is actually a Seq2Seq model, where the Encoder layer receives input and the Decoder layer obtains the output.

[0053] The Transformer's Encoder layer consists of two sub-layers:

[0054] The first sub-layer is Multi-Head Attention, which is used to compute the self-attention of the input.

[0055] The second sublayer is Feed Forward, which is a simple fully connected network.

[0056] A residual network was simulated at the end of each sub-layer, and the output formula for each sub-layer is as follows:

[0057] LayerNorm(x+Sublayer(x)) (3)

[0058] Encoder layer structure as follows: Figure 3 As shown. The input to the Encoder consists of the following three parts:

[0059] Input Encoding. In the original Transformer model, the input is a high-dimensional feature vector. This feature vector is obtained by converting the input text using word embedding methods such as Word2Vec, and is called the embedding vector. This invention uses fully connected layers to replace word embedding methods to encode the input data. After passing through the fully connected layers, the shape of the input data becomes [H, E], where H represents the number of time steps in the input and E represents the feature size of the input data.

[0060] Positional encoding. The Transformer adds an extra vector, PositionalEncoding, to the input of the Encoder layer. This vector has the same dimension as the embedding vector and is used to provide relative positional information. This vector determines the position of the current time step within the time window, and the Transformer can learn the positional information of the time step through this vector.

[0061] Global time encoding. Based on the Transformer model, this invention, in addition to using position encoding for local position embedding, also considers the effectiveness of timestamp information in practical applications. It uses the monthly position embedding, weekly position embedding, day of the week position embedding, hourly position embedding, and minute position embedding extracted from the timestamps of time series data as superimposed position encodings to form a learnable embedding.

[0062] Finally, the three vectors are added together and used as input to the Encoder layer.

[0063] The Transformer's Decoder layer consists of three sub-layers:

[0064] The first sub-layer is Masked Multi-Head Attention, which also computes the input's self-attention. However, since future information is unknown during generation, it's necessary to mask it. For a sequence, at time step t, the decoded output should only depend on the output before time t, not on the output after time t. Therefore, a masking operation is required.

[0065] The second sub-layer is Encoder-Decoder Attention. It performs attention calculations on the output of the Encoder layer and the output of the MaskedMulti-Head Attention sub-layer.

[0066] The third sub-layer is Feed Forward, which is the same as the Encoder layer.

[0067] The structure of the Decoder layer is as follows: Figure 4 As shown.

[0068] The input to the Decoder layer is a concatenation of the portion of historical data closest to the prediction data with an empty vector whose length is the same as the length of the data to be predicted.

[0069] Step 4: After the Decoder layer has finished executing, the final outputs of the three time windows are Z... now Z week Zmonth These three vectors are stacked and then fed into the average pooling layer. The structure of the average pooling layer is as follows: Figure 5 As shown, the calculation formula is as follows:

[0070]

[0071] in, This represents the predicted traffic data, and avgpooling() represents the pooling operation.

[0072] Step 5: Set model parameters.

[0073] Set the number of epochs for model training and the learning rate α. Set the loss function to measure the model's performance.

[0074] To more comprehensively evaluate the algorithm's prediction performance, this invention uses two loss functions, mean squared error (MSE) and mean absolute error (MAE), to measure the model's prediction performance. Where q i It is the actual value, and This is a predicted value.

[0075] (1) The mean squared error (MSE) is defined as follows:

[0076]

[0077] (2) The Mean Absolute Error (MAE) is defined as shown in the following formula:

[0078]

[0079] Finally, an optimization algorithm needs to be set. Using a suitable optimization algorithm can effectively improve the training speed of the model. Gradient descent is a method for finding the objective function, i.e., minimizing the loss function. It uses gradient information to iteratively adjust parameters to find a suitable target value and is one of the most widely used optimization algorithms in neural networks. This invention uses Adam as the optimization algorithm for the model.

[0080] Step 6: Stop training when the algorithm reaches its maximum training cycle. Use the final traffic flow prediction model to perform traffic flow prediction tasks on associated multi-intersections.

[0081] It should be understood that any parts not described in detail in this specification belong to the prior art. Those skilled in the art should understand that the above embodiments are merely to help readers understand the principles and implementation methods of the present invention, and the scope of protection of the present invention is not limited to such embodiments. All equivalent substitutions made based on the present invention are within the scope of protection of the present invention.

Claims

1. A method for predicting traffic flow at multiple intersections, characterized in that... Includes the following steps: Step 1: Collect traffic flow data of relevant intersections based on specific traffic areas, i.e., intersection vehicle flow data; and divide the intersection vehicle flow data into training set, validation set and test set after preprocessing. Step 2: Use CNN to extract spatial features from the input intersection traffic flow data; The model's input contains traffic flow data from three time windows, namely the traffic flow data from the previous time window (X). t-H X t-H+1 , ..., X t ), the data at the same time one week before the previous time window (X) t-H-week X t-H-week+1 , ..., X t-week ), the data at the same time one month before the previous time window (X) t-H-month X t-H-month+1 , ..., X t-month Each time window contains H time steps, and the traffic flow data of each time step is described as a two-dimensional matrix. The three input time windows are processed separately, that is, the H two-dimensional matrices in the data of each time window are stacked and input into the CNN. The CNN convolutional model uses a two-dimensional convolutional layer with a kernel size of (2, 2) and a padding size of (2, 1) to extract spatial features of associated intersections. A ReLU and Dropout layer is added after the convolution. The output of the nth convolutional layer at time t... It will go through a residual connection; finally, it will pass through a fully connected layer and be transformed into a one-dimensional feature vector Y. t The feature vector Y t As input to the Transformer network, it is used to capture temporal correlations; Step 3: Use the spatial features output by the CNN as input to the Transformer, and use the Transformer to extract temporal features; The input to the Transformer network is a sequence of spatial feature vectors containing H time steps, denoted as (Y t-H Y t-H+1 , ..., Y t ), where Y t The spatial feature vector output from the traffic flow data at time step t, after passing through n convolutional layers, is used to train a Transformer network to predict the traffic flow data of all associated intersections in the next H time steps. The shape of the input data is [H, M], where M represents the total number of traffic flow directions at all associated intersections at each time step, and H represents the number of time steps. Step 4: After the Transformer's Decoder layer has finished executing, the data from the three time windows will finally be output as Z. now Z week Z month ; Transform the three vectors Z now Z week Z month Stack the layers and feed them into an average pooling layer; Step 5: Set model parameters; Step 6: Train the model until the maximum training cycle, and use the final traffic flow prediction model to perform traffic flow prediction tasks on the associated multi-intersections.

2. The method for predicting traffic flow at multiple intersections according to claim 1, characterized in that... Step 1 divides the dataset into training set, validation set, and test set in a 2:2:1 ratio.

3. The method for predicting traffic flow at multiple intersections according to claim 2, characterized in that, After the preprocessed traffic flow data x is centered according to the minimum value, and then scaled according to the range, the data is converged to the range [0,1]; the range refers to the maximum value minus the minimum value. After normalization, the optimization process becomes smaller and smoother, making it easier to converge correctly to the optimal solution. The calculation formula is shown below:

4. A method for predicting traffic flow at multiple intersections according to claim 2 or 3, characterized in that, At time step t, the historical traffic flow data of a given road network is described as a matrix: In this matrix X, the superscript format is: intersection number - traffic flow direction number, and the subscript represents the time step t. Each row of the matrix represents the traffic flow of all traffic flow directions at the Nth target intersection at time t. Each intersection has 12 traffic flow directions, so there are a total of 12 columns of traffic flow data. Each column of the matrix represents the traffic volume of a certain traffic flow direction from intersection 1 to intersection N.

5. The method for predicting traffic flow at multiple intersections according to claim 4, characterized in that, The input to the Encoder consists of the following three parts: 1) Input encoding vector: A fully connected layer is used to encode the input data instead of the word embedding method. After passing through the fully connected layer, the shape of the input data becomes [H, E], where H represents the number of time steps of the input and E represents the feature size of the input data. 2) Positional Encoding Vector: An additional vector, Positional Encoding, is added to the input of the Encoder layer. This vector has the same dimension as the embedding vector and is used to provide relative position information. This vector determines the position of the current time step within the time window, and the Transformer can learn the position information of the time step through this vector. 3) Global time encoding vector: The monthly, weekly, day of the week, hourly, and minute positional embeddings extracted from the timestamps of the time series data are used to encode the superimposed positional codes and together form a learnable global time encoding vector. Finally, the three vectors are summed and used as input to the Encoder layer.

6. The method for predicting traffic flow at multiple intersections according to claim 5, characterized in that... After the Decoder layer has finished executing, the final outputs of the three time windows are Z. now Z week Z month Stack these three vectors and input them into the average pooling layer; the calculation formula is shown below: in, This represents the predicted traffic data, and avgpooling() represents the pooling operation.