Training method and device of flow prediction model, and traffic flow prediction method and device

By introducing convolutional layer, dynamic time module and convolutional attention module into the traffic flow prediction model, the shortcomings of the existing models in feature extraction and prediction accuracy are solved, and the accuracy of traffic flow prediction is significantly improved.

CN119274357APending Publication Date: 2025-01-07CIVIL AVIATION UNIV OF CHINA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411503777.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-01-07

AI Technical Summary

Technical Problem

The existing short-term traffic flow prediction models have shortcomings in feature extraction and prediction accuracy, especially the description quality of LSTM, GRU, and SAEs models is not high, and the important part of the feature extraction is insufficient, resulting in poor prediction results.

Method used

A traffic prediction model training method is proposed. By obtaining the historical data of traffic flow, dividing and normalizing the different time scales, combining the convolutional layer, dynamic time module and convolutional attention module, enhance the feature extraction ability and start training Predictive models to improve the accuracy of traffic flow prediction.

Benefits of technology

Through the combination of the dynamic time module and the convolution attention module, we can better pay attention to key features, improve the model's representation ability and decision-making accuracy, and improve the accuracy and identification performance of traffic flow prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119274357A_ABST
    Figure CN119274357A_ABST
Patent Text Reader

Abstract

The invention provides a flow prediction model training method and device, and a traffic flow prediction method and device, and relates to the technical field of road traffic monitoring, and the method comprises the steps: integrating information before a convolution layer through adding the convolution layer, and carrying out the further extraction of spatial features outputted by a target basic model, by combining the dynamic time module, the channel attention module and the space attention module, refining of input features is achieved, the model can pay attention to meaningful channels, space positions and time sequences at the same time, and therefore the representation capacity and decision accuracy of the model are improved. The dynamic time module and the convolution attention module can dynamically adjust the importance of each channel and spatial position in the features according to task requirements, so that the model can better pay attention to key features, and the recognition performance is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of road traffic monitoring, and specifically to a traffic flow prediction model training method and device, and a traffic flow prediction method and device. Background Art

[0002] With the development of urban economy and the continuous increase in the number of cars, traffic congestion in first- and second-tier cities has intensified and gradually spread to third- and fourth-tier cities. The traffic flow in different areas of the city reflects the travel needs of urban residents. Accurately and efficiently predicting the traffic flow in different areas is the basis for accurate vehicle dispatching and optimization of public transportation systems. It helps to alleviate urban traffic congestion and improve urban traffic efficiency, and is crucial to promoting the coordinated development of smart transportation and smart cities. Taking urban traffic congestion intersections as the research object, the short-term traffic flow prediction algorithm is used to explore the multi-time scale characteristics and spatiotemporal dependencies of traffic flow, and to achieve accurate prediction of short-term traffic flow.

[0003] The current short-term traffic flow prediction model is mainly based on the encoder-decoder model of deep learning, which has been widely used in the field of NLP, such as Transformer for machine translation, and its architecture is also used in the field of CV. Therefore, the architecture is used to design relevant algorithms to automatically extract the spatiotemporal correlation of traffic flow, construct a deep neural network, and realize the prediction of short-term traffic flow. However, in the traffic flow prediction models in related technologies, the LSTM, GRU, and SAEs models may face the problems of low description quality and insufficient extraction of important features. Summary of the invention

[0004] In view of the shortcomings of the related technologies mentioned above, the present application provides a traffic prediction model training method and device, and a traffic flow prediction method and device to solve the above technical problems.

[0005] The present application provides a flow prediction model training method, comprising: Acquire historical traffic flow data, and divide the historical traffic flow data into different time scales at different positions on the time axis to obtain historical traffic flow data to be processed; Normalizing the historical flow data to be processed to obtain intermediate historical flow data; Dividing the intermediate flow historical data based on the time-lag variable to obtain an initial data set, wherein the initial data set includes a plurality of flow historical data samples; Shuffling multiple traffic history data samples in the initial data set to obtain a target data set; Training an initial basic model based on the target data set to obtain a target basic model; A convolution layer, a dynamic time module and a convolution attention module are sequentially inserted after the feature extraction layer of the target basic model to obtain an initial prediction model; the dynamic time module is used to dynamically process the convolution output of the convolution layer to obtain output features, the convolution attention module includes a channel attention mechanism and a spatial attention mechanism, and the convolution attention module is used to extract features from the output features; An initial prediction model is trained based on the target data set to obtain a target prediction model, and the output of the target prediction model is a traffic flow prediction result.

[0006] In one embodiment of the present application, the dynamic time module includes a plurality of sequentially connected temporal convolution modules and a stop score prediction module connected to the output of each temporal convolution module; Among them, the temporal convolution module is used to perform causal convolution and dilated convolution on the input data, the input data of the temporal convolution module connected to the convolution layer is the convolution output of the convolution layer, the output data of the previous temporal convolution module is the input data of the current temporal convolution module, and the stop score prediction module is used to predict the stop score of the corresponding temporal convolution module, and when the cumulative stop score reaches a preset value, skip the remaining temporal convolution modules to obtain the output feature.

[0007] In one embodiment of the present application, an initial prediction model is trained based on the target data set to obtain a target prediction model, including: Loading the training weights of the target basic model into the initial prediction model; Inputting the traffic history data sample into the initial prediction model to obtain the convolution output of the convolution layer in the initial prediction model; Inputting the convolution output of the convolution layer into a dynamic time module to obtain output features of the dynamic time module; Extracting features from the output features based on a channel attention mechanism to obtain channel attention features; Extracting the channel attention feature based on the spatial attention mechanism to obtain the spatial attention feature; The spatial attention features are decoded to obtain a traffic flow prediction result.

[0008] In one embodiment of the present application, the convolution output of the convolution layer is input into a dynamic time module, and the output features of the dynamic time module include: (Formula 1) (Formula 2) (Formula 3) (Formula 4) in, Indicates The input data of the temporal convolution module is is an activation function, is the original dilation transformation, represents a logical function, Indicates The stopping fraction of the temporal convolutional modules, Indicates The weight parameters of the temporal convolution module, Indicates The bias of the temporal convolution module; (Formula 5) (Formula 6) Where N is the number of temporal convolution modules calculated, is a constant, Indicates remainder; (Formula 7) (Formula 8) in, represents the stopping probability of each temporal convolution module, Represents the output features of the dynamic time module.

[0009] In one embodiment of the present application, the initial basic model is a gated recurrent unit, a long short-term memory network, or a stacked autoencoder.

[0010] To achieve the above objectives and other related objectives, the present application provides a traffic flow prediction method, including: Obtain traffic flow data to be predicted; Call the pre-trained target prediction model; Based on the traffic flow data to be predicted and the target prediction model, a traffic flow prediction result is obtained; Wherein, the target prediction model is trained using one or more of the aforementioned traffic prediction model training methods.

[0011] To achieve the above objectives and other related objectives, the present application provides a flow prediction model training device, comprising: A sample acquisition module is used to acquire historical traffic flow data and divide the historical traffic flow data into different time scales at different positions on the time axis to obtain historical traffic flow data to be processed; A first processing module, configured to perform normalization processing on the historical flow data to be processed to obtain intermediate historical flow data; A second processing module is used to divide the intermediate flow history data based on the time lag variable to obtain an initial data set, wherein the initial data set includes a plurality of flow history data samples; A third processing module, configured to shuffle a plurality of traffic history data samples in the initial data set to obtain a target data set; A first training module is used to train an initial basic model based on the target data set to obtain a target basic model; A model building module, used to insert a convolution layer, a dynamic time module and a convolution attention module in sequence after the feature extraction layer of the target basic model to obtain an initial prediction model; the dynamic time module is used to dynamically process the convolution output of the convolution layer to obtain output features, the convolution attention module includes a channel attention mechanism and a spatial attention mechanism, and the convolution attention module is used to extract features from the output features; The second training module is used to train an initial prediction model based on the target data set to obtain a target prediction model, and the output of the target prediction model is a traffic flow prediction result.

[0012] To achieve the above objectives and other related objectives, the present application provides a traffic flow prediction device, comprising: A data acquisition module, used to acquire traffic flow data to be predicted; A calling module is used to call a pre-trained target prediction model; A prediction module, used to obtain a traffic flow prediction result based on the traffic flow data to be predicted and the target prediction model; Wherein, the target prediction model is trained using one or more of the aforementioned traffic prediction model training methods.

[0013] As described above, the traffic flow prediction model training method, device, and traffic flow prediction method and device provided by the present application have the following beneficial effects: A traffic prediction model training method in the present application, the method obtains a target basic model by first training an initial basic model, inserts a convolution layer, a dynamic time module and a convolution attention module in sequence after the feature extraction layer of the target basic model to obtain an initial prediction model, and trains the initial prediction model to obtain a target prediction model. Adding a convolution layer can integrate the information before the convolution layer, further extract the spatial features output by the target basic model, and refine the input features by combining the dynamic time module, the channel attention module and the spatial attention module, so that the model can simultaneously focus on meaningful channels, spatial positions and time series, thereby improving the model's representation ability and decision accuracy. The dynamic time module and the convolution attention module can dynamically adjust the importance of each channel and spatial position in the feature according to task requirements, which helps the model better focus on key features and improve recognition performance.

[0014] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings: Figure 1 is a flow chart of a traffic prediction model training method shown in an exemplary embodiment of the present application; Figure 2 is a schematic diagram of the structure of a dynamic time module and a convolutional attention module shown in an exemplary embodiment of the present application; Figure 3 is a flow chart of a traffic flow prediction method shown in an exemplary embodiment of the present application; Figure 4 is a structural block diagram of a flow prediction model training device shown in an exemplary embodiment of the present application; Figure 5 It is a structural block diagram of a traffic flow prediction device shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0016] The following will describe the implementation methods of the present application with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be understood that the preferred embodiments are only for illustrating the present application, not for limiting the scope of protection of the present application.

[0017] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application, and thus the drawings only show components related to the present application rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed at will, and the component layout may also be more complicated.

[0018] In the following description, a large number of details are discussed to provide a more thorough explanation of the embodiments of the present application. However, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present application difficult to understand.

[0019] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a traffic prediction model training method shown in an exemplary embodiment of the present application. Figure 1 It can be seen that the traffic prediction model training method may include: Step S110, acquiring historical traffic flow data, and dividing the historical traffic flow data into different time scales at different positions on the time axis to obtain historical traffic flow data to be processed.

[0020] In one embodiment of the present application, historical traffic flow data can be collected by a detector, and the acquired historical traffic flow data can be divided into different time scales at different positions on the time axis. For example, the California highway network PeMS traffic flow data set collects traffic flow data every 5 minutes, and 3 sensors are used to record 3 road characteristics, including vehicle volume, vehicle speed, and average road occupancy. Considering the periodicity of the time series, the acquired historical traffic flow data is divided according to the time series, and the subsequent process uses the time scale of the daily cycle as input data, and the daily cycle obtains the traffic flow data of the same period of the day before the period to be predicted.

[0021] Step S120, normalizing the historical flow data to be processed to obtain intermediate historical flow data.

[0022] In one embodiment of the present application, the obtained historical traffic data to be processed may be subjected to MinMaxScaler normalization processing to facilitate convergence during training. The MinMaxScaler normalization processing may include: ; in, represents the sample original traffic flow data (that is, the historical traffic data to be processed), Indicates the minimum value of sample data, Indicates the maximum value of sample data. Represents normalized data (that is, intermediate traffic historical data).

[0023] Step S130, dividing the intermediate flow history data based on the time lag variable to obtain an initial data set, which includes a plurality of flow history data samples.

[0024] In one embodiment of the present application, since the time series prediction task needs to use historical data to predict future data, the data can be divided using the time lag variable lags, and finally an initial data set of size (samples, lags) is obtained.

[0025] Step S140, shuffling multiple traffic history data samples in the initial data set to obtain a target data set.

[0026] In one embodiment of the present application, since the sampling process is performed in sequence, the divided initial data set still has a time series characteristic in the arrangement order. At this time, numpy.random.shuffle can be used to shuffle the data to disrupt the order of the traffic history data samples in the initial data set.

[0027] Step S150, training an initial basic model based on the target data set to obtain a target basic model.

[0028] It should be noted that the output of the target basic model is the basic prediction result, which is also the prediction result of the traffic flow.

[0029] In one embodiment of the present application, the training set, the validation set, and the test set can be divided into 60% training set, 20% validation set, and 20% test set ratios, and the training set in the target data set is used to train the initial basic model. The initial basic model can also be trained based on the target data set, and the trained initial basic model can be verified and tested using other pre-processed validation sets and test sets.

[0030] In one embodiment, the initial basic model may be a gated recurrent unit (GRU), a long short-term memory (LSTM), or a stacked autoencoder (SAEs).

[0031] Exemplarily, traffic history data samples in a training set may be input into a model with a multi-layer LSTM for training.

[0032] The basic model of LSTM can be expressed as: ; ; ; ; ; ; in, and Respectively represent the weight and bias of the forget gate, express The output of the input gate at any time, and Represent the weight and bias of the input gate respectively, express The candidate memory element at the moment, and Respectively The new weights and biases of the layers, and are the weight and bias of the output gate respectively, is the state of the previous moment, and uses Function as activation function, Indicates the current state. represents the forget gate (determines how much information in the cell state at the previous moment needs to be retained or forgotten), express The output of the gate at any time, represents the hidden state at the previous moment (t-1 moment), Indicates the hidden state at the current moment, express Input at the moment.

[0033] Exemplarily, traffic history data samples in the training set may be input into the GRU model for training.

[0034] The basic model of GRU can be expressed as: ; ; ; ; in, is the input at time t, is the hidden state at the current moment, is the hidden state at the previous moment, and are the weight and bias of the update gate respectively, and are the weights and biases of the reset gates, respectively. and are the weight parameters and bias parameters of the candidate hidden states, respectively. represents the update gate, Represents the reset gate, represents the candidate hidden state; Exemplarily, traffic history data samples in a training set may be input into a model with a SAEs encoder for training.

[0035] The basic model of SAEs can be composed of three autoencoders. The processing of a single autoencoder can be achieved by the following formula: ; ; in, , is the weight, , is the bias, Represents input data, represents the hidden layer output, represents the reconstructed input; is one activation function, and sigmoid is another activation function.

[0036] LSTM and GRU are trained as normal RNN networks. Use the train_model() function for training. SAEs training process: multiple SAEs are trained separately. After the first SAE is trained, its encoded output is used as the input of the second SAE, and then trained. Finally, after the training is completed, all the intermediate hidden layers of the SAEs are connected to form a SAEs network. The previous weights are used as the initial weights, and then the entire network is fine-tuned. Use the train_seas() function for training.

[0037] For example, the input traffic history data sample is calculated by the model to obtain the traffic flow prediction result, and the loss value is calculated according to the traffic flow prediction result and the true label, which can be achieved by cross entropy loss calculation. The specific formula is as follows: ; in, is the number of samples, i represents the i-th sample, k represents the k-th category, It is The samples belong to The true labels of the categories, The model predicts The samples belong to The predicted probability of each class.

[0038] For example, the input traffic history data sample is calculated by the model to obtain the traffic flow prediction result, and the loss value is calculated according to the traffic flow prediction result and the true label, which can be achieved by the mean square error loss calculation. The specific formula is as follows: ; in, is the sample size, For the The true value of the samples, For the The predicted value of a sample, i represents the i-th sample, and MSE represents the mean square error loss.

[0039] In addition, RMSprop can be used as an optimizer to optimize the network weights. You can use RMSprop (lr=0.001, rho=0.9, epsilon=1e-06) as the optimizer, batch_szie is 256, lags is 12 (that is, the lag length is one hour), the specific steps are as follows: Initialize the network weights of the above initial basic model to get the time step after initialization The weight parameter .in, All represent weights. At time step t, the value of the neurons in this layer can be expressed as a linear combination of the numerical weights of the neurons in the previous layer.

[0040] Randomly select Traffic history data samples and the corresponding labels .

[0041] Calculate the loss function on the selected samples with respect to the weight parameter The gradient is: ; in, is the i-th sample traffic flow data, for The corresponding label, is the time step after initialization The weight parameter, is the gradient vector, represents the loss function, m represents the number of sample traffic flow data, represents the initial parameters; Calculate its cumulative square gradient, that is, the mean direction quantity , the formula is as follows: ; in, is the time step The time-averaged direction quantity, is the mean direction quantity at the previous moment, is the decay rate, is the gradient vector.

[0042] Then calculate the weight parameter update, the formula is as follows: ; in, represents the weight update parameter, is the global learning rate, is a small constant, usually set to .

[0043] Update the weights according to the gradient parameters, the formula is as follows: ; in, Represents the updated weight parameter.

[0044] Step S160, inserting a convolutional layer, a dynamic time module and a convolutional attention module in sequence after the feature extraction layer of the target basic model to obtain an initial prediction model.

[0045] Among them, the dynamic time module is used to dynamically process the convolution output of the convolution layer to obtain output features, the convolution attention module includes a channel attention mechanism and a spatial attention mechanism, and the convolution attention module is used to extract features from the output features.

[0046] In one embodiment of the present application, the convolutional layer, the dynamic time module, and the convolutional attention module can be inserted after the feature extraction layer of the target base model. For example, when the target base model is LSTM, the convolutional layer, the dynamic time module, and the convolutional attention module can be inserted in sequence after the LSTM layer. When the target base model is GRU, the convolutional layer, the dynamic time module, and the convolutional attention module can be inserted in sequence after the GRU layer. When the target base model is SAEs, the convolutional layer, the dynamic time module, and the convolutional attention module can be inserted in sequence after the encoding layer. The convolutional layer, the dynamic time module, and the convolutional attention module are all located in the encoder of the target base model.

[0047] It should be noted that the convolutional layer can be used to integrate previous information and further extract the spatial features output by the target base model so that it can be input into the decoder later.

[0048] In one embodiment, the dynamic time module may include a plurality of sequentially connected temporal convolution modules and a stop score prediction module connected to the output of each temporal convolution module.

[0049] Among them, the temporal convolution module is used to perform causal convolution and dilated convolution on the input data. The input data of the temporal convolution module connected to the convolution layer is the convolution output of the convolution layer. The output data of the previous temporal convolution module is the input data of the current temporal convolution module. The stopping score prediction module is used to predict the stopping score of the corresponding temporal convolution module, and when the cumulative stopping score reaches the preset value, the remaining temporal convolution modules are skipped to obtain the output features.

[0050] Exemplarily, after the feature extraction layer of the above-mentioned target basic network (LSTM, GRU, SAEs), a convolutional layer, a dynamic time module and a convolutional attention module are sequentially inserted for further training. First, the feature data is dynamically processed by the dynamic time module so that it can obtain sufficient information from the variable input sequence. Then, the channel attention mechanism in the convolutional attention module adjusts the weight of each channel of the feature map, and then the spatial attention mechanism in the convolutional attention module is used to refine the features of each position.

[0051] Step S170, training an initial prediction model based on the target data set to obtain a target prediction model.

[0052] Among them, the output of the target prediction model is the traffic flow prediction result.

[0053] In one embodiment of the present application, an initial prediction model may be trained based on a target data set to obtain a target prediction model.

[0054] In an exemplary embodiment, the process of step S170 of training an initial prediction model based on a target data set to obtain a target prediction model may include steps S171 to S173.

[0055] Step S171, loading the training weights of the target basic model into the initial prediction model.

[0056] In one embodiment of the present application, loading the training weights of the target base model in the initial prediction model can accelerate the training process and improve model performance.

[0057] Step S172, inputting the traffic history data sample into the initial prediction model to obtain the convolution output of the convolution layer in the initial prediction model.

[0058] In one embodiment of the present application, a traffic history data sample may be input into an initial prediction model to obtain a convolution output of a convolution layer, after which a dynamic time module and a convolution attention module are inserted.

[0059] Step S173, input the convolution output of the convolution layer to the dynamic time module to obtain the output features of the dynamic time module.

[0060] In one embodiment of the present application, the convolution output of the convolution layer is input into the dynamic time module to obtain the output features of the dynamic time module, including: (Formula 1) (Formula 2) (Formula 3) (Formula 3) (Formula 4) in, Indicates The input data of the temporal convolution module is is an activation function, is the original dilation transformation, represents a logical function, Indicates The stopping fraction of the temporal convolutional modules, Indicates The weight parameters of the temporal convolution module, Indicates The bias of the temporal convolution module, represents the input data of the m-1th temporal convolution module, M represents the number of temporal convolution modules, represents the sigmoid function, represents global average pooling, and x represents intermediate data.

[0061] The stopping fraction of each temporal convolution module Depend on Function Compute, stopping fraction of the last temporal convolution module Set to 1 to force it to stop after this sequential convolutional module.

[0062] (Formula 5) (Formula 6) Where N is the number of temporal convolution modules calculated, is a constant, ensuring can be equal to 1, which means that the computation can stop after a single temporal convolution module. represents the remainder, n is the nth temporal convolution module; (Formula 7) (Formula 8) in, represents the stopping probability of each temporal convolution module, Represents the output features of the dynamic time module, which is the sum of the outputs of the temporal convolutional module, weighted by the stopping probability.

[0063] It should be noted that the Temporal Convolutional Network (TCN) is a neural network architecture for processing time series data. The Temporal Convolutional Network can include multiple Temporal Convolutional Modules (TCN Block), each of which can perform causal convolution and dilated convolution on the input features. The convolution output of the convolution layer is input into the first Temporal Convolutional Module as the input feature of the dynamic time module. After that, the input feature of each Temporal Convolutional Module is the output feature of the previous Temporal Convolutional Module. The input features are causally convolved and dilated, which is achieved by the following formula: ; ; in, represents the sequence of input features, Represents a filter set, represents the convolution operation, Indicates convolution kernels, represents the convolution kernel size, Indicates the sequence element number, represents the dilation factor, F represents the convolution kernel set, and r represents the sequence data.

[0064] In the embodiments of the present application, effective information can be extracted to a certain extent, reducing the amount of calculation.

[0065] Step S174, extracting the output features based on the channel attention mechanism to obtain channel attention features.

[0066] In one embodiment of the present application, the dynamic time module and the convolutional attention module are complementary in terms of spatial and channel attention. When processing dynamic changes in graph structure, the ability of the temporal convolution module to process temporal data is also combined to effectively fuse spatiotemporal information. The output features generated by the dynamic time module are used as the input feature map (H×W×C) of the convolutional attention module to perform attention learning in the channel and spatial dimensions.

[0067] Then the new output features are obtained Through the channel attention mechanism in the convolutional attention module, the input feature vector is a three-dimensional matrix (H×W×C). , respectively through global maximum pooling and global average pooling; Subsequently, the feature map is compressed in two dimensions to obtain feature descriptions of two different dimensions (1×1×C). The final merged feature map shares an MLP network with the number of neurons in the first layer being , is the reduction rate, and the activation function is , the number of neurons in the second layer is ; These two feature maps are then superimposed on the channel dimension by The activation function is multiplied by the initial input to obtain the final channel attention feature map (H×W×C). ,The specific feature processing process can be achieved through the following formula: ; ; ; in, is the initial input feature (that is, the output feature generated by the dynamic time module), and Represent the global average pooling feature and the global maximum pooling feature respectively, and are the two weights of the MLP network layer, It is the channel output feature that finally passes through the channel attention module.

[0068] Step S175, extract the channel attention features based on the spatial attention mechanism to obtain the spatial attention features.

[0069] In one embodiment of the present application, the obtained channel attention module output feature map Input into the spatial attention mechanism, the first step is to Global average pooling and global maximum pooling are performed respectively. This process produces two feature maps (H×W×1). and ; Then the channel connection is performed to connect them to generate a valid feature descriptor (each represents the global average pooling and global maximum pooling features of the entire channel). On the connected feature descriptors, convolution is used to generate a 2D spatial attention map Finally, by Activation function and current stage input feature map Multiply them together to get the final spatial attention feature map (H×W×C), ,The specific feature processing process can be achieved through the following formula: ; ; ; in, is the channel output feature, and Represent the global average pooling feature and the global maximum pooling feature respectively, It is a 3×3 convolutional layer. Note the features for the space.

[0070] See also Figure 2 , which is a schematic diagram of the structure of a dynamic time module and a convolutional attention module shown in an exemplary embodiment of the present application. The dynamic time module may include M sequential convolution modules, each of which may correspond to a stopping fraction h M (represents the stop score of the Mth temporal convolution module), hSum is the sum of all previous stop scores. If hSum is greater than 1, the remaining temporal convolution modules are skipped, and the outputs of all previous temporal convolution modules are weighted and summed based on the stop probability to obtain the output features, which are then input into the Convolutional Block Attention Module (CBAM). If hSum is less than or equal to 1, the output of the previous temporal convolution module is input into the next temporal convolution module.

[0071] Step S176, decoding the spatial attention features to obtain traffic flow prediction results.

[0072] In one embodiment of the present application, the spatial attention feature can be input into the decoder as an input feature of the decoder to obtain the final traffic flow prediction result.

[0073] In another exemplary embodiment of the present application, the process of training the initial prediction model based on the training set to obtain the target prediction model in step S170 may also include: 1) The input traffic history data samples are calculated by the initial prediction model to obtain the traffic flow prediction results, and the loss value is calculated based on the traffic flow prediction results and the true label. The loss value can be calculated by the cross entropy loss function, and the specific formula is as follows: ; in, is the sample size, It is The samples belong to The true labels of the categories, The model predicts The samples belong to The predicted probability of each class.

[0074] The loss value can also be calculated by the mean square error loss function. The specific formula is as follows: ; in, is the sample size, is the true value, is the predicted value; 2) Through back propagation, the gradient is calculated backwards along the computational graph of the initial prediction model, starting from the loss function, and the chain rule is used to calculate the gradient of the loss function to the network parameters, the influence of each network parameter on the loss function is obtained, and the network parameters are updated according to the gradient.

[0075] 3) Optimize the model based on the optimizer, which can be SGD. The specific steps are as follows: Randomly initialize the matrix of the above network weights to obtain the initialized weight matrix ; Randomly select a sample from the target dataset (which can be the training set) and the corresponding labels ; In the sample The loss function is calculated on The gradient of ; Update the weights according to the gradient, the formula is as follows: ; in, is at the time step The model parameters, is The loss function Relative to model parameters The gradient of is the learning rate, which controls the update step size; Set the maximum number of iterations to , repeat the above steps until the maximum number of iterations is reached.

[0076] 4) Limit the initial prediction model based on regularization to prevent the model from overfitting. The Dropout method can be used to prevent the model from overfitting. The specific steps are as follows: In each layer of the neural network of the initial prediction model, Dropout is used with probability A portion of hidden neurons are randomly selected for deletion, and the input and output neurons remain unchanged so that they do not participate in the calculation in this forward and backward propagation. This process is achieved by generating a random 0, 1 vector, where 1 indicates that the neuron is retained and 0 indicates that the neuron is deleted. The generation of this random vector follows the Bernoulli distribution (the probability of each neuron being 1 is ); Then the input is forward propagated through the modified neural network, the result is calculated by the loss function, and the loss result is back-propagated through the modified neural network; The output of the selected neurons (i.e. neurons that are not deleted) is multiplied by a randomly generated mask vector , each neuron in this vector is either 1 or 0, corresponding to the random vector generated in the previous step, which is achieved by the following formula: ; in, represents the output after applying Dropout, is a randomly generated mask vector, is the original output; After executing this process, the corresponding network weights are updated according to the SGD method on the neurons that have not been deleted. The formula is as follows: ; This step is to update the weights of neurons that were not deleted in the previous process in the Dropout method, restore the deleted neurons, and then update the neurons that were not deleted. Then, the above process is repeated continuously to prevent overfitting of the model.

[0077] When testing the initial prediction model, in order to ensure the consistency of the model's output, the weight parameters need to be adjusted, that is, the weight parameters of each neuron need to be multiplied by the probability , because some neurons are randomly deleted during the retraining process, which is equivalent to the weight of each neuron being reused Therefore, when testing the initial prediction model, it is necessary to adjust the weight parameters of each neuron in the model. The formula is as follows: ; Among them, the probability of each neuron being 1 is , represents the optimized weight parameter, Represents the weight parameter in the testing phase.

[0078] In one embodiment of the present application, three initial prediction models can be trained separately, and the three initial prediction models are obtained based on different target basic models. For example, an initial prediction model can be obtained based on an LSTM model, an initial prediction model can be obtained based on a GRU model, and an initial prediction model can be obtained based on an SAEs model. The three initial prediction models can be trained separately to obtain three target prediction models, namely DyTCBA-LSTM, DyTCBA-GRU, and DyTCBA-SAEs. Three traffic flow prediction results can be obtained based on the same input data and compared with real-time traffic data.

[0079] Explained-variance-score, mean absolute percentage error MAPE, mean absolute error MAE, root mean square error RMSE and determination coefficient R2 (R-Square) are used as evaluation indicators to evaluate the final traffic flow prediction results, and the prediction accuracy of the corresponding target prediction model is analyzed. The specific formula is as follows: ; ; ; ; ; in, is the number of samples, is the true value, is the predicted value, is the average value, is the variance. It can be seen from the formula that the larger the calculated values ​​of the two evaluation indicators, explained-variance-score and R2, the smaller the calculated values ​​of the three evaluation indicators, MAPE, MAE, and RMSE, which means that the prediction effect of the model is better and the prediction result accuracy is higher.

[0080] As shown in Table 1, the explained-variance-score of the DyTCBA-LSTM model is 0.92, which is closest to 1, indicating the best fitting effect. Subsequently, the SAEs model is second, and the GRU performs the worst. In addition, the mean absolute percentage error (MAPE) of the DyTCBA-LSTM model is 32.53%, the mean absolute error (MAE) is 8.53, and the root mean square error (RMSE) is 12.42, all showing excellent fitting effects. In addition, the R2 score of the DyTCBA-LSTM model is 0.91, which is also closest to 1, indicating the best fit. Considering these five indicators comprehensively, the DyTCBA-LSTM model has the best fitting effect.

[0081] Table 1 Prediction effect of each target prediction model on highway traffic flow data in area A .

[0082] In summary, the scheme of the embodiment of the present application obtains the target basic model by first training the initial basic model, inserts the convolution layer, dynamic time module and convolution attention module in sequence after the feature extraction layer of the target basic model, obtains the initial prediction model, and trains the initial prediction model to obtain the target prediction model. Adding a convolution layer can integrate the information before the convolution layer, further extract the spatial features output by the target basic model, and refine the input features by combining the dynamic time module, the channel attention module and the spatial attention module, so that the model can simultaneously focus on meaningful channels, spatial positions and time series, thereby improving the model's representation ability and decision accuracy. The dynamic time module and the convolution attention module can dynamically adjust the importance of each channel and spatial position in the feature according to task requirements, which helps the model to better focus on key features and improve recognition performance.

[0083] See also Figure 3 , Figure 3 is a flow chart of a traffic flow prediction method shown in an exemplary embodiment of the present application. Figure 3 It can be seen that the traffic flow prediction method may include: Step S310, obtaining traffic flow data to be predicted.

[0084] Step S320, calling a pre-trained target prediction model.

[0085] Step S330, obtaining a traffic flow prediction result based on the traffic flow data to be predicted and the target prediction model.

[0086] The target prediction model is trained using the traffic prediction model training method provided in any of the aforementioned embodiments.

[0087] In one embodiment of the present application, the historical traffic flow feature vector (that is, the traffic flow data to be predicted) is input into a trained target prediction model.

[0088] For example, the initial basic model is an LSTM neural network model. The first step in the forward propagation of the data feature vector of the traffic flow data predicted by the LSTM neural network model is to update the forget gate. This step determines the way the information passes through the sigmoid function neural layer by reading the input value. (hidden state) and (Time step Traffic flow data at the time of the traffic flow) to represent the passing information. The LSTM workflow in the target prediction model can be specifically expressed by the following formula: ; in, and Represent the weight and bias of the forget gate respectively, and use Function as activation function.

[0089] The second step is to update the cell's status value and use The layer generates an updated replacement value, which is implemented by the following formula: ; ; in, express The input gate output at any time, express The candidate memory element at the moment, and Represent the weight and bias of the input gate respectively, and Respectively New weights and biases for the layer.

[0090] Then the state Updated to , and by the state Determine the value to be output, using the following formula: ; ; ; in, and are the weight and bias of the output gate respectively, first through Function output, and then through Layer processing and The output weights of the layers are multiplied to get the final output result.

[0091] The initial basic model is the GRU neural network model. GRU's processing of data feature vectors can be achieved through the following formula: ; ; ; ; in, is the input at time t, is the hidden state at the current moment, is the hidden state at the previous moment, and are the weight and bias of the update gate respectively, and are the weights and biases of the reset gates, respectively. and are the weight parameters and bias parameters of the candidate hidden states, respectively. represents the update gate, Represents the reset gate, represents a candidate hidden state.

[0092] The initial basic model is the SAEs neural network model. The processing of data by SAEs can be regarded as the processing of a single autoencoder and then passed to the next autoencoder for processing. The processing of a single autoencoder can be achieved by the following formula: ; ; in, , is the weight, , is the bias, Represents input data, represents the hidden layer output, represents the reconstructed input; is one activation function, and sigmoid is another activation function.

[0093] By processing the above feature data, we obtain the convolution output of the convolution layer at the current stage.

[0094] The convolution output of the convolutional layer is input to the dynamic time module, which is implemented through the following process: The convolution output of the convolution layer is used as the input feature of the dynamic time module and input into the temporal convolution module. The input features are subjected to causal convolution and dilated convolution, which is achieved by the following formula: ; ; in, represents the sequence of input features, i.e. , Represents a filter set, represents the convolution operation, Indicates convolution kernels, represents the convolution kernel size, Indicates the sequence element number, Represents the expansion factor.

[0095] Add a branch at the output of each temporal convolution module to predict Stop score in range ,when When the cumulative sum reaches 1, all remaining temporal convolution modules will be skipped. In order to ensure that the sum of all stop scores is 1, the last branch before skipping is replaced by the remainder, which is equal to 1 minus the previous cumulative sum; Then, the output of the temporal convolution module is redefined as the weighted sum of the outputs of the previous temporal convolution modules, where the weight of each temporal convolution module is given by a stopping probability value; enter , output , the specific process is realized by the following formula: ; ; ; ; ; in, Indicates The input data of the temporal convolution module is is an activation function, is the original dilation transformation, represents a logical function, Indicates The stopping fraction of the temporal convolutional modules, Indicates The weight parameters of the temporal convolution module, Indicates The bias of the temporal convolution module, represents the input data of the m-1th temporal convolution module, M represents the number of temporal convolution modules, represents the sigmoid function, Represents global average pooling Among them, the stopping score of each temporal convolution module is Depend on Function Compute, stopping fraction of the last temporal convolution module Set to 1 to force it to stop after this sequential convolutional module; ; ; Where N is the number of temporal convolution modules calculated, is a very small constant, ensuring can be equal to 1, which means that the computation can stop after a single temporal convolution module, represents the remainder, n is the nth temporal convolution module; ; ; in, represents the stopping probability of each temporal convolution module, represents the output features of the dynamic time module, is the sum of the outputs of the temporal convolutional modules, weighted by the stopping probability.

[0096] Then the new output features are obtained Through the channel attention mechanism in the convolutional attention module, the input feature vector is a three-dimensional matrix (H×W×C). , respectively, through global maximum pooling and global average pooling; Subsequently, the feature map is compressed in two dimensions to obtain feature descriptions of two different dimensions (1×1×C). The final merged feature map shares an MLP network with the number of neurons in the first layer being , is the reduction rate, and the activation function is , the number of neurons in the second layer is ; These two feature maps are then superimposed on the channel dimension by The activation function is multiplied by the initial input to obtain the final channel attention feature map (H×W×C). ,The specific feature processing process can be achieved through the following formula: ; ; ; in, is the initial input feature map, and Represent the global average pooling feature and the global maximum pooling feature respectively, and are the two weights of the MLP network layer, It is the output feature map of the final channel attention module.

[0097] The obtained channel attention module output feature map Input into the spatial attention mechanism, the first step is to Global average pooling and global maximum pooling are performed respectively. This process produces two feature maps (H×W×1). and ; Then the channel connection is performed to connect them to generate a valid feature descriptor (each represents the global average pooling and global maximum pooling features of the entire channel). On the connected feature descriptors, convolution is used to generate a 2D spatial attention map Finally, by Activation function and current stage input feature map Multiply them together to get the final spatial attention feature map (H×W×C), ,The specific feature processing process can be achieved through the following formula: ; ; ; in, is the initial input feature map, and Represent the global average pooling feature and the global maximum pooling feature respectively, It is a 3×3 convolutional layer. is the final output feature map; The final output feature map It is input into the decoder as the input feature of the decoder to obtain the final traffic flow prediction result.

[0098] Figure 4 FIG. 1 is a structural block diagram of a flow prediction model training device shown in an exemplary embodiment of the present application. Figure 4 As shown, the exemplary traffic prediction model training device 400 includes: The sample acquisition module 410 is used to acquire historical traffic flow data and divide the historical traffic flow data into different time scales at different positions on the time axis to obtain historical traffic flow data to be processed.

[0099] The first processing module 420 is used to perform normalization processing on the historical flow data to be processed to obtain intermediate historical flow data.

[0100] The second processing module 430 is used to divide the intermediate flow history data based on the time-lag variable to obtain an initial data set, which includes multiple flow history data samples.

[0101] The third processing module 440 is used to shuffle multiple traffic history data samples in the initial data set to obtain a target data set.

[0102] The first training module 450 is used to train an initial basic model based on a target data set to obtain a target basic model.

[0103] The model building module 460 is used to insert a convolution layer, a dynamic time module and a convolution attention module in sequence after the feature extraction layer of the target basic model to obtain an initial prediction model; the dynamic time module is used to dynamically process the convolution output of the convolution layer to obtain output features, the convolution attention module includes a channel attention mechanism and a spatial attention mechanism, and the convolution attention module is used to extract features from the output features.

[0104] The second training module 470 is used to train the initial prediction model based on the target data set to obtain a target prediction model, and the output of the target prediction model is the traffic flow prediction result.

[0105] It should be noted that the traffic prediction model training device provided in the above embodiment and the traffic prediction model training method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here. In practical applications, the traffic prediction model training device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.

[0106] Figure 5 FIG. 1 is a structural block diagram of a traffic flow prediction device shown in an exemplary embodiment of the present application. Figure 5 As shown, the exemplary traffic flow prediction device 500 includes: The data acquisition module 510 is used to acquire traffic flow data to be predicted.

[0107] The calling module 520 is used to call the pre-trained target prediction model.

[0108] The prediction module 530 is used to obtain traffic flow prediction results based on the traffic flow data to be predicted and the target prediction model.

[0109] Among them, the target prediction model is trained using the traffic prediction model training method provided in any of the above embodiments of the present application.

[0110] It should be noted that the traffic flow prediction device provided in the above embodiment and the traffic flow prediction method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs operations has been described in detail in the method embodiment, and will not be repeated here. In practical applications, the traffic flow prediction device provided in the above embodiment can allocate the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.

[0111] In the embodiments of the present application, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. "Including" and "comprising" mentioned throughout the specification and claims are open-ended terms and should be interpreted as "including but not limited to".

[0112] The above embodiments are merely illustrative of the principles and effects of the present application, and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.

Claims

1. A traffic prediction model training method, characterized in that: include: Acquire historical traffic flow data, and divide the historical traffic flow data into different time scales at different positions on the time axis to obtain historical traffic flow data to be processed; Normalizing the historical flow data to be processed to obtain intermediate historical flow data; Dividing the intermediate flow historical data based on the time-lag variable to obtain an initial data set, wherein the initial data set includes a plurality of flow historical data samples; Shuffling multiple traffic history data samples in the initial data set to obtain a target data set; Training an initial basic model based on the target data set to obtain a target basic model; A convolution layer, a dynamic time module and a convolution attention module are sequentially inserted after the feature extraction layer of the target basic model to obtain an initial prediction model; the dynamic time module is used to dynamically process the convolution output of the convolution layer to obtain output features, the convolution attention module includes a channel attention mechanism and a spatial attention mechanism, and the convolution attention module is used to extract features from the output features; The initial prediction model is trained based on the target data set to obtain a target prediction model, and the output of the target prediction model is a traffic flow prediction result.

2. The traffic prediction model training method according to claim 1, characterized in that: The dynamic time module includes a plurality of sequentially connected temporal convolution modules and a stop score prediction module connected to the output of each temporal convolution module; Among them, the temporal convolution module is used to perform causal convolution and dilated convolution on the input data, the input data of the temporal convolution module connected to the convolution layer is the convolution output of the convolution layer, the output data of the previous temporal convolution module is the input data of the current temporal convolution module, and the stop score prediction module is used to predict the stop score of the corresponding temporal convolution module, and when the cumulative stop score reaches a preset value, skip the remaining temporal convolution modules to obtain the output feature.

3. The traffic prediction model training method according to claim 2, characterized in that: Training an initial prediction model based on the target data set to obtain a target prediction model includes: Loading the training weights of the target basic model into the initial prediction model; Inputting the traffic history data sample into the initial prediction model to obtain the convolution output of the convolution layer in the initial prediction model; Inputting the convolution output of the convolution layer into a dynamic time module to obtain output features of the dynamic time module; Extracting features from the output features based on a channel attention mechanism to obtain channel attention features; Extracting the channel attention feature based on the spatial attention mechanism to obtain the spatial attention feature; The spatial attention features are decoded to obtain a traffic flow prediction result.

4. The traffic prediction model training method according to claim 3 is characterized in that: The convolution output of the convolution layer is input into the dynamic time module, and the output features of the dynamic time module include: (Formula 1) (Formula 2) (Formula 3) (Formula 4) in, Indicates The input data of the temporal convolution module is is an activation function, is the original dilation transformation, represents a logical function, Indicates The stopping fraction of the temporal convolutional modules, Indicates The weight parameters of the temporal convolution module, Indicates The bias of the temporal convolution module; (Formula 5) (Formula 6) Where N is the number of temporal convolution modules calculated, is a constant, Indicates remainder; (Formula 7) (Formula 8) in, represents the stopping probability of each temporal convolution module, Represents the output features of the dynamic time module.

5. The traffic prediction model training method according to claim 1, characterized in that: The initial base model is a gated recurrent unit, a long short-term memory network, or a stacked autoencoder.

6. A traffic flow prediction method, characterized in that: include: Obtain traffic flow data to be predicted; Call the pre-trained target prediction model; Based on the traffic flow data to be predicted and the target prediction model, a traffic flow prediction result is obtained; Wherein, the target prediction model is trained using the traffic prediction model training method described in any one of claims 1-4.

7. A flow prediction model training device, characterized in that: include: A sample acquisition module is used to acquire historical traffic flow data and divide the historical traffic flow data into different time scales at different positions on the time axis to obtain historical traffic flow data to be processed; A first processing module, configured to perform normalization processing on the historical flow data to be processed to obtain intermediate historical flow data; A second processing module is used to divide the intermediate flow history data based on the time lag variable to obtain an initial data set, wherein the initial data set includes a plurality of flow history data samples; A third processing module, configured to shuffle a plurality of traffic history data samples in the initial data set to obtain a target data set; A first training module is used to train an initial basic model based on the target data set to obtain a target basic model; A model building module, used to insert a convolution layer, a dynamic time module and a convolution attention module in sequence after the feature extraction layer of the target basic model to obtain an initial prediction model; the dynamic time module is used to dynamically process the convolution output of the convolution layer to obtain output features, the convolution attention module includes a channel attention mechanism and a spatial attention mechanism, and the convolution attention module is used to extract features from the output features; The second training module is used to train the initial prediction model based on the target data set to obtain a target prediction model, and the output of the target prediction model is a traffic flow prediction result.

8. A traffic flow prediction device, characterized in that: include: A data acquisition module, used to acquire traffic flow data to be predicted; A calling module is used to call a pre-trained target prediction model; A prediction module, used to obtain a traffic flow prediction result based on the traffic flow data to be predicted and the target prediction model; Wherein, the target prediction model is trained using the traffic prediction model training method described in any one of claims 1-4.

Citation Information

Cited By

  • Urban traffic flow space-time distribution prediction method based on multistage road operation information

    CN120088990A