Traffic flow prediction method based on self-supervised spatio-temporal representation and scene adaptation
By combining self-supervised spatiotemporal representation pre-training with RTP3D residual branching, the problems of insufficient multi-scale dependence and insufficient scene adaptation in urban traffic flow prediction are solved, achieving higher prediction accuracy and response speed.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- QILU UNIVERSITY OF TECHNOLOGY (SHANDONG ACADEMY OF SCIENCES)
- Filing Date
- 2026-02-10
- Publication Date
- 2026-05-19
AI Technical Summary
Existing deep learning methods for urban traffic flow prediction suffer from problems such as insufficient coverage of multi-scale dependencies, accumulation of nonlinear time-period errors, lack of scene adaptation in fusion, and insufficient robustness across scenes. In particular, it is difficult to dynamically adjust the contribution of information sources under complex conditions.
We employ self-supervised spatiotemporal representation pre-training (SSRP) to learn robust evolutionary representations, and combine RTP3D multi-scale residual branching and scene-adaptive multi-expert gating. Through self-supervised spatiotemporal representation pre-training, we generate multi-scale residual compensation features and dynamically generate three-branch gating weights for weighted summation, thereby enhancing prediction accuracy and response speed.
It enhances the multi-scale modeling capability of traffic flow prediction, reduces the dependence on supervised samples, improves the robustness of cross-time period and cross-regional migration, and can retain peak rise and diffusion patterns in complex scenarios, thus mitigating error accumulation.
Smart Images

Figure CN121708754B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of urban traffic flow prediction, and more specifically, relates to a traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation. Background Technology
[0002] Urban traffic flow prediction is a crucial foundational capability for Intelligent Transportation Systems (ITS) and refined urban governance, widely applied in scenarios such as signal timing optimization, congestion warning, capacity control, and road resource allocation. In engineering practice, traffic flow is often represented by a fixed spatial grid, and continuous sampling is performed on multiple channels such as "inflow / outflow" at time slices, forming a typical spatiotemporal sequence prediction task: using the traffic flow grid sequence from several past time steps to predict future traffic conditions.
[0003] However, traffic flow in real urban environments exhibits strong non-stationarity and suddenness, significantly influenced by morning and evening rush hours, accidents and construction, events, and weather changes. Furthermore, multi-scale coupling exists, with differences in functional attributes and road network structures across different regions leading to inconsistent evolution patterns within the same time period. To improve prediction reliability, exogenous variables such as meteorological data and holidays, as well as regional prior semantics, are often introduced as auxiliary information. However, exogenous variables and traffic sequences suffer from differences in sampling frequency, time alignment, and interpolation errors. Regional priors are mostly provided as static vectors / labels and require alignment with grid resolution, making it difficult to characterize key structural information such as road morphology, building density, and land use.
[0004] Existing deep learning methods mostly employ convolutional, recurrent, graph networks, or Transformers to model spatiotemporal correlations and fuse multiple sources using feature concatenation or linear superposition. However, these methods still suffer from several drawbacks: insufficient coverage due to multi-scale dependencies; easy error accumulation during periods of strong nonlinearity; lack of scene adaptation in fusion, making it difficult to dynamically adjust the contribution of information sources under complex conditions such as "rainy days + evening rush hour"; and insufficient robustness across scenarios due to limitations in semantic representation caused by data coverage and annotation granularity. Given the dynamic constraints of traffic systems, relying solely on supervised point prediction is often sensitive to distribution drift. Therefore, there is an urgent need to construct a self-supervised spatiotemporal representation pre-training (SSRP) system to learn more general evolutionary representations and transfer them to downstream predictions. Summary of the Invention
[0005] The present invention aims to overcome at least one of the defects of the prior art and provide a traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation, which aims to enhance the modeling ability of nonlinear spatiotemporal dependence, sudden disturbances and the coupling effect of exogenous environment. Invention Overview:
[0007] This invention starts with exogenous sequence information such as traffic observation data, meteorological / holiday data, and static regional priors. Standardized tensor inputs are generated through unified data preprocessing and alignment, and normalization and mapping parameters are solidified to ensure consistency in training, validation, and testing. Based on this, self-supervised spatiotemporal representation pre-training (SSRP) is conducted to learn robust evolutionary representations. In the downstream prediction stage, RTP3D multi-scale residual branching combined with scene-adaptive multi-expert gating achieves multi-source fusion and prediction output, thereby improving prediction accuracy and response speed.
[0008] The detailed technical solution of this invention is as follows:
[0009] A traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation, the method comprising:
[0010] S1. Acquire traffic flow data, environmental data, and static regional semantic embedding data, and perform preprocessing operations on each data point before fusing them to obtain a standardized tensor input; at the same time, construct structural prior data to constrain and correct the subsequent model prediction output.
[0011] The preprocessing operations include constructing a spatiotemporal matrix for traffic flow data, handling missing values, and normalizing data; encoding environmental features and aligning time for environmental data; and aligning static region semantic embedding data for static region embedding.
[0012] S2. Construct a traffic flow prediction model. Input the preprocessed data into the prediction model and output the future traffic flow prediction results. The prediction process is as follows:
[0013] Self-supervised spatiotemporal representation pre-training is performed. Based on historical traffic windows and aligned environmental conditions, the context encoder is trained through conditional denoising and reconstruction tasks to obtain spatiotemporal encoder parameters with stronger generalization ability. These encoder parameters are then transferred to the downstream predictor to initialize the parameters of the downstream predictor backbone network.
[0014] The downstream predictor uses the DeepResNet3D backbone network to extract steady-state baseline features of historical traffic sequences;
[0015] The RTP3D module constructs three parallel 3D residual branches (macro, meso, and micro) to perform residual compensation on components in the historical sequence that are difficult to be fully characterized by the steady-state backbone, generating multi-scale residual candidates.
[0016] Scenario-adaptive gating fusion: Based on environmental conditions, traffic intensity and abrupt change, an external context representation is constructed, and a three-branch gating weight is dynamically generated. The weighted sum of the weighted weights and multi-scale residual candidates is then obtained to obtain the gated residual compensation features.
[0017] The gated residual compensation features are fused with the steady-state baseline features output by the DeepResNet3D backbone network to obtain the final spatiotemporal fusion features. Finally, the final spatiotemporal fusion features are input into the spatiotemporal decoder to predict the future traffic flow prediction sequence.
[0018] S3. Introduce road masks and capacity upper bounds as constraints during training and inference to improve the stability of prediction output.
[0019] According to a preferred embodiment of the present invention, step S1, which involves constructing a spatiotemporal matrix, handling missing values, and normalizing traffic flow data, specifically includes:
[0020] Spatiotemporal matrix construction includes three steps: spatiotemporal serialization, sliding window slicing, and dimension permutation.
[0021] Spatiotemporal serialization: The spatiotemporal sequence of traffic can be represented as:
[0022] (1)
[0023] in, This represents time-series traffic flow data of length N; N is the total number of time steps; C is the number of channels; H and W represent the number of rows and columns of the spatial raster, respectively; for any t , Let represent the traffic flow raster tensor at time step t;
[0024] Sliding window slicing: For any initial time t, construct the model input and prediction labels as follows:
[0025] (2)
[0026] (3)
[0027] Where t is the starting time step index of the sliding window; L is the length of the historical input window; and T is the prediction step size; thus, This represents the historical input sequence consisting of L consecutive frames of traffic flow raster tensors starting from time step t, where The last frame of the history window; This represents the supervisory label sequence consisting of the traffic flow raster tensors of the following T consecutive frames, where To predict the first frame of the window, To predict the last frame of the window;
[0028] Dimensional permutation: transforming the input tensor The dimensions have been adjusted to a format of "channel first, time second":
[0029] (4)
[0030] in This represents the dimension permutation operator, used to transform... The dimensional order changes from (L,C,H,W) to (C,L,H,W);
[0031] By introducing a batch dimension B into the first dimension of the tensor, we obtain the historical input tensor and the permuted tensor: and ;
[0032] Missing value handling includes handling missing locations The interpolated value is obtained by weighting the temporal and spatial neighborhoods. :
[0033]
[0034] Where t is the time index, c is the channel, and (i,j) is the target grid coordinate; This represents the interpolated value for the missing position; Temporal neighborhood weighting: taking the flow observations of the same grid (i,j) over the past K time steps. and with time decay coefficient The weights control the decay of time lag k as it increases; K is the number of time backtracking steps. Spatial neighborhood weighting: at the same time t, take the set of neighborhoods around the target grid. and use distance attenuation coefficient Empowerment, among which Grid distance; It is a numerically stable term.
[0035] Data normalization involves performing max-min normalization independently for each grid location:
[0036]
[0037] in and These represent the values for channel c and grid position on the training set, respectively. The minimum and maximum values obtained from statistics; This is a numerically stable term; the normalized traffic flow of each grid cell collectively forms the normalized traffic flow sequence. .
[0038] According to a preferred embodiment of the present invention, in step S1, environmental feature encoding and time alignment are performed on the environmental data, and static region embedding alignment is performed on the static region semantic embedding data, specifically as follows:
[0039] The environmental data includes discrete and continuous variables, with the discrete variables obtained using one-hot encoding. The standardized results of continuous variables were obtained by Z-score standardization. The two are then concatenated to form a meteorological feature vector:
[0040] (7)
[0041] in, This represents vector concatenation along the feature dimension; For discrete meteorological variables, the unique heat vector is used. The results are standardized from continuous meteorological variables; Meteorological feature vector The dimension;
[0042] Further meteorological feature vectors Aligned to traffic time step t via linear interpolation, let the two meteorological sampling times adjacent to traffic time step t be... and Then the aligned meteorological vector is:
[0043] (8)
[0044] in, This represents the meteorological feature vector that is aligned to the traffic time step t using linear interpolation; and These represent the times at which meteorological samples were collected. and The meteorological feature vector obtained at the location; For interpolation weights;
[0045] Global discrete identifiers use binary encoding ,in It is a 1-dimensional scalar, and after completion time alignment with... The final environment vector is formed by concatenating the vectors.
[0046] (9)
[0047] in, This represents vector concatenation along the feature dimension; The dimension of the environmental feature vector;
[0048] The static region semantic embedding includes coarse-grained semantic embedding. Cross-domain semantic embedding With fine-grained semantic embedding If the spatial resolution of the semantic embedding of the original static region is different from that of the target mesh... If inconsistent, align it using upsampling / interpolation and edge padding. The aligned multi-source embeddings are concatenated in the feature dimension and then unified to the target dimension through a pixel-level projection network to obtain the region semantic prior feature map:
[0049]
[0050] in This is a pixel-by-pixel multi-layer perception mechanism, where D is the dimension of the target features; To achieve spatial resolution consistent with the backbone features.
[0051] According to a preferred embodiment of the present invention, in step S1, constructing the prior structural data specifically includes:
[0052] A road grid mask M is constructed to identify whether each grid belongs to a passable road network area;
[0053] Constructing an upper bound graph of capacity This represents the maximum reasonable flow intensity for each grid cell in a statistical or structural sense.
[0054] (11)
[0055] in, Represents the set of nonnegative real numbers; This is a capacity upper bound diagram. The first dimension, "2", corresponds to the inflow and outflow channels. The capacity upper bound diagram includes... and Representing grids respectively The upper bound of capacity on the inflow and outflow channels; the upper bound of capacity is estimated by structural information regression or by historical flow statistical quantiles.
[0056] According to a preferred embodiment of the present invention, in step S2, before performing self-supervised spatiotemporal representation pre-training, a normalized traffic flow sequence is first used. Construct a historical traffic window of length L. And the predicted target for future T-steps The corresponding environmental condition sequence is denoted as ;
[0057] The specific steps for performing self-supervised spatiotemporal representation pre-training are as follows:
[0058] In batch training, the historical traffic input corresponding to batch dimension B is: The corresponding rearranged historical traffic input is: ;
[0059] Subsequently, a context encoder is built. Based on the rearranged historical traffic input Aligned environment sequence input and static region prior Input, output conditional feature map :
[0060] (12)
[0061] Next, we perform noise reduction and reconstruction, using the last frame of the historical window as the reconstruction target. Let the target frame be:
[0062] (13)
[0063] right Injection scale is Gaussian noise The perturbation sample is obtained:
[0064] (14)
[0065] Denoising Network In conditional features Predict the noise term:
[0066] (15)
[0067] in, To create a learnable convolutional denoising network and introduce a noise scale. The embedding vector; and simultaneously the conditional features Conditional denoising is achieved by injecting the signal into the network through splicing or modulation.
[0068] Finally, the objective function is trained to minimize the noise prediction error:
[0069] (16)
[0070] in Indicates noise reconstruction loss; Indicates the noise scale With noise The joint sampling distribution takes the expectation For network noise The prediction results; Represents the L2 norm;
[0071] Through the above self-supervised spatiotemporal representation pre-training, spatiotemporal encoder parameters with stronger generalization ability are obtained.
[0072] According to a preferred embodiment of the present invention, in step S2, the downstream predictor uses the DeepResNet3D backbone network to extract steady-state baseline features of historical traffic sequences, specifically as follows:
[0073] Input rearranged historical traffic data The backbone network then extracts features by using multiple layers of 3D convolutions and 3D residual blocks while maintaining the spatial resolution (H, W), and aggregates the temporal dimension to obtain the backbone output.
[0074] (17)
[0075] Further temporal convolutional smoothing and feature normalization are applied to the backbone output:
[0076] (18)
[0077] in, Indicates the backbone network. Number of output channels for the backbone network. The feature map output by the backbone network at time t. This indicates temporal convolution smoothing and feature normalization processing. The processed feature map;
[0078] Then, take The last time slice yields a two-dimensional spatial feature map:
[0079] (19)
[0080] This represents the steady-state baseline characteristics extracted over a historical window length L. This indicates that the feature map corresponding to the T-th time step is extracted from the history window.
[0081] According to a preferred embodiment of the present invention, in step S2, residual compensation is performed on components in the historical sequence that are difficult to be fully characterized by the steady-state backbone to generate multi-scale residual candidates, specifically referring to:
[0082] Input historical traffic The input is the RTP3D module, which employs three parallel 3D convolutional branches, corresponding to the macro, meso, and micro receptive fields, respectively. The three branches are mapped as follows: , , Then the 3D residual candidate features output by each branch are:
[0083] (20)
[0084] in This represents the number of intermediate channels in a single branch.
[0085] The 3D residual candidate features of each branch are then reduced in dimensionality along the time dimension to form a 2D residual candidate map:
[0086] (twenty one)
[0087] in, This represents a 3D convolution operator with a kernel size of 3×1×1, used for local aggregation along the time dimension and to complete channel projection; This indicates that average pooling is performed along the time dimension to reduce the 3D features to a 2D residual candidate map along the time dimension. This represents the number of channels in the candidate residual image after dimensionality reduction. This indicates branches at different time scales.
[0088] According to a preferred embodiment of the present invention, in step S2, an external context representation is constructed based on environmental conditions, flow intensity, and abrupt change degree; a three-branch gating weight is dynamically generated; and the weighted sum is performed with the multi-scale residual candidates to obtain the gated residual compensation feature. Specifically, this refers to:
[0089] Within the input window corresponding to any starting time t, let the last historical time be denoted as t. The gating network constructs three scalar cue quantities based on environmental conditions, durian intensity, and mutation degree:
[0090] (twenty two)
[0091] in, This represents the global average of the input tensor across the channel and spatial dimensions; This is the time-aligned environment vector from Section 1.5; Its mean summary is used to characterize the overall intensity of the current environment; Steady-state benchmark characteristics The global mean is used to characterize the overall flow scale at the end of the window; This is the global mean of the feature differences between two adjacent frames, used to characterize the intensity of short-term abrupt changes; when the window length is less than two frames... It can be set to 0;
[0092] The three scalars are concatenated to obtain the original context input of the gating. Then, it is mapped into a scene vector through a multilayer perceptron. :
[0093] (twenty three)
[0094] in Implemented using fully connected layers and nonlinear activation, it projects low-dimensional cues onto learnable data. A 3D space allows different scenes to be separable in the representation space;
[0095] Based on scene vectors The gated network outputs three-branch logits, and the gate weights, which are interpretable and sum to 1, are obtained through Softmax. :
[0096] (twenty four)
[0097] and These are learnable parameters;
[0098] Finally, the three types of 2D residual candidate maps are weighted and summed to obtain the gated residual compensation features:
[0099] (25)
[0100] Obtain the residual compensation characteristics after gating Then, after necessary channel alignment / linear projection, it is injected into the main steady-state features in a residual manner. .
[0101] According to a preferred embodiment of the present invention, in step S2, the gated residual compensation features are fused with the steady-state baseline features output by the DeepResNet3D backbone network to obtain the final spatiotemporal fusion features. Finally, the final spatiotemporal fusion features are input into the spatiotemporal decoder to predict the future traffic flow prediction sequence. Specifically, this means:
[0102] First, through the channel projection operator Mapping the residual compensation features to the main channel space yields:
[0103] (26)
[0104] Subsequently, residual summation is used to complete the most direct dynamic compensation, resulting in the final spatiotemporal fusion features. :
[0105] (27)
[0106] in Inject intensity into learnable residuals to control the compensation magnitude;
[0107] Through the above fusion, the final spatiotemporal fusion characteristics are obtained. Then through the spacetime decoder First of all Copying / expanding along the time dimension yields the initial decoded tensor:
[0108] (28)
[0109] here This represents the replication of two-dimensional features into a 3D representation of T frames;
[0110] Subsequently, the decoder gradually integrates spatiotemporal details through several layers of 3D transposed convolution and nonlinear transformation;
[0111] Finally, a 1×1×1 3D convolution is used to compress the channels to the target output channel number C=2, and an output constraint function is used. By controlling the forecast range, a future traffic flow forecast sequence is obtained. :
[0112] (29)
[0113] in, For supervision labels; B is the batch size, T is the prediction step size, C=2 indicates the inflow / outflow channel, and H×W is the spatial grid resolution; The spatiotemporal feature tensor output by the decoder. Map the features to the target number of channels. Used to constrain the output to a reasonable range.
[0114] According to a preferred embodiment of the present invention, in step S3, a road mask and an upper capacity bound are introduced for constraint during training and inference, as follows:
[0115] Use road mask To impose consistent constraints on future predicted sequences, Broadcasting in the time dimension and channel dimension yields: ;
[0116] Based on this, define the road mask-weighted regression loss:
[0117] (30)
[0118] in, This is element-wise multiplication; It is a sequence-level spatiotemporal weight mask used to weight the prediction errors at different time steps and different grid positions; Denotes the norm 1;
[0119] Use the capacity upper bound diagram Broadcast it to both the sequence dimension and the channel dimension: ;
[0120] Define the overflow penalty term:
[0121] (31)
[0122] comprehensive and With two types of constraints, the final training objective function is:
[0123] (32)
[0124] in This is the capacity constraint weight, used to balance prediction accuracy and the strength of the upper capacity constraint.
[0125] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0126] (1) This invention proposes an overall prediction framework based on self-supervised spatiotemporal representation pre-training, with RTP3D residual multi-expert modeling as the core and expert gating adaptive fusion as the final step. In the training phase, self-supervised spatiotemporal representation pre-training is first performed. Through joint optimization of reconstruction, rolling generation and consistency constraints, the general evolution law of "external condition change - traffic state migration - congestion diffusion" is learned, thereby reducing the dependence on supervised samples and improving the robustness of cross-time period / cross-region migration. In strongly non-stationary scenarios such as "rainfall superimposed on evening peak", it helps to retain the peak rise and diffusion pattern and alleviate the error accumulation caused by excessive smoothing of the peak segment.
[0127] (2) In terms of the predictor structure, this invention decomposes traffic evolution into "steady-state background trend" and "sudden / high-frequency residual compensation": the backbone network characterizes the medium- and long-term trend and outputs stable baseline features; RTP3D compensates for short-term spikes and high-frequency disturbances, and sets three residual branches with different time receptive fields: macro, medium, and micro. Furthermore, an expert gating network is introduced to encode weather, holidays, and static regional semantics into scene representations, dynamically generate three-branch gating weights, and then weight and aggregate the residuals and fuse them with the backbone to achieve adaptive modeling under different scenarios, enhance sensitivity to peaks and sudden disturbances, and reduce error propagation. Attached Figure Description
[0128] Figure 1 This is a flowchart of the traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation described in this invention.
[0129] Figure 2 This is a flowchart of data preprocessing in Embodiment 1 of the present invention.
[0130] Figure 3 This is a flowchart of the construction process of the spatiotemporal matrix in Embodiment 1 of the present invention.
[0131] Figure 4 This is a flowchart of input rearrangement and context condition encoding in Embodiment 1 of the present invention.
[0132] Figure 5 This is a flowchart of noise disturbance and denoising reconstruction in Embodiment 1 of the present invention.
[0133] Figure 6 This is a flowchart of the stable benchmark spatiotemporal feature extraction process of the DeepResNet3D backbone in Embodiment 1 of the present invention.
[0134] Figure 7 This is a flowchart of RTP3D multi-scale residual candidate generation in Embodiment 1 of the present invention.
[0135] Figure 8 This is a diagram of the external context encoding and gating network structure in Embodiment 1 of the present invention.
[0136] Figure 9 This is a flowchart of the decoding process of the spatiotemporal decoder in Embodiment 1 of the present invention. Detailed Implementation
[0137] The present disclosure will be further described below with reference to the accompanying drawings and embodiments.
[0138] Example 1
[0139] This embodiment provides a traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation. The overall process is as follows: Figure 1 As shown, after data preprocessing and time alignment (SSRP pre-training and parameter transfer), prediction is performed through backbone feature extraction and RTP3D residual gating fusion, and the final result is obtained by combining structural prior constraints at the output. The method specifically includes:
[0140] S1. Acquire traffic flow data, environmental data, and static region semantic embedding data, and perform preprocessing operations on each data before fusing them to obtain a standardized tensor input; at the same time, construct structural prior data to constrain and correct the subsequent model prediction output; the preprocessing operations include constructing a spatiotemporal matrix, handling missing values, and normalizing data for traffic flow data, encoding environmental features and aligning time for environmental data, and aligning static region semantic embedding data for static region embedding.
[0141] like Figure 2 As shown, in this embodiment, the input data includes traffic flow data, environmental data, and static regional semantic embedding data. The traffic flow data represents the urban space using a regular grid, dividing the study area into H×W grid units. The inflow and outflow volumes for each grid are counted at fixed time intervals Δt (e.g., 30 minutes or 5 minutes), forming a rasterized traffic flow sequence. The traffic flow state at time step t is defined as: ;in This represents the inflow and outflow channels, where t∈{1,2,…,N} is the time step index, and N is the total number of time steps. For ease of description later, we will use... Let represent the flow intensity of grid (i,j) on channel c at time step t, where c=1 indicates inflow and c= indicates outflow; i∈{1,2,…,H}, j∈{1,2,…,W}.
[0142] The environmental data is used to characterize external disturbances such as weather and holidays, and is defined as the environmental vector at time step t: ,in The environmental feature vector dimension is equal to the total number of selected external disturbance features (e.g., temperature, rainfall, wind speed, humidity, weather type, and holiday / weekend indicators, etc.). Each feature can be aligned by time, normalized, and then concatenated to form the vector. .
[0143] After obtaining the above data, preprocessing operations are performed on it. In order to capture the dynamic pattern of traffic flow evolution over time, the traffic flow data is first subjected to spatiotemporal matrix construction, missing value handling, and data normalization, as detailed below:
[0144] 1) Figure 3 The process of constructing a spatiotemporal matrix is demonstrated, including three steps: spatiotemporal serialization, sliding window slicing, and dimension permutation. Spatiotemporal serialization: The spatiotemporal sequence of traffic can be represented as:
[0145]
[0146] in, This represents time-series traffic flow data of length N; N is the total number of time steps; C is the number of channels; H and W represent the number of rows and columns of the spatial raster, respectively; for any t , Let represent the traffic flow raster tensor at time step t, which is visualized as a traffic flow raster map at that time step. Let N represent the traffic flow raster tensor at the Nth time step at the end of the sequence; therefore... It represents a complete spatiotemporal sequence formed by stacking traffic flow tensors of N time steps along the time dimension.
[0147] Sliding window slicing: In supervised prediction tasks, let the length of the historical input be L, and the prediction step size be... For any initial time t (satisfying 1≤t≤N) L (T+1), the model input and prediction labels are as follows:
[0148]
[0149]
[0150] Where t is the starting time step index of the sliding window; L is the length of the historical input window; and T is the prediction step size; thus, This represents the historical input sequence consisting of L consecutive frames of traffic flow raster tensors starting from time step t, where The last frame of the history window; This represents the supervisory label sequence consisting of the traffic flow raster tensors of the following T consecutive frames, where To predict the first frame of the window, For the last frame of the prediction window; the constraint 1≤t≤N L T+1 is used to ensure that neither the historical window nor the prediction window exceeds the limit.
[0151] Dimensional substitution: To adapt to the sliding feature extraction of 3D convolutions or spatiotemporal encoders in the time dimension, the input tensor dimension is adjusted to a "channel first, time second" format.
[0152]
[0153] in This represents the dimension permutation operator, used to transform... The dimensional order is transformed from (L, C, H, W) to (C, L, H, W). To support batch training and parallel computation, a batch dimension B (i.e., batch size) is introduced into the first dimension of the tensor. Therefore, the historical input and the permuted tensor are represented as follows: and By adopting this "channel first, time last" data layout, it can be directly adapted to the computational habits of 3D convolution or spatiotemporal encoders, making it easy to characterize periodic and sudden changes along the time axis and capture local propagation and regional coupling relationships along the spatial axis.
[0154] 2) In practical applications, some grid cells may have missing flow values due to abnormal acquisition, sparseness, or missing measurements. To ensure the continuity of the spatiotemporal sequence and reduce the bias introduced by simple zero-filling, this embodiment performs spatiotemporal joint weighted estimation of the missing values. For the missing locations... The interpolated value is obtained by weighting the temporal and spatial neighborhoods. :
[0155]
[0156] Where t is the time index, c is the channel (e.g., inflow / outflow), and (i,j) are the target grid coordinates; This represents the interpolated value for the missing position; the first item Temporal neighborhood weighting: taking the flow observations of the same grid (i,j) over the past K time steps. and with time decay coefficient The weights decrease as the time lag k increases (the greater the lag, the smaller the weight); K is the number of time backtracking steps, which can be selected according to the sampling frequency to cover short-term inertia; the second term Spatial neighborhood weighting: at the same time t, take the set of neighborhoods around the target grid. (For example, a four-neighbor or eight-neighbor area, where only valid neighbors are taken at the boundary), and a distance decay coefficient is used. Empowerment, among which The grid distance can be either Manhattan distance or Euclidean distance, with the weight decreasing as the distance increases; the denominator is the sum of the time and spatial weights mentioned above, used for normalization, so that the interpolated value is a weighted average of the neighborhood observations. This is a numerically stable term to avoid numerical instability when the available neighborhood is empty or the weight sum is too small.
[0157] 3) To improve model training stability and avoid gradient imbalance caused by differences in dimensions between different grids, traffic flow is normalized: Max-min normalization is performed independently for each grid location.
[0158]
[0159] in and These represent the values for channel c and grid position on the training set, respectively. The minimum and maximum values obtained from statistics are fixed and used during the training / inference phase to avoid information leakage; This is a numerically stable term used to avoid a denominator of 0; it is obtained after normalization. The traffic flow generally falls within the [0,1] interval, and the normalized traffic flow of each grid cell collectively forms a normalized traffic flow sequence. .
[0160] Secondly, environmental feature encoding and time alignment are performed on the environmental data, as follows:
[0161] The impact of environmental factors on traffic patterns is significantly scene-dependent, and their sampling frequency often differs from that of the traffic grid. For example, weather is sampled hourly, while traffic is sampled every 30 minutes or 5 minutes. If the nearest neighbor method is directly used to stitch environmental features into the traffic sequence, misalignment can easily occur at time boundaries such as rainfall transitions and sudden changes in wind speed, leading to mismatches between environmental conditions and traffic periods and causing scene misjudgments.
[0162] Therefore, this embodiment first performs unified coding and standardization on environmental elements, and aligns them to the traffic time axis in the time dimension, so that each traffic time step obtains the corresponding environmental input. Environmental data includes discrete and continuous variables: discrete variables such as weather type are encoded using one-hot encoding, while continuous variables such as temperature and wind speed are standardized using Z-score.
[0163]
[0164] in This represents the original value of a certain continuous environmental variable at the corresponding sampling time k (such as temperature, wind speed, etc.). Its standardized results; , These are the mean and standard deviation of the variable on the training set, respectively.
[0165] The two are then concatenated to form a meteorological feature vector (represented by the original sampling time k).
[0166]
[0167] in, This represents vector concatenation along the feature dimension; For discrete meteorological variables, the unique heat vector is used. The results are standardized from continuous meteorological variables; Meteorological feature vector The dimension;
[0168] Considering the potential differences between meteorological sampling frequencies and traffic sampling frequencies, the meteorological feature vector is further... Aligned to traffic time step t via linear interpolation, let the two meteorological sampling times adjacent to traffic time step t be... and Then the aligned meteorological vector is:
[0169]
[0170] in, and These represent the times at which meteorological samples were collected. and The meteorological feature vector obtained at that point, and ≤ ≤ , , These are two meteorological sampling times adjacent to the traffic time step t; This represents the meteorological feature vector that is aligned to the traffic time step t by linear interpolation of the meteorological sequence. For interpolation weights, Used to characterize t in the interval [ , Relative position within: when t= hour =0 has = When t= hour =1 has = .
[0171] Furthermore, global discrete identifiers such as those for holidays are encoded using binary encoding. ,in For example, when distinguishing between "whether it is a holiday" or "whether it is a public holiday", take... =1 indicates a holiday. =0 indicates non-holidays; and after aligning with the completion time... The final environment vector is formed by concatenating the vectors.
[0172]
[0173] in, For the final environment vector The dimension;
[0174] This ensures that each traffic time step receives environmental condition inputs on the same time axis, enabling the model to perceive and model scenarios such as "rainy day + evening rush hour", "strong wind + neighboring area corridor", and "holiday + scenic spot gathering" at the correct time and location.
[0175] Then, static region embedding alignment is performed on the static region semantic embedding data, as follows:
[0176] To enhance the model's ability to identify regional functional and spatial structural differences, static region semantic embeddings are introduced as long-term prior information. In this embodiment, the static region semantic embedding consists of multi-source embeddings, including coarse-grained semantic embeddings. Cross-domain semantic embedding With fine-grained semantic embedding If the spatial resolution of the original static embedding is And with the target grid If inconsistent, align it using upsampling / interpolation and edge padding. .
[0177] The aligned multi-source embeddings are concatenated along the feature dimension and then unified to the target dimension through a pixel-level projection network (MLP / 1×1 linear projection) to obtain the region semantic prior feature map:
[0178]
[0179] in This is a pixel-by-pixel multi-layer perception mechanism (Linear–ReLU–Linear), where D is the dimension of the target feature. To achieve spatial resolution consistent with the backbone features.
[0180] During the model input and fusion stage, historical traffic sequences are used to extract dynamic features via the backbone network. Aligned environment sequence Providing external context, the region semantic prior feature map and dynamic features jointly participate in the fusion to obtain a fused representation:
[0181]
[0182] in This refers to fusion operators, including convolution / linear projection after feature concatenation, gated weighting, or attention fusion.
[0183] The above data preprocessing yields a normalized traffic flow sequence. Environmental feature sequences aligned with the traffic timeline , and static region semantic embeddings R aligned to grid resolution.
[0184] Furthermore, relying solely on data-driven learning, the model may produce two types of unreasonable outputs in its predictions: first, "leaking" flow in non-road grids; and second, "overshooting" predictions exceeding reasonable limits for main road grids during periods of heavy rainfall or extreme peak times. To improve the physical rationality and structural consistency of the prediction results, prior structural data is constructed to constrain and correct subsequent model prediction outputs.
[0185] In this embodiment, a road grid mask M is constructed to identify whether each grid belongs to a passable road network area, and it is defined as follows: .
[0186] Represents a grid There is road coverage and vehicle traffic is permitted. 0 represents a non-road area. The road grid mask M can be obtained by projecting the GIS road network vector onto the grid, or by thresholding the road density. This mask can be directly gated at the output end to reduce noise leakage from non-road areas.
[0187] Simultaneously, a capacity upper bound graph can be constructed. This represents the maximum reasonable flow intensity for each grid cell in a statistical or structural sense.
[0188]
[0189] in, Represents the set of nonnegative real numbers; This is a capacity upper bound diagram, where the first dimension "2" corresponds to the inflow and outflow channels; for example, and Representing grids respectively The maximum reasonable flow intensity on the inflow / outflow channel is the upper limit of capacity. The upper limit of capacity can be estimated by regression from structural information such as road grade, number of lanes, and road network density, or by historical flow statistics quantiles (such as the 99th percentile).
[0190] During the inference phase, let the unconstrained output of the backbone network at time t+1 be... First, the initial prediction is obtained through nonnegative mapping. ;
[0191] Then, the scaling factor is calculated for each grid. When the total predicted volume exceeds the upper limit of the capacity, the dual channels are scaled proportionally to ensure that the capacity is not exceeded and the in / out ratio is maintained.
[0192]
[0193]
[0194] in, and This indicates that before applying capacity constraints, the model at time t+1 is in the grid. Initial forecasts for inflows / outflows; This is a numerically stable term used to avoid numerical instability caused by a denominator of zero.
[0195] S2. Input the preprocessed data into the prediction model and output the future traffic flow prediction results;
[0196] First, following the method for constructing supervised samples defined in the sliding window slicing step, we use normalized traffic flow sequences. Construct a historical traffic window of length L. And the predicted target for future T-steps Then, the historical input and the permuted tensor corresponding to the batch dimension B are represented as follows: and The corresponding environmental condition sequence is denoted as Based on this, the specific steps for the model training and inference stages are as follows:
[0197] Self-supervised spatiotemporal representation pre-training is performed. Based on historical traffic windows and aligned environmental conditions, a context encoder is trained through a conditional denoising and reconstruction task to obtain spatiotemporal encoder parameters with stronger generalization ability. These encoder parameters are then transferred to the downstream predictor to initialize the parameters of the downstream predictor backbone network.
[0198] Supervised regression fitting only While the model readily learns local correlations in the training set, it struggles to respond adequately to out-of-distribution shocks when samples from sudden events such as heavy rain, accidents, or temporary traffic control are scarce or when distribution shifts occur. This can lead to issues like peak smoothing and delayed peak fallback. To address this, this embodiment proposes Self-Supervised Spatiotemporal Representation Pre-training (SSRP): Given historical traffic windows and external conditions, the model learns the general evolutionary patterns of traffic states through conditional denoising / generation. It then employs joint optimization using denoising reconstruction, rolling generation, and consistency constraints to enable the encoder to obtain robust representations of periodic rhythms, scene differences, and disturbance transfers. These representations are subsequently transferred to the downstream predictor to improve convergence speed and cross-time / cross-regional generalization performance.
[0199] 1) Input rearrangement and contextual condition encoding:
[0200] In batch training, if the batch dimension is B, then the historical traffic input stack is:
[0201]
[0202] To adapt to the "channel-first, time-last" format commonly used in 3D convolutional or spatiotemporal encoders, its dimensions are replaced as follows:
[0203]
[0204] Subsequently, a context encoder is constructed in the self-supervised spatiotemporal representation pre-training framework SSRP. This is used to jointly encode historical traffic windows with external conditions, resulting in a conditional feature map that constrains the "current scene / state". Specifically, Based on rearranged historical traffic input Aligned environment sequence input and static region prior Input, output conditional feature map , This can be understood as a spatial expression of "the macroscopic operational state of urban traffic within time window L," which will serve as conditional information in subsequent denoising reconstruction / generative learning, constraining the network to generate traffic states consistent with this scenario.
[0205]
[0206] Figure 4 This demonstrates the process of input rearrangement and context-conditional encoding.
[0207] 2) Noise disturbance - denoising and reconstruction
[0208] In the self-supervised spatiotemporal representation pre-training, this embodiment uses the last frame of the historical window as the reconstruction target (which is strongly correlated with the downstream prediction task and facilitates stable training in implementation). The target frame is denoted as:
[0209]
[0210] right Injection scale is Gaussian noise , Each element is an independent standard normal random variable, resulting in a perturbed sample:
[0211]
[0212] Denoising Network In conditional features Predict the noise term:
[0213]
[0214] in, A learnable convolutional denoising network can be constructed by stacking several residual blocks and introducing noise scales. The embedding vector; and simultaneously the conditional features Conditional denoising is achieved by injecting the signal into the network through splicing or modulation. Figure 5 A schematic diagram of noise disturbance and denoising reconstruction is shown.
[0215] 3) Training objective function and transfer explanation
[0216] To train the denoising network, minimize the noise prediction error:
[0217]
[0218] in Indicates noise reconstruction loss; Indicates the noise scale With noise The joint sampling distribution takes the expectation For network noise The prediction results; Represents the L2 norm;
[0219] Through the aforementioned self-supervised spatiotemporal representation pre-training, spatiotemporal encoder parameters with stronger generalization capabilities can be obtained. In the downstream supervised prediction stage, these encoder parameters are used as initialization or prior feature extractors, and then combined with a stronger prediction backbone and residual expert gating mechanism, end-to-end prediction of future T-step traffic flow maps can be achieved.
[0220] After completing the self-supervised spatiotemporal representation pre-training, this embodiment transfers the spatiotemporal encoder parameters with stronger generalization ability obtained in the pre-training stage to the downstream predictor to initialize key network parameters, thereby reducing the slow convergence and insensitivity to sudden scenarios caused by training from scratch. Specifically, the context encoder obtained from the self-supervised pre-training... We studied "the typical spatiotemporal structure and evolution of traffic conditions under given historical windows and external conditions," with parameters denoted as... The backbone network of the downstream predictor is used to extract stable trend representations of historical sequences, and its parameters are denoted as... This embodiment uses parameter migration to initialize the downstream backbone: ,in" "Indicates that will" As Initial weights: Layers with consistent structure and shape are directly assigned weights; layers with inconsistent structures are initialized using name matching and partial loading (or shape self-adaptive mapping) to ensure network structure usability. Through the "pre-training-transfer-fine-tuning" training strategy, the downstream predictor can converge faster and improve generalization stability in cross-time / cross-regional and sudden disturbance scenarios.
[0221] The downstream predictor uses the DeepResNet3D backbone network to extract steady-state baseline features of historical traffic sequences:
[0222] In the downstream supervised prediction stage, based on parameter transfer initialization, a DeepResNet3D backbone network is used to extract spatiotemporal features from historical traffic sequences to obtain baseline features representing "normal trends / stable structures." Let the backbone network be... Its input is the historical traffic data rearranged according to "channel first, time second". The backbone extracts features by using multiple layers of 3D convolutions and 3D residual blocks while maintaining the spatial resolution (H, W), and then aggregates the temporal dimension to obtain the backbone output.
[0223]
[0224] in The number of main output channels.
[0225] Since the backbone output is compressed to 1 in the time dimension during implementation, this embodiment further applies temporal convolutional smoothing and feature normalization to enhance representation stability and facilitate subsequent fusion:
[0226]
[0227] in, The feature map output by the backbone network at time t; This means applying a smooth convolution along the time axis to the feature and then normalizing it to improve the stability of the representation and facilitate subsequent fusion. This is the processed feature map.
[0228] Subsequently, to interface with the subsequent residual expert branch and decoder, the last time slice (with a time length of 1, equivalent to taking a unique slice) is taken to obtain the two-dimensional spatial feature map:
[0229]
[0230] This represents the steady-state baseline characteristics extracted over a historical window length L, used to characterize the periodic patterns of commuting peaks, the stable differences between the core and peripheral areas, and the relatively persistent spatial structure. This indicates that the feature map corresponding to the Tth time step is extracted from the historical window for subsequent modules to model and fuse. Figure 6 The diagram illustrates the baseline feature extraction process of the DeepResNet3D backbone.
[0231] The RTP3D module constructs three parallel 3D residual branches (macro, meso, and micro) to perform residual compensation on components in the historical sequence that are difficult to be fully characterized by the steady-state backbone, generating multi-scale residual candidates.
[0232] Relying solely on the backbone network, predictions are prone to lag or over-smoothing when faced with high-frequency abrupt changes and local spikes caused by accidents, regulations, or heavy rain. To enhance the model's responsiveness to sudden changes and high-frequency details, this embodiment stabilizes the backbone features. In addition, the RTP3D (Residual Temporal Propagation 3D) module is introduced to perform residual compensation for components in historical sequences that are difficult to be fully characterized by the steady-state backbone, such as "short-term spikes, propagation and diffusion, and structural abrupt changes." Figure 7 As shown.
[0233] Specifically, historical traffic input 3D residual candidate generation is performed using the macro / meso / micro three-branch input:
[0234] RTP3D employs three parallel 3D convolutional branches, corresponding to macro, meso, and micro receptive fields respectively, to form a multi-scale residual candidate set. Let the three branch mappings be... , , Then the 3D residual candidate features output by each branch are:
[0235]
[0236] in This represents the number of intermediate channels in a single branch.
[0237] The 3D residual candidate features of each branch are then reduced to 2D residual candidate maps along the time dimension:
[0238]
[0239] in, This represents a 3D convolution operator with a kernel size of 3×1×1, used for local aggregation along the time dimension and to complete channel projection; This indicates that average pooling is performed along the time dimension to reduce the 3D features to a 2D residual candidate map along the time dimension. This represents the number of channels in the candidate residual image after dimensionality reduction. Indicates branches at different time scales;
[0240] The parallel output of the above-mentioned "macro-medium-micro" three branches enables the change patterns that are difficult to capture by a single steady-state backbone to be explicitly decomposed into interpretable multi-scale residual candidates, providing an object basis for subsequent gating selection.
[0241] An external context representation is constructed based on environmental conditions, flow intensity, and abrupt change degree. A three-branch gating weight is dynamically generated, and it is weighted and summed with multi-scale residual candidates to obtain the gated residual compensation feature.
[0242] The three residual candidate classes (macro / meso / micro) alone are insufficient to cover the dominant change scales under different external scenarios. Therefore, external context encoding and gating networks are introduced to encode environmental conditions and the current traffic situation into a scene representation, and based on this, three-branch weights are dynamically generated to achieve adaptive selection of "scene-scale," such as... Figure 8 As shown.
[0243] 1) Construction of the external state scalar required for gating:
[0244] At any initial time t (satisfying 1≤t≤N) L In the input window corresponding to T+1, record the last historical moment as... Gated networks do not directly use the full high-dimensional input, but instead construct three scalar cue quantities based on three aspects: "environmental conditions, content intensity, and degree of mutation."
[0245]
[0246] in, This represents the global average of the input tensor across the channel and spatial dimensions; This is the time-aligned environment vector from Section 1.5; Its mean summary is used to characterize the overall intensity of the current environment; Steady-state benchmark characteristics The global mean is used to characterize the overall flow scale at the end of the window; This is the global mean of the feature differences between two adjacent frames, used to characterize the intensity of short-term abrupt changes; when the window length is less than two frames... It can be set to 0.
[0247] The above three questions respectively answer whether the environment is abnormal, whether the current load is high, and whether it is undergoing mutation, providing an explanatory basis for the subsequent selection of macro / meso / micro.
[0248] 2) External Context Encoding - From Scalar to Scene Vector:
[0249] The three scalars are concatenated to obtain the original context input of the gating. Then, it is mapped into a scene vector through a multilayer perceptron. :
[0250]
[0251] in This can be achieved using a "fully connected layer + non-linear activation" approach, used to project low-dimensional cues onto learnable data. 3D space allows different scenes to be separable in the representation space: for example, "heavy rain + sudden change" will simultaneously increase the height. , The statement that "high prices during holidays" is more in line with... , The long-term rise.
[0252] 3) Three-branch weight generation - Softmax normalization scale selection:
[0253] Based on scene vectors The gated network outputs three-branch logits, and the gate weights, which are interpretable and sum to 1, are obtained through Softmax. :
[0254]
[0255] , These are learnable parameters; the Softmax constraint ensures that the weights inherently possess a "proportional" meaning. During training, if a micro-branch is more effective at reducing error in a certain scenario (e.g., an accidental stab), backpropagation will promote the corresponding micro-branch in that scenario. Increase; if holidays cause a more significant overall increase over a longer period, then It will be driven up.
[0256] 4) Residual Gated Aggregation - Weighting and merging the three types of candidate residuals into the main branch:
[0257] Finally, the three types of 2D residual candidate maps are weighted and summed to obtain the gated residual compensation features:
[0258]
[0259] Obtain the residual compensation characteristics after gating Then, after necessary channel alignment / linear projection, it is injected into the main steady-state features in a residual manner. This forms a unified representation that simultaneously includes "steady-state trend + scene adaptive residual compensation" for subsequent regional semantic fusion and end-to-end decoder prediction.
[0260] The gated residual compensation features are fused with the steady-state baseline features output by the DeepResNet3D backbone network to obtain the final spatiotemporal fusion features. Finally, the final spatiotemporal fusion features are input into the spatiotemporal decoder to predict the future traffic flow prediction sequence.
[0261] Residual compensation characteristics after gating Steady-state baseline features of the DeepResNet3D backbone output Channel alignment and residual fusion are performed to obtain the final fused features used for decoding prediction. .
[0262] Considering and The number of channels may differ ( First, through the channel projection operator Mapping the residual compensation features to the main channel space yields:
[0263]
[0264] Subsequently, residual summation is used to complete the most direct dynamic compensation, resulting in the final spatiotemporal fusion features. :
[0265]
[0266] in Intensities are injected into the learnable residuals to control the compensation amplitude. Through the above fusion process, the final spatiotemporal fusion features are obtained. It also includes the steady-state structure and periodic trends learned by the backbone and the compensation for sudden disturbances and propagation chains provided by the gating residuals.
[0267] After obtaining the final fusion characteristics Then, through the spacetime decoder This is mapped to a dual-channel traffic flow prediction sequence for the next T time steps. Figure 9 The decoding process of the spatiotemporal decoder is demonstrated. According to the definition of supervision in Chapter 1, the model output should correspond to the label. Alignment is required, therefore the predicted output is defined as:
[0268]
[0269] in For the first Inflow / outflow forecast graph for each moment.
[0270] To recover the time dimension from the two-dimensional fused representation, the decoder first... Copying / expanding along the time dimension yields the initial decoded tensor:
[0271]
[0272] here This means that the two-dimensional features are copied into a 3D representation of T frames, so that subsequent 3D convolutions can be jointly modeled and refined in the time dimension.
[0273] Subsequently, the decoder gradually integrates spatiotemporal details through several layers of 3D transposed convolution (deconvolution) and nonlinear transformations (the example uses two layers, which can be extended to multiple layers depending on the implementation):
[0274]
[0275]
[0276] in This represents a 3D transposed convolution with kernel size k and stride s, where BN is batch normalization. The activation function is ReLU. The purpose of these layers is to enhance the resolvable dynamics in the temporal dimension and supplement local details while maintaining consistent spatial resolution.
[0277] Finally, a 1×1×1 3D convolution is used to compress the channels to the target output channel number C=2, and an output constraint function is used. By controlling the forecast range, a future traffic flow forecast sequence is obtained. :
[0278]
[0279] in, For supervision labels; B is the batch size, T is the prediction step size, C=2 indicates the inflow / outflow channel, and H×W is the spatial grid resolution; The spatiotemporal feature tensor output by the decoder. Map the features to the target number of channels. Use the Sigmoid function to constrain the output to a reasonable range.
[0280] S3. Introduce road masks and capacity upper bounds as constraints during training and inference to improve the stability of prediction output:
[0281] Road mask obtained based on structural priors With upper capacity bound diagram Furthermore, it provides the loss constraints and joint optimization objectives during the supervised training phase.
[0282] 1) Prediction error term weighted by road mask
[0283] Use road mask To impose consistent constraints on future predicted sequences, Broadcasting in the time dimension and channel dimension yields: .
[0284] Based on this, define the road mask-weighted regression loss:
[0285]
[0286] in, This is element-wise multiplication; This is a sequence-level spatiotemporal weight mask used to weight the prediction errors at different time steps and different grid positions, and its shape is similar to... The same or can be aligned according to broadcast rules; and Let represent the predicted traffic flow tensor and the actual traffic flow tensor at time step t, respectively. The loss term represents the L1 norm; its meaning is to focus supervision on real traversable areas, avoiding the model from "fabricating traffic flow" in non-road areas to fit the whole map, thereby improving the spatial structure consistency of the predicted map.
[0287] 2) Capacity upper bound constraint (suppressing unreasonable peak overflow)
[0288] Use the capacity upper bound diagram Similarly, broadcast it to both the sequence dimension and the channel dimension: .
[0289] The capacity constraint does not require the prediction to be close to the capacity, but only imposes a penalty when the prediction exceeds the upper bound. Therefore, an "overflow penalty term" is defined:
[0290]
[0291] in Element-wise effect: This item is 0 when the prediction does not exceed the upper limit of the capacity; when a "burst point" exceeds the upper limit, the penalty increases with the increase of the overflow magnitude, thereby suppressing unreasonable spikes and improving stability in the peak segment.
[0292] 3) Final training objective (joint optimization of accuracy and structural rationality)
[0293] Combining the above two types of constraints, the final training objective function is given as follows:
[0294]
[0295] in The capacity constraint weights are used to balance prediction accuracy and the strength of the capacity upper bound constraint. Through this joint objective, the model suppresses overshoot and non-road noise leakage while fitting the error of the real data, thereby improving the stability and structural consistency of the output.
[0296] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solutions of the present invention, and are not intended to limit the specific implementation of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention should be included within the protection scope of the claims of the present invention.
Claims
1. A traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation, characterized in that, The method includes: S1. Acquire traffic flow data, environmental data, and static regional semantic embedding data, and perform preprocessing operations on each data point before fusing them to obtain a standardized tensor input; at the same time, construct structural prior data to constrain and correct the subsequent model prediction output. The preprocessing operations include constructing a spatiotemporal matrix for traffic flow data, handling missing values, and normalizing data; encoding environmental features and aligning time for environmental data; and aligning static region semantic embedding data for static region embedding. S2. Construct a traffic flow prediction model. Input the preprocessed data into the prediction model and output the future traffic flow prediction results. The prediction process is as follows: Self-supervised spatiotemporal representation pre-training is performed. Based on historical traffic windows and aligned environmental conditions, the context encoder is trained through conditional denoising and reconstruction tasks to obtain spatiotemporal encoder parameters with stronger generalization ability. These encoder parameters are then transferred to the downstream predictor to initialize the parameters of the downstream predictor backbone network. The downstream predictor uses the DeepResNet3D backbone network to extract steady-state baseline features of historical traffic sequences; The RTP3D module constructs three parallel 3D residual branches (macro, meso, and micro) to perform residual compensation on components in the historical sequence that are difficult to be fully characterized by the steady-state backbone, generating multi-scale residual candidates. Scenario-adaptive gating fusion: Based on environmental conditions, traffic intensity and abrupt change, an external context representation is constructed, and a three-branch gating weight is dynamically generated. The weighted sum of the weighted weights and multi-scale residual candidates is then obtained to obtain the gated residual compensation features. The gated residual compensation features are fused with the steady-state baseline features output by the DeepResNet3D backbone network to obtain the final spatiotemporal fusion features. Finally, the final spatiotemporal fusion features are input into the spatiotemporal decoder to predict the future traffic flow prediction sequence. S3. Introduce road masks and capacity upper bounds as constraints during training and inference to improve the stability of prediction output.
2. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 1, characterized in that, In step S1, the traffic flow data undergoes spatiotemporal matrix construction, missing value processing, and data normalization, specifically including: Spatiotemporal matrix construction includes three steps: spatiotemporal serialization, sliding window slicing, and dimension permutation. Spatiotemporal serialization: The spatiotemporal sequence of traffic can be represented as: (1) in, This represents time-series traffic flow data of length N; N is the total number of time steps; C is the number of channels; H and W represent the number of rows and columns of the spatial raster, respectively; for any t , Let represent the traffic flow raster tensor at time step t; Sliding window slicing: For any initial time t, construct the model input and prediction labels as follows: (2) (3) Where t is the starting time step index of the sliding window; L is the length of the historical input window; and T is the prediction step size; thus, This represents the historical input sequence consisting of L consecutive frames of traffic flow raster tensors starting from time step t, where The last frame of the history window; This represents the supervisory label sequence consisting of the traffic flow raster tensors of the following T consecutive frames, where To predict the first frame of the window, To predict the last frame of the window; Dimensional permutation: transforming the input tensor The dimensions have been adjusted to a format of "channel first, time second": (4) in This represents the dimension permutation operator, used to transform... The dimensional order changes from (L,C,H,W) to (C,L,H,W); By introducing a batch dimension B into the first dimension of the tensor, we obtain the historical input tensor and the permuted tensor: and ; Missing value handling includes handling missing locations The interpolated value is obtained by weighting the temporal and spatial neighborhoods. : Where t is the time index, c is the channel, and (i,j) is the target grid coordinate; This represents the interpolated value for the missing position; Temporal neighborhood weighting: taking the flow observations of the same grid (i,j) over the past K time steps. and with time decay coefficient The weights control the decay of time lag k as it increases; K is the number of time backtracking steps. Spatial neighborhood weighting: at the same time t, take the set of neighborhoods around the target grid. and use distance attenuation coefficient Empowerment, among which Grid distance; It is a numerically stable term; Data normalization involves performing max-min normalization independently for each grid location: in and These represent the values for channel c and grid position on the training set, respectively. The minimum and maximum values obtained from statistics; This is a numerically stable term; the normalized traffic flow of each grid cell collectively forms the normalized traffic flow sequence. .
3. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 2, characterized in that, In step S1, environmental feature encoding and time alignment are performed on the environmental data, and static region embedding alignment is performed on the static region semantic embedding data, as detailed below: The environmental data includes discrete and continuous variables, with the discrete variables obtained using one-hot encoding. The standardized results of continuous variables were obtained by Z-score standardization. The two are then concatenated to form a meteorological feature vector: (7) in, This represents vector concatenation along the feature dimension; For discrete meteorological variables, the unique heat vector is used. The results are standardized from continuous meteorological variables; Meteorological feature vector The dimension; Further meteorological feature vectors Aligned to traffic time step t via linear interpolation, let the two meteorological sampling times adjacent to traffic time step t be... and Then the aligned meteorological vector is: (8) in, This represents the meteorological feature vector that is aligned to the traffic time step t using linear interpolation; and These represent the times at which meteorological samples were collected. and The meteorological feature vector obtained at the location; For interpolation weights; Global discrete identifiers use binary encoding ,in It is a 1-dimensional scalar, and after completion time alignment with... The final environment vector is formed by concatenating the vectors. (9) in, This represents vector concatenation along the feature dimension; For the final environment vector The dimension; The static region semantic embedding includes coarse-grained semantic embedding. Cross-domain semantic embedding With fine-grained semantic embedding If the spatial resolution of the semantic embedding of the original static region is different from that of the target mesh... If inconsistent, align it using upsampling / interpolation and edge padding. The aligned multi-source embeddings are concatenated in the feature dimension and then unified to the target dimension through a pixel-level projection network to obtain the region semantic prior feature map: in This is a pixel-by-pixel multi-layer perception mechanism, where D is the dimension of the target features; To achieve spatial resolution consistent with the backbone features.
4. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 3, characterized in that, In S1, the construction of prior structural data specifically includes: A road grid mask M is constructed to identify whether each grid belongs to a passable road network area; Constructing an upper bound graph of capacity This represents the maximum reasonable flow intensity for each grid cell in a statistical or structural sense. (11) in, Represents the set of nonnegative real numbers; This is a capacity upper bound diagram. The first dimension, "2", corresponds to the inflow and outflow channels. The capacity upper bound diagram includes... and Representing grids respectively The upper bound of capacity on the inflow and outflow channels; H and W are the number of grid rows and columns, respectively; the upper bound of capacity is estimated by structural information regression or by historical flow statistics quantiles.
5. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 4, characterized in that, In step S2, before performing self-supervised spatiotemporal representation pre-training, a normalized traffic flow sequence is first used. Construct a historical traffic window of length L. And the predicted target for future T-steps The corresponding environmental condition sequence is denoted as ; The specific steps for performing self-supervised spatiotemporal representation pre-training are as follows: In batch training, the historical traffic input corresponding to batch dimension B is: The corresponding rearranged historical traffic input is: ; Subsequently, a context encoder is built. Based on the rearranged historical traffic input Aligned environment sequence input and static region prior Input, output conditional feature map : (12) Next, we perform noise reduction and reconstruction, using the last frame of the historical window as the reconstruction target. Let the target frame be: (13) right Injected noise scale is Gaussian noise The perturbation sample is obtained: (14) Denoising Network In conditional features Predict the noise term: (15) in, To create a learnable convolutional denoising network and introduce a noise scale. The embedding vector; and simultaneously the conditional features Conditional denoising is achieved by injecting the signal into the network through splicing or modulation. Finally, the objective function is trained to minimize the noise prediction error: (16) in Indicates noise reconstruction loss; Indicates the noise scale With noise The joint sampling distribution takes the expectation; For network noise The prediction results; Represents the L2 norm; Through the above self-supervised spatiotemporal representation pre-training, spatiotemporal encoder parameters with stronger generalization ability are obtained.
6. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 5, characterized in that, In step S2, the downstream predictor uses the DeepResNet3D backbone network to extract steady-state baseline features of historical traffic sequences, as follows: Input rearranged historical traffic data The backbone network then extracts features by using multiple layers of 3D convolutions and 3D residual blocks while maintaining the spatial resolution (H, W), and aggregates the temporal dimension to obtain the backbone output. (17) Further temporal convolutional smoothing and feature normalization are applied to the backbone output: (18) in, Indicates the backbone network. Number of output channels for the backbone network. The feature map output by the backbone network at time t. This indicates temporal convolution smoothing and feature normalization processing. The processed feature map; Then, take The last time slice yields a two-dimensional spatial feature map: (19) This represents the steady-state baseline characteristics extracted over a historical window length L. This indicates that the feature map corresponding to the T-th time step is extracted from the history window.
7. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 6, characterized in that, In S2, residual compensation is performed on components in the historical sequence that are difficult to be fully characterized by the steady-state backbone to generate multi-scale residual candidates. Specifically, this means: Input historical traffic The input is the RTP3D module, which employs three parallel 3D convolutional branches, corresponding to the macro, meso, and micro receptive fields, respectively. The three branches are mapped as follows: , , Then the 3D residual candidate features output by each branch are: (20) in This refers to the number of intermediate channels in a single branch. The 3D residual candidate features of each branch are then reduced in dimensionality along the time dimension to form a 2D residual candidate map: (21) in, This represents a 3D convolution operator with a kernel size of 3×1×1, used for local aggregation along the time dimension and to complete channel projection; This indicates that average pooling is performed along the time dimension to reduce the 3D features to a 2D residual candidate map along the time dimension. This represents the number of channels in the candidate residual image after dimensionality reduction. This indicates branches at different time scales.
8. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 7, characterized in that, In S2, an external context representation is constructed based on environmental conditions, flow intensity, and abrupt change degree. A three-branch gating weight is dynamically generated, and this weighted sum is performed with multi-scale residual candidates to obtain the gated residual compensation feature. Specifically, this refers to: Within the input window corresponding to any starting time t, let the last historical time be denoted as t. The gating network constructs three scalar cue quantities based on environmental conditions, flow intensity, and degree of abrupt change: (22) in, This represents the global average of the input tensor across the channel and spatial dimensions; This represents the environmental vector formed by concatenating the time-aligned meteorological feature vector with the global discrete identifier at traffic time step t. Its mean summary is used to characterize the overall intensity of the current environment; Steady-state benchmark characteristics The global mean is used to characterize the overall flow scale at the end of the window; This is the global mean of the feature differences between two adjacent frames, used to characterize the intensity of short-term abrupt changes; when the window length is less than two frames... It can be set to 0; The three scalars are concatenated to obtain the original context input of the gating. Then, it is mapped into a scene vector through a multilayer perceptron. : (23) in Implemented using fully connected layers and nonlinear activation, it projects low-dimensional cues onto learnable data. A 3D space allows different scenes to be separable in the representation space; Based on scene vectors The gated network outputs three-branch logits, and the gate weights, which are interpretable and sum to 1, are obtained through Softmax. : (24) and These are learnable parameters; Finally, the three types of 2D residual candidate maps are weighted and summed to obtain the gated residual compensation features: (25) Obtain the residual compensation characteristics after gating Then, after necessary channel alignment / linear projection, it is injected into the main steady-state features in a residual manner. .
9. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 8, characterized in that, In step S2, the gated residual compensation features are fused with the steady-state baseline features output by the DeepResNet3D backbone network to obtain the final spatiotemporal fusion features. Finally, the final spatiotemporal fusion features are input into the spatiotemporal decoder to predict the future traffic flow prediction sequence. Specifically, this means: First, through the channel projection operator Mapping the residual compensation features to the main channel space yields: (26) Subsequently, residual summation is used to complete the most direct dynamic compensation, resulting in the final spatiotemporal fusion features. : (27) in Inject intensity into learnable residuals to control the compensation magnitude; Through the above fusion, the final spatiotemporal fusion characteristics are obtained. Then through the spacetime decoder First of all Copying / expanding along the time dimension yields the initial decoded tensor: (28) here This represents the replication of two-dimensional features into a 3D representation of T frames; Subsequently, the decoder gradually integrates spatiotemporal details through several layers of 3D transposed convolution and nonlinear transformation; Finally, a 1×1×1 3D convolution is used to compress the channels to the target output channel number C=2, and an output constraint function is used. By controlling the forecast range, a future traffic flow forecast sequence is obtained. : (29) in, For supervision labels; B is the batch size, T is the prediction step size, C=2 indicates the inflow / outflow channel, and H×W is the spatial grid resolution; The spatiotemporal feature tensor output by the decoder. Map the features to the target number of channels. Used to constrain the output to a reasonable range.
10. The traffic flow prediction method based on self-supervised spatiotemporal representation and scene adaptation according to claim 9, characterized in that, In S3, road masks and capacity upper bounds are introduced as constraints during training and inference, as follows: Use road mask To impose consistent constraints on future predicted sequences, Broadcasting in the time dimension and channel dimension yields: ; Based on this, define the road mask-weighted regression loss: (30) in, This represents element-wise multiplication; It is a sequence-level spatiotemporal weight mask used to weight the prediction errors at different time steps and different grid positions; Denotes the norm 1; Use the capacity upper bound diagram Broadcast it to both the sequence dimension and the channel dimension: ; Define the overflow penalty term: (31) comprehensive and With two types of constraints, the final training objective function is: (32) in This is the capacity constraint weight, used to balance prediction accuracy and the strength of the upper capacity constraint.