Traffic flow prediction method and system based on spatio-temporal contrast learning model
By constructing a traffic flow prediction method based on a spatiotemporal contrastive learning model, the problem of complex spatiotemporal changes in traffic data is solved, higher accuracy traffic flow prediction is achieved, and the perception and prediction capabilities of intelligent transportation systems are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING UNIV OF CIVIL ENG & ARCHITECTURE
- Filing Date
- 2026-04-20
- Publication Date
- 2026-07-10
AI Technical Summary
Existing traffic flow prediction models struggle to effectively handle the complex spatiotemporal variations of road traffic data, resulting in insufficient perception and prediction capabilities of intelligent transportation systems.
A traffic flow prediction method based on a spatiotemporal contrastive learning model is adopted. By constructing a dual-flow enhancement and feature extraction backbone network, including a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module, the method combines temporal and spatial enhancement techniques to optimize feature representation capabilities and uses contrastive learning algorithms to improve prediction accuracy.
It significantly improves the accuracy and robustness of traffic flow prediction, better captures the spatiotemporal correlation characteristics in traffic data, and enhances the perception and prediction capabilities of intelligent transportation systems.
Smart Images

Figure CN122364767A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of transportation information engineering technology, and in particular to a traffic flow prediction method and system based on a spatiotemporal comparative learning model. Background Technology
[0002] With the gradual maturation of big data and artificial intelligence technologies, the organic integration of sensor technology, artificial intelligence, and other cutting-edge technologies with urban traffic needs has become a widespread social demand. This involves constructing intelligent transportation systems (ITS) to meet the massive demands of daily urban travel and logistics transportation, while simultaneously reducing traffic accident rates and improving urban traffic efficiency and safety. As ITS systems continue to improve and develop, a large amount of spatiotemporal road traffic data is being continuously observed, sampled, and accumulated. However, this data exhibits characteristics such as spatiotemporal nonlinear variations, modal differences, and semantic gaps, posing significant challenges to the construction of key ITS components, such as data-driven road traffic prediction models. Summary of the Invention
[0003] This invention provides a traffic flow prediction method and system based on a spatiotemporal contrastive learning model to address the complex spatiotemporal variations of road traffic data. The solution in this application breaks through the performance bottleneck of existing prediction models by applying a novel contrastive learning algorithm theory, thereby improving the perception, prediction, and understanding capabilities of intelligent transportation systems.
[0004] This invention provides a traffic flow prediction method based on a spatiotemporal contrastive learning model, comprising: The data preparation and preprocessing steps include: acquiring traffic flow and / or speed data collected by traffic sensors, slicing the data at fixed time intervals to form a traffic data sequence; modeling the road network structure, defining the sensor locations as graph nodes, and constructing an initial adjacency matrix of the road network based on the distances between nodes; dividing the traffic data sequence into training, validation, and test sets in chronological order, and normalizing the data to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; A traffic flow prediction model based on spatiotemporal contrastive learning is constructed. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation. The traffic data to be predicted is input into the model for training, and the model is updated and the parameters are optimized. The predicted traffic flow value is output and compared with the true value to calculate the error.
[0005] According to the traffic flow prediction method based on a spatiotemporal contrastive learning model provided by the present invention, the data preparation and preprocessing steps further include: The TDA model is used for time augmentation, with traffic data sequences as input. Then, an average pooling layer with padding is used to quickly obtain samples and effective predictions of the input sequence data, as shown in the following formula (1): (1) in, It is time-pooled data, and To augment contrastive learning with randomized data, random variables are sampled from a uniform distribution. The size is the same as the input data, that is , It is a control factor, determined by element-wise multiplication. and The effect is shown in the following formula (2): (2) in, It is random average data.
[0006] According to the traffic flow prediction method based on a spatiotemporal contrastive learning model provided by the present invention, the data preparation and preprocessing steps further include: With probability (The range of values is) Discarding data is defined by the following formula (3): (3) For the input traffic data The output of TDA is defined as follows (4): (4) in, It is a time enhancement module. It is augmented data; After time augmentation of the data, spatial augmentation is performed using an optimization graph to obtain different feature representations of the same input data. The optimization graph augmentation part is divided into an optimization additive graph. and optimized dot product map For example, in formula (5): (5) in, This indicates element-wise multiplication. yes The degree matrix, yes The degree matrix, It uses shared optimization graph learning parameters, which can encode data correlations and preserve... and Consistency between them.
[0007] According to the traffic flow prediction method based on a spatiotemporal contrastive learning model provided by the present invention, the spatiotemporal graph convolutional network module consists of... The system consists of spatiotemporal blocks, each of which includes a temporal convolutional layer, a graph convolutional layer, and a gated linear activation layer. Temporal convolutional layers are used to learn the input traffic data. The local time characteristics are calculated as shown in Formula 6: (6) in, This represents a two-dimensional convolution operator with a kernel size of . , It is a local temporal feature. It is a feature The number of channels; Graph convolutional layers are used for learning. The spatial characteristics are calculated as shown in Formula 7: (7) in, These are learnable parameters. It is the order of the Chebyshev polynomial. It is the scaled Laplace matrix. It is the first Chebyshev polynomial of order 1 It is a local spatiotemporal feature. It is a feature The number of channels; Gated linear activation layers are used to control the information flow and maintain the importance of spatiotemporal information when it is passed to the next spatiotemporal block, calculated as shown in Equation 8: (8); in, The operator represents the division operator. , It controls the activation function. It is the output of time characteristics. Used for control The information is passed to the next level; Spatiotemporal graph convolutional networks encode spatiotemporal features The operation summary of the output features of the spacetime block is shown in Formula 9: (9).
[0008] According to the traffic flow prediction method based on a spatiotemporal contrastive learning model provided by the present invention, the contrastive learning module is further used for: Different spatiotemporal features are input into the same linear mapping layer, which includes two fully connected networks. The calculation process is as follows: (10) (10) in, , It is the first Features of each sample; , It is the first Features of each sample; It's the dropout ratio, adding random variations to enhance the optimization graph. These are the learning parameters of the Projection_Head network; A negative sample selection model is designed to calculate the feature similarity between anchor point samples and the remaining samples of input traffic data, and to exclude samples with the highest feature similarity to anchor point samples during the negative sample selection process. The sample conforms to the following formula (11): (11) in, Transposed data, It is the maximum index algorithm. It is the cosine similarity function. It is the first in each anchor point sample The sorting number of the maximum feature similarity, and according to These features are excluded from the negative samples of the anchor samples; No. Individual sample features yes Positive samples, features Convert to and will Convert to Thus, the loss function for the spatiotemporal features is input, which conforms to the following formula (12): (12) in, and It is the cosine similarity function. It is a parameter that controls the proportion of negative samples in the input data, and is usually set to 0.1 in contrastive learning; For the input traffic data Two random augmented data sets are generated using the time data augmentation model, as shown in the following formula (13): (13) in, These are two sets of randomly augmented data. and They share the same structure as TDA, but are independent of each other and acquire different random augmentation data. These two random augmentation data... and The feature is incorporated into a multi-graph convolutional network to obtain enhanced features, conforming to the following formula (14):
[0009] (14) in, These are the spatiotemporal characteristics of each layer; Using the spatiotemporal features of the last layer As input for contrastive learning, these two features are fed into the projection head to obtain output features in the same feature space, conforming to the following formula (15):
[0010]
[0011]
[0012] (15) in, and These are the parameters of the fully connected layer. and It is a bias parameter. , It is the output of the projection head; Using different augmented data of the same input traffic data as positive samples and different augmented data of different input traffic data as negative samples, the infoNCE loss function is calculated according to the following formula (16): (16) in, .
[0013] According to the traffic flow prediction method based on a spatiotemporal contrastive learning model provided by the present invention, the prediction head network uses skip connections and two fully connected layers to map the pre-trained model. Spatiotemporal characteristics of all layers It conforms to the following formula (17):
[0014]
[0015]
[0016] (17) in, It is a jumping feature. These are the parameters of the skip connection layer. , These are the parameters of two fully connected layers. It is a prediction result. It is a truth value; Using the mean absolute error as the loss function, it conforms to the following formula (18): (18).
[0017] According to the traffic flow prediction method based on a spatiotemporal contrastive learning model provided by the present invention, the method further includes, after jointly training the prediction loss model in conjunction with the traffic prediction module, the following steps: The mean absolute error (MAE), mean absolute percentage error (MAPE), and root mean square error (RMSE) were used as evaluation metrics to assess the performance of the trained model.
[0018] This invention also provides a traffic flow prediction system based on a spatiotemporal contrastive learning model, which applies a traffic flow prediction method based on a spatiotemporal contrastive learning model, including: The data preparation and preprocessing module is used to acquire traffic flow and / or speed data collected by traffic sensors, slice the data at fixed time intervals to form a traffic data sequence; model the road network structure, define the sensor locations as graph nodes, and construct an initial adjacency matrix of the road network based on the distances between nodes; divide the traffic data sequence into training, validation, and test sets in chronological order, and normalize the data to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; The model building module is used to build a traffic flow prediction model based on spatiotemporal contrastive learning. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation. The traffic flow prediction module is used to input the traffic data to be predicted into the model for training, update the model and optimize the parameters, output the traffic flow prediction value, and compare the data with the true value to calculate the error.
[0019] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements any of the traffic flow prediction methods based on the spatiotemporal contrastive learning model described above.
[0020] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the traffic flow prediction methods based on the spatiotemporal contrastive learning model described above.
[0021] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements any of the traffic flow prediction methods based on a spatiotemporal contrastive learning model described above.
[0022] The traffic flow prediction method based on a spatiotemporal contrastive learning model provided by this invention has at least the following beneficial effects: From the perspective of spatial attributes of data, this paper comprehensively considers global and local graph representation methods and regards them as spatial attribute enhancement algorithms. Based on this, a novel contrastive-optimized graph convolutional network traffic prediction model is constructed by jointly using global and local graph convolutional networks and cleverly incorporating a contrastive learning framework. This model can more accurately capture the spatial correlation characteristics in traffic data. Experimental results show that compared with prediction models using only a single graph representation, the contrastive-optimized graph convolutional network traffic prediction model significantly improves prediction accuracy on four public traffic flow and speed datasets.
[0023] From the perspective of the temporal attributes of data and based on the importance of temporal patterns for traffic prediction, a contrastive learning pre-trained traffic prediction model based on multi-graph convolutional networks is constructed. First, a multi-graph convolutional network is introduced, connecting several different graph convolutional networks with temporal convolution to obtain more accurate spatiotemporal features. Second, a temporal data augmentation model is designed to perform special data augmentation on sequence samples to expand the distribution of training samples. Finally, a contrastive learning pre-training framework is constructed to enhance the model's output samples and pre-train the multi-graph convolutional network prediction model to obtain more expressive pre-trained spatiotemporal features, thereby improving the performance of traffic flow prediction tasks. Experimental results show that the contrastive learning pre-training framework can significantly improve the accuracy of the original prediction model, verifying its effectiveness in mining complex temporal patterns in data. Attached Figure Description
[0024] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0025] Figure 1 This is a flowchart illustrating the traffic flow prediction method based on a spatiotemporal contrastive learning model provided in an embodiment of the present invention. Figure 2 This is a schematic diagram of the traffic flow prediction model provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the temporal data enhancement framework provided in an embodiment of the present invention; Figure 4 This is a logical diagram of global and local features provided in the embodiments of the present invention; Figure 5 This is a schematic diagram of the spatial contrast learning module provided in an embodiment of the present invention; Figure 6 This is a schematic diagram of the traffic flow prediction system based on a spatiotemporal contrastive learning model provided in an embodiment of the present invention; Figure 7 This is a schematic diagram of the physical structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0027] Figure 1 This is a flowchart illustrating the traffic flow prediction method based on a spatiotemporal contrastive learning model provided in an embodiment of the present invention.
[0028] like Figure 1 As shown, this embodiment provides a traffic flow prediction method based on a spatiotemporal contrastive learning model, including: Step 101, Data Preparation and Preprocessing: Acquire traffic flow and / or speed data collected by traffic sensors, slice the data at fixed time intervals to form a traffic data sequence; model the road network structure, define the sensor locations as graph nodes, and construct an initial adjacency matrix of the road network based on the distances between nodes; divide the traffic data sequence into training, validation, and test sets in chronological order, and normalize the data to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; Step 102: Construct a traffic flow prediction model based on spatiotemporal contrastive learning. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation. Step 103: Input the traffic data to be predicted into the model for training, update the model and optimize the parameters, output the traffic flow prediction value, and compare the data with the true value to calculate the error.
[0029] In one specific embodiment, the method flow may include: The dataset is read, and traffic sequences are input. Temporal data augmentation is performed using the TDA model to imbue the data with its own temporal relationships and regularities. After temporal convolution, the original data with temporal features is divided into two parts, T1 and T2. Spatial features are then assigned to these parts respectively, through addition and dot product operations, to give the data spatial characteristics.
[0030] Traffic data with spatiotemporal characteristics is input into a spatiotemporal graph convolutional network, which is composed of... The model is composed of spatiotemporal blocks, each consisting of a temporal convolutional layer, a graph convolutional layer, and a gated linear activation layer. Four sets of enhanced features are output through the graph convolutional network, and then the spatiotemporal convolutional network is pre-trained using a contrastive learning algorithm. Based on the different enhanced spatiotemporal features within the same group, these features are input into a linear mapping layer. A loss function is constructed according to the rule of minimizing the feature distance of positive nodes and maximizing the feature distance of negative nodes. The results obtained from the contrastive learning are used to update the model parameters, optimize model performance, and obtain the temporal contrastive pre-trained model.
[0031] The pre-trained model is mapped using skip connections and two fully connected layers. Spatiotemporal characteristics of all layers After the model training is completed, the second part of the program is run to test the model's performance, using the mean absolute error (MAE) as the loss function.
[0032] Figure 2 This is a schematic diagram of the traffic flow prediction model provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the temporal data enhancement framework provided in an embodiment of the present invention; Figure 4 This is a logical diagram of global and local features provided in the embodiments of the present invention; Figure 5 This is a schematic diagram of the spatial contrast learning module provided in an embodiment of the present invention; like Figures 2 to 5 As shown, the traffic flow prediction method based on a spatiotemporal contrastive learning model provided in this application may specifically include: In the data preprocessing step, a spatiotemporal traffic data sequence is constructed. A time augmentation model (TDA) is used to augment the data, with the traffic sequence data as input. Then, an average pooling layer with padding is used to quickly obtain samples and effective predictions of the input sequence data, as shown in the following formula (1): (1) in, It is time-pooled data. To provide randomized augmentation data for contrastive learning, this application samples random variables from a uniform distribution. Its size is the same as the input data, that is . It is a control factor, determined by element-wise multiplication. and The effect is shown below: (2) in, It is random average data.
[0033] Furthermore, real-world traffic data is often incomplete when collecting and retrieving data from road networks; therefore, this application proposes a Mask layer for probabilistic... (The range of values is) The process of discarding some data is defined as follows: (3) In summary, regarding the input traffic data The output of TDA is defined as follows: (4) in, It is a time enhancement module. It's about enhancing data.
[0034] After time augmentation of the data, spatial augmentation is performed using an optimization graph to obtain different feature representations of the same input data. The optimization graph augmentation part is specifically divided into optimization additive graph. and optimized dot product map Formula 5 is as follows: (5) in, This indicates element-wise multiplication. yes The degree matrix, yes The degree matrix, It uses shared optimization graph learning parameters, which can encode data correlations and preserve... and Consistency between them.
[0035] It is calculated by multiplying the learnable parameter h element-by-element with the adjacency matrix A, and It is by... Add to Obtained from above. and The main difference lies in the position and presence of non-zero weights: It is created from a complete graph, allowing exploration of the spatial properties between all pairs of nodes through all edges; and It is generated from an incomplete graph, capturing the spatial characteristics between adjacent nodes only through specific edges. and The differences between them lead to significant spatial semantic differences.
[0036] In summary, by using TDA temporal data augmentation and optimized graph spatial data augmentation, the data is made to contain spatiotemporal characteristics and incorporated into the spatiotemporal graph convolutional network to extract spatiotemporal features.
[0037] The spatiotemporal graph convolutional module of the traffic flow prediction method based on spatiotemporal contrastive learning is based on a spatiotemporal graph convolutional network. The spatiotemporal graph convolutional network consists of... The system consists of spatiotemporal (ST) blocks, each of which comprises three components: a temporal convolutional layer, a graph convolutional layer, and a gated linear activation layer.
[0038] Temporal convolutional layers are used to learn the input traffic data. The local time characteristics are calculated as shown in formula (6): (6) in, This represents a two-dimensional convolution operator with a kernel size of . , It is a local temporal feature. It is a feature The number of channels. Then, a graph convolutional layer is used to learn. The spatial characteristics are calculated as shown in Formula 7: (7) in, These are learnable parameters. It is the order of the Chebyshev polynomial. It is the scaled Laplace matrix. It is the first Chebyshev polynomial of order 1 It is a local spatiotemporal feature. It is a feature The number of channels. Finally, in order to control the information flow and maintain the importance of spatiotemporal information when it is passed to the next ST block, this application adopts gated linear activation (GLA), which is calculated as shown in Equation 8: (8) in, The operator represents the division operator. , It is the control activation function. Based on the theory of the Gated Linear Unit (GLU) model, this application... and Learn local temporal characteristics. It is the output of time characteristics, while It is a gating mechanism similar to LSTM, used for control. The information is passed to the next layer. Based on this, the spatiotemporal graph convolutional network encodes spatiotemporal features. The operations on the output features of the ST block can be summarized as shown in Formula 9: (9) A contrastive learning module for traffic flow prediction based on spatiotemporal contrastive learning, using OAG. and ODPG The S-TGCN obtains two distinct spatiotemporal features and inputs them into the same linear mapping layer (Projection_Head network), which consists of two fully connected networks. The computation process can be represented as follows: (10) in, , It is the first Features of each sample; , It is the first Features of each sample; It represents the dropout ratio, which can add random variations to the enhanced optimization graph. These are the learning parameters of the Projection_Head network.
[0039] Then, two features are constructed in the feature representation space. and In contrastive learning algorithms, two features of the same sample in a batch are defined as positive sample pairs, and different samples are defined as negative sample pairs. The algorithm minimizes the feature distance between positive nodes and maximizes the feature distance between negative nodes. However, in the field of traffic prediction, periodicity and similarity of traffic sequence data have a certain impact on prediction performance. Based on this phenomenon, and considering the negative samples in the input feature batch, this application designs a negative sample selection model, unlike the original contrastive learning algorithm. This model calculates the feature similarity between the anchor sample and the remaining samples of the input traffic data, and excludes the samples with the highest feature similarity to the anchor sample during the negative sample selection process. One sample. The entire process is defined as follows: (11) in, Transposed data, It is the cosine similarity function. It is the maximum index algorithm. It is the first in each anchor point sample The sorting number of the maximum feature similarity, and according to These features are excluded from the negative samples of the anchor sample.
[0040] According to the above definition, the first Individual sample features yes Positive samples, except in Apart from these samples, the remaining samples are negative samples. To calculate the InfoNCE loss of the samples, this application needs to incorporate the features... Convert to and will Convert to Thus, the InfoNCEloss of the input spatiotemporal features is represented as follows: (12) in, and It is the cosine similarity function. It is a parameter that controls the proportion of negative samples in the input data, and is usually set to 0.1 in contrastive learning. The contrastive learning algorithm in CLMGCN is logically identical to that in the COGCN model. Based on the above theory, the contrastive learning algorithm of CLMGCN is modified to have four sets of contrastive learning features.
[0041] For the input traffic data Two random augmented data sets are generated using time-based data augmentation models, as shown below: (13) in, These are two sets of randomly augmented data. and They share the same structure as TDA, but are independent of each other and acquire different random augmentation data. Then, CLMGCN combines these two random augmentation data... and We incorporate these features into a multi-graph convolutional network to obtain enhanced features, defined as follows:
[0042] (14) in, These are the spatiotemporal characteristics of each layer.
[0043] Next, the spatiotemporal features of the last layer are used as input for contrastive learning, i.e. Then CLMGCN inputs these two features into the projection head to obtain output features in the same feature space, defined as follows:
[0044]
[0045]
[0046] (15) in, and These are the parameters of the fully connected layer. and It is a bias parameter. , This is the output of the projector head.
[0047] Finally, using different augmented data with the same input traffic data as positive samples and different augmented data with different input traffic data as negative samples, the infoNCE loss function is calculated. Borrowing from the contrastive learning algorithm of the CLMGCN model, its decoupled infoNCE loss (d-infoNCE loss) is adopted. The d-infoNCE loss simplifies the original infoNCE loss and achieves better performance with small batch sizes, defined as follows: (16) in, In summary, STCLGCN uses d-infoNCE loss to train the parameters of a multi-graph convolutional network and obtains a time-comparative pre-trained model. .
[0048] This document describes a traffic prediction module based on a spatiotemporal contrastive learning-based traffic flow prediction method. The output block is combined with a prediction network that uses skip connections and two fully connected layers to map the pre-trained model. Spatiotemporal characteristics of all layers The definition is as follows:
[0049]
[0050]
[0051] (17) in, It is a jumping feature. These are the parameters of the skip connection layer. , These are the parameters of two fully connected layers. It is a prediction result. It is a truth value.
[0052] Finally, STCLGCN uses the mean absolute error (MAE) as the loss function, defined as follows: (18) The following specific embodiment illustrates the traffic flow prediction method based on spatiotemporal contrastive learning provided by this application.
[0053] (1) Work environment The model code was written using the PyTorch framework. All experimental code was compiled and executed on a Windows software environment, and experiments were conducted using PyTorch v2.2.2 on the Featureize virtual workbench. The configured GPU was an Nvidia RTX3080, and the CPU was a 6-core Xeon Gold 6142.
[0054] (2) Introduction to the experimental dataset The PEMS03, PEMS04, PEMS07 and PEMS08 public traffic flow datasets of four regions of a certain highway were used. The average traffic flow of the road segment was sampled at a sampling rate of one sample every 5 minutes. Then, the input data was processed by Z-score normalization, and the initial adjacency matrix of the road network was constructed by Gaussian kernels based on the distance between different road segments and the threshold.
[0055] (3) Selection of benchmark model In the comparative experiment, two benchmark models were selected and their performance was compared with the proposed model on a given dataset.
[0056] COGCN (Contrastive Optimized Graph Convolutional Network): Building upon the traditional GCN model, it fully mines the global road network graph (optimizing the additive graph). ) and local road network map (optimized dot-matrix map) The collaborative relationship between them is established. Through a parameter-sharing dual-branch structure, both OAG and ODPG optimized road network maps are processed synchronously.
[0057] CLMGCN (Contrastive Learning based on Multi Graph Convolution Network): This model uses a contrastive learning algorithm to expand the distribution of sequence samples on top of the traditional GCN model, thereby improving the quality and generalization ability of the prediction model.
[0058] (4) Experimental parameter settings The batch size is set to 64 (Batch_size=64), the initial learning rate is 0.001, and the Adam optimizer is used. The length of the input traffic sequence data is equal to the length of the output data, i.e. The input data is traffic status (flow rate or speed), i.e. The number of channels for time or spatiotemporal features is 32, that is... Training was performed for 100 epochs on four different datasets. The hyperparameters of the model were then analyzed. , , , and The optimal hyperparameter combination obtained from the verification experiment was used.
[0059] (5) Selection of evaluation indicators The predictive performance of each model is evaluated using three common metrics: Mean Absolute Error (MAE), Root Mean Square Error (RMSE), and Mean Absolute Percentage Error (MAPE). Smaller metrics generally indicate better performance.
[0060] (6) Experimental results and analysis Table 1 compares the three models under different datasets and the same metric. The 12-step length is divided into four groups, with the first data point from each group entered into the table. The table header also includes the specific dataset and evaluation metric. The data comparison shows that the STCLGCN model significantly outperforms the other two models. The largest performance improvement is observed on the PEMS08 dataset, with a 4.4% improvement on MAE. Performance is lower on the PEMS07 dataset. The core advantage of the STCLGCN model in comprehensively surpassing COGCN and CLMGCN in traffic prediction tasks stems from its innovative spatiotemporal contrastive collaborative architecture and decoupled feature learning mechanism. Compared to the limitations of COGCN, which focuses solely on spatial dimension dual-graph fusion, and CLMGCN's separate processing of temporal enhancement and spatial modeling, STCLGCN achieves a fundamental breakthrough through four groups of joint contrastive learning. At the spatial modeling level, the model simultaneously constructs a globally optimized additive graph and a locally optimized dot product graph. It uses the parameter-shared GCN branch to extract macroscopic road network connectivity and microscopic neighborhood interaction features respectively, and forces the two to align in the latent space by comparing the loss function, which effectively solves the problem of missing long-range dependencies caused by the single graph structure of COGCN.
[0061] Table 1. Experimental comparison results of the model on four datasets.
[0062] Table 2 reflects the average training time, validation loss, number of epochs for optimal model training, and total training time across the four datasets. It can be seen that the larger the dataset, the worse the performance. Combined with the experimental results in Table 1, the model still has certain issues with large datasets, resulting in poor performance improvement.
[0063] Table 2 Other evaluation metrics of STCLGCN across four datasets
[0064] Based on the above examples, the spatiotemporal contrastive learning-based traffic flow prediction method provided in this application can be summarized to have at least the following beneficial effects: 1) By integrating the dual-branch spatial contrastive learning mechanism of global optimization graph (OAG) and local optimization graph (ODPG), and combining multi-graph convolutional network (MGCN) and temporal data augmentation (TDA) technology, a spatiotemporal contrastive collaborative optimization framework (STCLGCN) was constructed, which significantly enhanced the ability to model complex spatiotemporal dependencies in traffic data and improved the accuracy and robustness of short-term traffic state prediction. 2) This method can provide effective theoretical support and technical solutions for the accurate perception, dynamic control and efficient decision-making of intelligent transportation systems (ITS), which can help alleviate the contradiction between urban traffic supply and demand, optimize road network resource scheduling, improve overall traffic efficiency and safety, and provide more refined and adaptive prediction tools for smart travel scenarios such as vehicle-road cooperation and low-carbon transportation, thus promoting the continuous progress of intelligent traffic management.
[0065] The traffic flow prediction system based on the spatiotemporal contrastive learning model provided by this invention is described below. The traffic flow prediction system based on the spatiotemporal contrastive learning model described below can be referred to in correspondence with the traffic flow prediction method based on the spatiotemporal contrastive learning model described above.
[0066] Figure 6 This is a schematic diagram of the traffic flow prediction system based on a spatiotemporal contrastive learning model provided in an embodiment of the present invention.
[0067] like Figure 6 As shown, the traffic flow prediction system based on a spatiotemporal contrastive learning model provided in this embodiment includes: The data preparation and preprocessing module 601 is used to acquire traffic flow and / or speed data collected by traffic sensors, slice the data at fixed time intervals to form a traffic data sequence; model the road network structure, define the sensor locations as graph nodes, and construct an initial adjacency matrix of the road network based on the distances between nodes; divide the traffic data sequence into training, validation, and test sets in chronological order, and normalize the data to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; The model building module 602 is used to build a traffic flow prediction model based on spatiotemporal contrastive learning. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation. The traffic flow prediction module 603 is used to input the traffic data to be predicted into the model for training, update the model and optimize the parameters, output the traffic flow prediction value, and compare the data with the true value to calculate the error.
[0068] The specific implementation method of the traffic flow prediction system based on the spatiotemporal contrastive learning model provided in this embodiment can be implemented with reference to the above embodiment, and will not be repeated here.
[0069] Figure 7 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730, and a communication bus 740, wherein the processor 710, the communication interface 720, and the memory 730 communicate with each other via the communication bus 740. The processor 710 can call logical instructions in the memory 730 to execute a traffic flow prediction method based on a spatiotemporal contrastive learning model, the method including: The data preparation and preprocessing steps include: acquiring traffic flow and / or speed data collected by traffic sensors, slicing the data at fixed time intervals to form a traffic data sequence; modeling the road network structure, defining the sensor locations as graph nodes, and constructing an initial adjacency matrix of the road network based on the distances between nodes; dividing the traffic data sequence into training, validation, and test sets in chronological order, and normalizing the data to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; A traffic flow prediction model based on spatiotemporal contrastive learning is constructed. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation, and the model is jointly trained by combining the prediction loss from the pre-trained model stage of the traffic flow prediction module. The traffic flow prediction module is divided into a pre-training model stage and a prediction training model stage. In the pre-training model stage, the traffic data to be predicted is input into the model for training in conjunction with the prediction head network, and the model is updated and the parameters are optimized. During the prediction training model phase, the traffic prediction module outputs future traffic flow predictions and compares them with the true values to calculate the error.
[0070] Furthermore, the logical instructions in the aforementioned memory 730 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0071] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer is able to execute the traffic flow prediction method based on the spatiotemporal contrastive learning model provided by the above methods, the method comprising: The data preparation and preprocessing steps include: acquiring traffic flow and / or speed data collected by traffic sensors, slicing the data at fixed time intervals to form a traffic data sequence; modeling the road network structure, defining the sensor locations as graph nodes, and constructing an initial adjacency matrix of the road network based on the distances between nodes; dividing the traffic data sequence into training, validation, and test sets in chronological order, and normalizing the data to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; A traffic flow prediction model based on spatiotemporal contrastive learning is constructed. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation, and the model is jointly trained by combining the prediction loss of the traffic prediction module. The traffic data to be predicted is input into the trained model, and the traffic prediction module outputs the predicted value of future traffic flow.
[0072] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the traffic flow prediction method based on the spatiotemporal contrastive learning model provided by the above methods, the method comprising: The data preparation and preprocessing steps include: acquiring traffic flow and / or speed data collected by traffic sensors, slicing the data at fixed time intervals to form a traffic data sequence; modeling the road network structure, defining the sensor locations as graph nodes, and constructing an initial adjacency matrix of the road network based on the distances between nodes; dividing the traffic data sequence into training, validation, and test sets in chronological order, and normalizing the data to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; A traffic flow prediction model based on spatiotemporal contrastive learning is constructed. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation, and the model is jointly trained by combining the prediction loss from the pre-trained model stage of the traffic flow prediction module. The traffic flow prediction module is divided into a pre-training model stage and a prediction training model stage. In the pre-training model stage, the traffic data to be predicted is input into the model for training in conjunction with the prediction head network, and the model is updated and the parameters are optimized. During the prediction training model phase, the traffic prediction module outputs future traffic flow predictions and compares them with the true values to calculate the error.
[0073] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0074] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.
[0075] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A traffic flow prediction method based on a spatiotemporal contrastive learning model, characterized in that, include: The data preparation and preprocessing steps involve acquiring traffic flow and / or speed data collected by traffic sensors, slicing the data at fixed time intervals to form a traffic data sequence. The road network structure is modeled, with sensor locations defined as graph nodes, and an initial adjacency matrix is constructed based on the distances between nodes. The traffic data sequence is divided into training, validation, and test sets in chronological order, and the data is normalized to construct a spatiotemporal traffic data matrix. Where B is the batch size, N is the number of road network nodes, T1 is the length of the input historical sequence, and D is the feature dimension; A traffic flow prediction model based on spatiotemporal contrastive learning is constructed. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used to generate multiple enhanced views of the input data using the spatiotemporal data augmentation module, input the spatiotemporal graph convolutional network module to extract spatiotemporal features, and calculate the contrastive loss through the contrastive learning module to optimize the feature representation. The traffic data to be predicted is input into the model for training, and the model is updated and the parameters are optimized. The predicted traffic flow value is output and compared with the true value to calculate the error.
2. The traffic flow prediction method based on a spatiotemporal contrastive learning model according to claim 1, characterized in that, The data preparation and preprocessing steps also include: The TDA model is used for time augmentation, with traffic data sequences as input. Then, an average pooling layer with padding is used to quickly obtain samples and effective predictions of the input sequence data, as shown in the following formula (1): (1) in, It is time-pooled data, and To augment contrastive learning with randomized data, random variables are sampled from a uniform distribution. The size is the same as the input data, that is , It is a control factor, determined by element-wise multiplication. and The effect is shown in the following formula (2): (2) in, It is random average data.
3. The traffic flow prediction method based on a spatiotemporal contrastive learning model according to claim 2, characterized in that, The data preparation and preprocessing steps also include: With probability (The range of values is) Discarding data is defined by the following formula (3): (3) For the input traffic data The output of TDA is defined as follows (4): (4) in, It is a time enhancement module. It is augmented data; After time augmentation of the data, spatial augmentation is performed using an optimization graph to obtain different feature representations of the same input data. The optimization graph augmentation part is divided into an optimization additive graph. and optimized dot product map For example, in formula (5): (5) in, This indicates element-wise multiplication. yes The degree matrix, yes The degree matrix, It uses shared optimization graph learning parameters, which can encode data correlations and preserve... and Consistency between them.
4. The traffic flow prediction method based on a spatiotemporal contrastive learning model according to claim 1, characterized in that, The spatiotemporal graph convolutional network module consists of The system consists of spatiotemporal blocks, each of which includes a temporal convolutional layer, a graph convolutional layer, and a gated linear activation layer. Temporal convolutional layers are used to learn the input traffic data. The local time characteristics are calculated as shown in Formula 6: (6) in, This represents a two-dimensional convolution operator with a kernel size of . , It is a local temporal feature. It is a feature The number of channels; Graph convolutional layers are used for learning. The spatial characteristics are calculated as shown in Formula 7: (7) in, These are learnable parameters. It is the order of the Chebyshev polynomial. It is the scaled Laplace matrix. It is the first Chebyshev polynomial of order 1 It is a local spatiotemporal feature. It is a feature The number of channels; Gated linear activation layers are used to control the information flow and maintain the importance of spatiotemporal information when it is passed to the next spatiotemporal block, calculated as shown in Equation 8: (8); in, The operator represents the division operator. , It controls the activation function. It is the output of time characteristics. Used for control The information is passed to the next level; Spatiotemporal graph convolutional networks encode spatiotemporal features The operation summary of the output features of the spacetime block is shown in Formula 9: (9)。 5. The traffic flow prediction method based on a spatiotemporal contrastive learning model according to claim 1, characterized in that, The contrastive learning module is also used for: Different spatiotemporal features are input into the same linear mapping layer, which includes two fully connected networks. The calculation process is as follows: (10) (10) in, , It is the first Features of each sample; , It is the first Features of each sample; It's the dropout ratio, adding random variations to enhance the optimization graph. These are the learning parameters of the Projection_Head network; A negative sample selection model is designed to calculate the feature similarity between anchor point samples and the remaining samples of input traffic data, and to exclude samples with the highest feature similarity to anchor point samples during the negative sample selection process. The sample conforms to the following formula (11): (11) in, Transposed data, It is the maximum index algorithm. It is the cosine similarity function. It is the first in each anchor point sample The sorting number of the maximum feature similarity, and according to These features are excluded from the negative samples of the anchor samples; No. Individual sample features yes Positive samples, features Convert to and will Convert to Thus, the loss function for the spatiotemporal features is input, which conforms to the following formula (12): (12); in, and It is the cosine similarity function. It is a parameter that controls the proportion of negative samples in the input data, and is usually set to 0.1 in contrastive learning; For the input traffic data Two random augmented data sets are generated using the time data augmentation model, as shown in the following formula (13): (13) in, These are two sets of randomly augmented data. and They share the same structure as TDA, but are independent of each other and acquire different random augmentation data. These two random augmentation data... and The feature is incorporated into a multi-graph convolutional network to obtain enhanced features, which conforms to the following formula (14): ; (14); in, These are the spatiotemporal characteristics of each layer; Using the spatiotemporal features of the last layer As input for contrastive learning, these two features are fed into the projection head to obtain output features in the same feature space, conforming to the following formula (15): ; ; ; (15); in, and These are the parameters of the fully connected layer. and It is a bias parameter. , It is the output of the projection head; Using different augmented data with the same input traffic data as positive samples and different augmented data with different input traffic data as negative samples, the infoNCE loss function is calculated according to the following formula (16): (16) in, .
6. The traffic flow prediction method based on a spatiotemporal contrastive learning model according to claim 1, characterized in that, The prediction head network uses skip connections and two fully connected layers to map the pre-trained model. Spatiotemporal characteristics of all layers It conforms to the following formula (17): ; ; ; (17); in, It is a jumping feature. These are the parameters of the skip connection layer. , These are the parameters of two fully connected layers. It is a prediction result. It is a truth value; Using the mean absolute error as the loss function, it conforms to the following formula (18): (18)。 7. The traffic flow prediction method based on a spatiotemporal contrastive learning model according to claim 1, characterized in that, The joint training model combining the prediction loss of the traffic prediction module further includes: The mean absolute error (MAE), mean absolute percentage error (MAPE), and root mean square error (RMSE) were used as evaluation metrics to assess the performance of the trained model.
8. A traffic flow prediction system based on a spatiotemporal contrastive learning model, employing the traffic flow prediction method based on a spatiotemporal contrastive learning model as described in any one of claims 1-7, characterized in that, include: The data preparation and preprocessing module is used to acquire traffic flow and / or speed data collected by traffic sensors, slice the data at fixed time intervals, and form a traffic data sequence. The road network structure is modeled, with sensor locations defined as graph nodes, and an initial adjacency matrix is constructed based on the distances between nodes. The traffic data sequence is divided into training, validation, and test sets in chronological order, and the data is normalized to construct a spatiotemporal traffic data matrix. Where B is the batch size and N is the number of road network nodes. The length of the input historical sequence is given by D, where D is the feature dimension. The model building module is used to build a traffic flow prediction model based on spatiotemporal contrastive learning. The traffic flow prediction model includes a dual-flow enhancement and feature extraction backbone network and a prediction head network. The dual-stream enhancement and feature extraction backbone network includes a spatiotemporal data enhancement module, a spatiotemporal graph convolutional network module, and a contrastive learning module; The spatiotemporal data enhancement module is used to generate enhanced views with differentiated perspectives in time and space for the same batch of input traffic data; The spatiotemporal graph convolutional network module is composed of multiple layers of spatiotemporal blocks stacked together, and is used to extract deep spatiotemporal features from the enhanced data; The contrastive learning module is used to receive multiple sets of spatiotemporal features output from the spatiotemporal graph convolutional network module, map the features to the contrastive learning space through a projection head network, and calculate the total loss of the four contrastive learning tasks based on the decoupled information-noise contrastive estimation loss function, so as to optimize the feature representation capability of the backbone network by bringing positive sample pairs closer and pushing negative sample pairs further apart. The prediction head network is used for: The spatiotemporal data augmentation module generates multiple augmented views of the input data, which are then input into the spatiotemporal graph convolutional network module to extract spatiotemporal features. The contrastive learning module calculates the contrastive loss to optimize the feature representation. The traffic flow prediction module is used to input the traffic data to be predicted into the model for training, update the model and optimize the parameters, output the traffic flow prediction value, and compare the data with the true value to calculate the error.