A traffic prediction method based on a dual-granularity hierarchical transformer
Patent Information
- Application Number
- CN202511953620.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-23
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2045-12-23
AI Technical Summary
但该类模型存在两大关键缺陷:一是空间层次缺失,将路口与道路段视为同质节点,忽略了路口的全局调控作用与道路段的局部传导功能,无法刻画全局趋势与局部动态的互动关系,导致预测整体模糊、局部失真;二是动态感知不足,采用静态邻接矩阵,无法响应信号配时、突发事故等引发的路网连通性变化,且模型黑箱性强,可解释性不足,难以支撑交通管理部门的决策应用
(1)本发明通过路口-道路段双粒度分层设计,可同时捕捉城市路网的宏观拥堵扩散趋势与道路段的微观流量波动,解决了全局趋势与局部响应难以兼顾的技术难题,大幅提升了预测精度。
Smart Images

Figure CN121564977B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of traffic prediction technology, and in particular to a traffic prediction method based on a dual-granularity hierarchical Transformer. Background Technology
[0002] Urban traffic flow prediction is a core component of intelligent transportation systems, and its prediction accuracy and stability directly impact the effectiveness of higher-level applications such as traffic signal timing, congestion warning, and travel planning. Currently, urban traffic prediction methods are mainly divided into two categories: data-driven models based on fixed sensors and deep prediction models based on single-layer graph neural networks. Both types of methods have significant limitations in practical applications.
[0003] Data-driven models based on fixed sensors are a traditional method of traffic monitoring. They collect vehicle traffic data using devices such as geomagnetic coils and microwave radar, and then combine this data with statistical or linear regression models to make short-term predictions. While these methods offer strong real-time data and low noise, accurately reflecting the condition of local road sections, they suffer from significant drawbacks when applied on a large scale: sensor deployment requires road excavation and pipeline modifications, resulting in long construction periods and high costs; the equipment is susceptible to environmental interference and malfunctions, making maintenance difficult; and the data dimension is limited, only collecting physical quantities such as vehicle speed and traffic flow, failing to obtain crucial information such as road topology and regional functions. In older urban areas and areas with numerous overpasses, data interruptions can easily lead to inaccurate predictions.
[0004] Deep prediction models based on single-layer graph neural networks are currently the mainstream research approach. They abstract road networks into node-edge graph structures and learn traffic dynamic dependencies using graph convolution or spatiotemporal attention mechanisms. Representative models include STGCN, DCRNN, and Graph WaveNet. These models can overcome the limitations of traditional linear modeling in short- to medium-term predictions and capture nonlinear traffic patterns. However, these models have two major drawbacks: First, they lack spatial hierarchy, treating intersections and road segments as homogeneous nodes and ignoring the global control role of intersections and the local transmission function of road segments. This fails to depict the interaction between global trends and local dynamics, leading to overall fuzzy predictions and local distortions. Second, they lack dynamic perception, using static adjacency matrices that cannot respond to changes in road network connectivity caused by signal timing, sudden accidents, etc. Furthermore, the models are highly black-boxed, lack interpretability, and are difficult to support decision-making applications by traffic management departments.
[0005] In summary, existing technologies lack multi-scale structural understanding and cross-layer information fusion capabilities, making it impossible to fully depict the spatiotemporal evolution of traffic flow and meet the prediction needs of complex urban traffic. Summary of the Invention
[0006] The purpose of this invention is to propose a traffic prediction method based on a dual-granularity hierarchical Transformer. By constructing a two-layer structure of intersection and road segment, it achieves collaborative modeling of global and local data. At the same time, relying on the global attention mechanism of Transformer, it ensures the interpretability and prediction stability of the model while capturing long-term dependencies.
[0007] To achieve the above objectives, this invention proposes a traffic prediction method based on a dual-granularity hierarchical Transformer, comprising: Step S1: Use CCTV video capture to perform vehicle detection and multi-target tracking to obtain node-level time-series indicators aggregated by time window; Step S2: Use road topology and historical correlation fusion to construct graph structure, and obtain a two-layer hybrid adjacency matrix and hierarchical mapping; Step S3: Use the dual-granularity hierarchical deep learning model Transformer to learn spatiotemporal representations, obtain the global semantics of the intersection layer and the local semantics of the road segment layer, and construct a joint representation of global guidance and local correction. Step S4: Optimize the model using joint loss and adaptive training strategy to obtain a stable and interpretable multi-step predictor under long horizon. Step S5: Use service-oriented interfaces and visualization to go online and close the loop, and obtain a real-time prediction system that directly drives signal timing and congestion warning.
[0008] Preferably, in step S1, the specific steps are as follows: Step S11: Deploy cameras at intersections and road sections of the selected urban road network, and use unified time synchronization and fixed frame rate for synchronous data collection. Step S12: Use the target detection and tracking algorithm link to generate a structured trajectory record table. And the trajectory is divided into time windows Aggregate metrics such as traffic, average speed, occupancy, and queue length; among them, A unique identifier for the vehicle's trajectory. The timestamps corresponding to the trajectory points. and These are the spatial coordinates of the vehicle in the image or mapped coordinate system. This is an estimate of the vehicle's instantaneous speed at the corresponding moment. Vehicle category labels; Step S13: Establish image quality labels and weight or mask segments with low light, strong reflections, and rain / fog obstruction at night. Combine this with signal logs, weather and holiday labels to complete feature alignment, and finally construct the input tensor. ;in, N The number of road nodes or intersections.T 1 The length of the time window in the time dimension. F The number of feature dimensions for each node at a single time step.
[0009] The preferred formula for calculating flow rate is as follows: ; in, For traffic, This represents the number of vehicles counted within that time window. i The vehicle index is an integer; The formula for average speed is as follows: ; in, For average speed, For the first The instantaneous or estimated speed of a vehicle within a statistical time window; The formula for calculating market share is as follows: ; in, For market share, This refers to the cumulative time a vehicle occupies the detection area within the statistical time window. This represents the total duration of the corresponding statistical time window; The formula for calculating queue length is as follows: ; in, Queue length The vertical position coordinates of the stop line in the image or mapped coordinate system. The coordinates are the longitudinal positions of the vehicles in the queue in the corresponding coordinate system.
[0010] Preferably, in step S2, at the intersection level... With road section layer Establish a physical adjacency matrix And estimate the dynamic relevance adjacency matrix. To form a hybrid adjacency matrix ; through parent-child mapping matrix Each road segment is associated with a parent intersection, and the diffusion operator is calculated to capture multi-order neighborhood propagation; among which... Traffic map at intersection level. For the set of intersection nodes, For the edge set of the intersection layer, This is a road segment level traffic map. For the set of road segment nodes, For the edge set of the road segment layer, The fusion weight coefficient between the physical adjacency matrix and the dynamic related adjacency matrix; The diffusion operator formula is as follows: ; in, The adjacency matrix after multi-order diffusion. K s The maximum order of diffusion, It is the inverse of the degree matrix of the corresponding adjacency matrix. k This is the diffusion order index.
[0011] Preferably, the specific steps of step S2 are as follows: Step S21: Use functional profiling and clustering algorithms to group intersections and obtain cluster sets. With soft allocation weights The cluster key matrix is initialized; feature profiles are constructed based on land attributes, passenger and freight vehicle ratios, signal schemes, and historical peak-valley patterns; functional clustering is performed using the K-means algorithm or GMM algorithm; and the key projection matrix of each cluster is learned or pre-set. And soft allocation is introduced to ensure a smooth transition, as shown in the following formula: and ; in, c For functional cluster indexes; Step S22: Use cluster-specific key attention for temporal modeling to obtain a rhythmic consistency temporal representation of intersections with the same function; in the cluster Calculate the query matrix Key matrix Sum matrix and use Obtain time-attention output; where, This is the input feature matrix of the intersection node in the time dimension. and These are the linear mapping weight matrices between the query and the value, respectively. This is an attention computation function based on scaled dot product. For normalized exponential functions, d Let T be the feature dimension of the attention subspace, and T be the matrix transpose. For nodes i Soft allocation fusion is used to achieve adaptive switching of nodes in different functional subspaces, as shown in the following formula: ; in, For nodes Key vector representation after soft-assignment fusion For nodes The input feature vector corresponding to the current time step; Step S23: Use cluster-gated spatial attention to perform spatial filtering to obtain sparse and high-value spatial interaction weights; assign weights to each pair of nodes. The gating factor is constructed using the following formula: ; in, For nodes With nodes Spatial gating factor between It is a non-linear activation function. For nodes With nodes Correlation characteristics between them For nodes With nodes The time synchronization characteristics between them For nodes With nodes Residual information characteristics between This is a gated bias term; By multiplying the gating factor by the spatial attention and simultaneously incorporating sparsity and rhythm consistency regularization, a synergistic optimization of spatial topology selection and temporal rhythm constraints is achieved, as shown in the following formula: ; , ; in, For nodes For nodes Spatial attention weights, and They are nodes Query vectors and nodes The key vector, This is a regularization term used to constrain spatial attention sparsity. This is a regularization term used to constrain the consistency of node representations within the same functional cluster. For functional cluster indexes, and They are nodes With nodes The hidden state representation at the intersection layer; Step S24: Use residual fusion and layer normalization to perform robust output and obtain the global semantics of the intersection layer. It also completes the prior injection preparation for the lower layer; it fuses the temporal and spatial branches and suppresses high-frequency jitter through second-order temporal difference smoothing, as shown in the following formula: ; ; in, This represents the hidden state of the nodes extracted for the time branch. The hidden state representation of nodes extracted for spatial branching. For layer normalization operation, This is a smoothing regularization term based on the second-order difference of time. This is the predicted output sequence of the model at each time step.
[0012] Preferably, in step S3, at the intersection layer, temporal rhythm alignment of intersections with similar functions is achieved through cluster-specific key attention, and redundant connections are suppressed and the main interaction channel is highlighted through cluster-gated spatial attention, resulting in the output. As a global prior, information is adaptively fused between parent intersections and child road segments at the road segment level through cross-parent spatial gating attention. Local short-term dynamics are extracted by combining diffusing convolution and multi-scale temporal attention. Finally, a dual-scale prior fusion mechanism is used to achieve multi-step prediction output. ;in, The time step length for multi-step prediction. The number of output feature dimensions corresponding to each prediction time step.
[0013] Preferably, the specific steps of step S3 are as follows: Step S31: Initialize road segment nodes using parent-child mapping and feature integration to obtain the road segment input base and traceable upstream and downstream relationships; based on Align the parent-level intersection representation with the historical features of the child-level road segments, simultaneously fill in missing segments, and unify the sampling frequency to form... Adjacency matrix index with boundary; Step S32: Use cross-parent space gated attention to perform global-local fusion to obtain adaptively matched road segment semantics; for road segments Intersection with parent level The calculation is performed using the following formula: ; ; in, For road section In the The hidden state representation after the layer update. For road section In the Hidden state representation of layers, For road section Corresponding parent intersection In the Hidden state representation of layers, For the cross-parent space gating coefficient, This is a local feature mapping function for road segments. This is an element-wise multiplication operation. The learnable weight matrix for the gated mapping; Step S33: Local spatiotemporal refinement is performed using diffuse convolution and multi-scale temporal attention to obtain a representation that is sensitive to both short-term disturbances and periodic patterns; the spatial diffusion effect between road segments is explicitly modeled, and multi-scale window attention is superimposed to take into account both shortwave signal switching and long-period commuting patterns; the explicit modeling formula is as follows: ; in, This is the feature representation of the road segment obtained after multiple levels of diffusion convolution. Ks The maximum order of the diffraction convolution is... For the first The learnable linear mapping weight matrix corresponding to the order diffusion; Step S34: Use dual-scale prior fusion and multi-step decoding to predict the output, and obtain... And the uncertainty interval; inject the intersection layer prior into the decoding end, and combine it with the deep learning inference method MCDropout to generate the confidence interval, as shown in the following formula: ; in, For mapping or broadcasting operators, and These are the learnable linear mapping weight matrices at the decoding end. This represents the hidden state of the road segment layer after spatiotemporal modeling. b This is the bias term for the decoding end.
[0014] Preferably, in step S4, the joint loss function formula is as follows: ; in, For joint loss accuracy, To constrain prediction accuracy, To constrain time smoothing, To ensure the consistency of rhythms among clusters with the same function, To constrain spatial gating sparsity, , , These are the weight parameters.
[0015] Preferably, in step S5, an inference interface is provided externally via REST or gRPC, and input... and Output The confidence interval is used to calculate the green signal adjustment amount and drive the simulation of the induction screen and strategy; the formula for calculating the green signal adjustment amount is as follows: ; in, Enter the time window length for the history. The green signal adjustment amount for signal timing. For a moment The corresponding predicted traffic flow sequence, The traffic threshold that triggers the adjustment of the green signal; The system front-end displays heatmaps, time profiles, and Sankey diagrams of flow direction, providing an interpretable view of attention weights and gating strength; when or probability of congestion Timely triggering of early warnings and recommended measures, while comparing and ,Evaluate and The KPIs are set, and high-biased samples are fed back into the incremental pool for periodic fine-tuning, forming a closed business loop of prediction-execution-evaluation-retraining; among which... The critical flow threshold for triggering a traffic congestion warning. As a relative latency improvement indicator, The average traffic delay under the baseline control strategy, To optimize the average traffic delay under the control strategy, As a relative indicator of improved traffic capacity, To optimize traffic flow under the control strategy, Traffic volume under the baseline control strategy.
[0016] Therefore, this invention proposes a traffic prediction method based on a dual-granularity hierarchical Transformer, which has the following advantages: (1) This invention uses a dual-granularity layered design of intersection-road segment to simultaneously capture the macro-congestion diffusion trend of urban road network and the micro-flow fluctuation of road segment, solving the technical problem that it is difficult to balance global trend and local response, and greatly improving the prediction accuracy.
[0017] (2) Based on the synergistic effect of multiple gating attention mechanisms and dual-scale prior fusion mechanism, this invention effectively suppresses the error accumulation and drift problem in long-term series prediction, and can maintain stable prediction performance even in sudden scenarios such as signal switching and road closure.
[0018] (3) Each attention module in this invention can output an explicit weight distribution, allowing traffic management personnel to intuitively observe the contribution of different spatiotemporal nodes to the prediction results. This provides a quantifiable basis for decision-making such as signal timing and traffic scheduling, and enhances the trustworthiness of the model in practical applications.
[0019] (4) The hierarchical and modular architecture design of this invention enables the model to be easily migrated to traffic networks of different sizes and topologies, and can also be extended to scenarios such as highway traffic prediction and bus route passenger flow scheduling. It can be seamlessly integrated with intelligent traffic management systems and mobility as a service platforms.
[0020] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0021] Figure 1 This is a flowchart of a traffic prediction method based on a dual-granularity hierarchical Transformer according to the present invention; Figure 2 This is a flowchart of the intersection layer functional clustering and spatiotemporal representation learning process in step S2 of this embodiment of the invention. Figure 3 This is a flowchart of the road segment layer cross-layer fusion and local spatiotemporal refinement in step S3 of an embodiment of the present invention. Detailed Implementation
[0022] To make the technical solutions, advantages, and objectives of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below. The described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the described embodiments of the present invention without creative effort are within the protection scope of the present invention.
[0023] Unless otherwise defined, the technical or scientific terms used in this invention shall have the ordinary meaning as understood by one of ordinary skill in the art to which this invention pertains.
[0024] Example like Figure 1 As shown, this invention provides a traffic prediction method based on a dual-granularity hierarchical Transformer, with the following specific steps: Step S1: Perform vehicle detection and multi-target tracking to obtain node-level time-series metrics aggregated by time window. The specific steps are as follows: Step S11: Deploy cameras at intersections and road sections of the selected urban road network, and use unified time synchronization and fixed frame rate for synchronous data collection. Step S12: Use the target detection and tracking algorithm link to generate a structured trajectory record table. And the trajectory is divided into time windows Aggregate metrics such as traffic, average speed, occupancy, and queue length; among them, A unique identifier for the vehicle's trajectory. The timestamps corresponding to the trajectory points. and These are the spatial coordinates of the vehicle in the image or mapped coordinate system. This is an estimate of the vehicle's instantaneous speed at the corresponding moment. Vehicle category labels; The formula for calculating flow rate is as follows: ; in, For traffic, This represents the number of vehicles counted within that time window. i The vehicle index is an integer; The formula for average speed is as follows: ; in, For average speed, For the first The instantaneous or estimated speed of a vehicle within a statistical time window; The formula for calculating market share is as follows: ; in, For market share, This refers to the cumulative time a vehicle occupies the detection area within the statistical time window. This represents the total duration of the corresponding statistical time window; The formula for calculating queue length is as follows: ; in, Queue length The vertical position coordinates of the stop line in the image or mapped coordinate system. The coordinates are the longitudinal positions of the vehicles in the queue in the corresponding coordinate system.
[0025] Step S13: Establish image quality labels and weight or mask segments with low light, strong reflections, and rain / fog obstruction at night. Combine this with signal logs, weather and holiday labels to complete feature alignment, and finally construct the input tensor. ;in, N The number of road nodes or intersections. T 1 The length of the time window in the time dimension. F The number of feature dimensions for each node at a single time step.
[0026] Step S2: Construct a graph structure using the fusion of road topology and historical relevance to obtain a two-layer hybrid adjacency matrix and hierarchical mapping; respectively at the intersection layer. With road section layer Establish a physical adjacency matrix And estimate the dynamic relevance adjacency matrix. To form a hybrid adjacency matrix ; through parent-child mapping matrix Each road segment is associated with a parent intersection, and the diffusion operator is calculated to capture multi-order neighborhood propagation; among which... Traffic map at intersection level. For the set of intersection nodes, For the edge set of the intersection layer, This is a road segment level traffic map. For the set of road segment nodes, For the edge set of the road segment layer, The fusion weight coefficient between the physical adjacency matrix and the dynamic related adjacency matrix; The diffusion operator formula is as follows: ; in, The adjacency matrix after multi-order diffusion. K s The maximum order of diffusion, It is the inverse of the degree matrix of the corresponding adjacency matrix. k This is the diffusion order index.
[0027] like Figure 2 As shown, the specific steps of step S2 are as follows: Step S21: Use functional profiling and clustering algorithms to group intersections and obtain cluster sets. With soft allocation weights The cluster key matrix is initialized; feature profiles are constructed based on land attributes, passenger and freight vehicle ratios, signal schemes, and historical peak-valley patterns; functional clustering is performed using the K-means algorithm or GMM algorithm; and the key projection matrix of each cluster is learned or pre-set. And soft allocation is introduced to ensure a smooth transition, as shown in the following formula: and ; in, c For functional cluster indexes; Step S22: Use cluster-specific key attention for temporal modeling to obtain a rhythmic consistency temporal representation of intersections with the same function; in the cluster Calculate the query matrix Key matrix Sum matrix and use Obtain time-attention output; where, This is the input feature matrix of the intersection node in the time dimension. and These are the linear mapping weight matrices between the query and the value, respectively. This is an attention computation function based on scaled dot product. For normalized exponential functions, d Let T be the feature dimension of the attention subspace, and T be the matrix transpose. For nodes i Soft allocation fusion is used to achieve adaptive switching of nodes in different functional subspaces, as shown in the following formula: ; in, For nodes Key vector representation after soft-assignment fusion For nodes The input feature vector corresponding to the current time step; Step S23: Use cluster-gated spatial attention to perform spatial filtering to obtain sparse and high-value spatial interaction weights; assign weights to each pair of nodes. The gating factor is constructed using the following formula: ; in, For nodes With nodes Spatial gating factor between It is a non-linear activation function. For nodes With nodes Correlation characteristics between them For nodes With nodes The time synchronization characteristics between them For nodes With nodes Residual information characteristics between This is a gated bias term; By multiplying the gating factor by the spatial attention and simultaneously incorporating sparsity and rhythm consistency regularization, a synergistic optimization of spatial topology selection and temporal rhythm constraints is achieved, as shown in the following formula: ; , ; in, For nodes For nodes Spatial attention weights, and They are nodes Query vectors and nodes The key vector, This is a regularization term used to constrain spatial attention sparsity. This is a regularization term used to constrain the consistency of node representations within the same functional cluster. For functional cluster indexes, and They are nodes With nodes The hidden state representation at the intersection layer; Step S24: Use residual fusion and layer normalization to perform robust output and obtain the global semantics of the intersection layer. It also completes the prior injection preparation for the lower layer; it fuses the temporal and spatial branches and suppresses high-frequency jitter through second-order temporal difference smoothing, as shown in the following formula: ; ; in, This represents the hidden state of the nodes extracted for the time branch. The hidden state representation of nodes extracted for spatial branching. For layer normalization operation, This is a smoothing regularization term based on the second-order difference of time. This is the predicted output sequence of the model at each time step.
[0028] Step S3: Use the Transformer deep learning model with dual granularity to learn spatiotemporal representations, obtain the global semantics at the intersection layer and the local semantics at the road segment layer, and construct a joint representation of global guidance and local correction; at the intersection layer, achieve temporal rhythm alignment of intersections with similar functions through clustered specific key attention, suppress redundant connections and highlight the main interaction channel through clustered gated spatial attention, and output... As a global prior, information is adaptively fused between parent intersections and child road segments at the road segment level through cross-parent spatial gating attention. Local short-term dynamics are extracted by combining diffusing convolution and multi-scale temporal attention. Finally, a dual-scale prior fusion mechanism is used to achieve multi-step prediction output. ;in, The time step length for multi-step prediction. The number of output feature dimensions corresponding to each prediction time step.
[0029] like Figure 3 As shown, the specific steps of step S3 are as follows: Step S31: Initialize road segment nodes using parent-child mapping and feature integration to obtain the road segment input base and traceable upstream and downstream relationships; based on Align the parent-level intersection representation with the historical features of the child-level road segments, simultaneously fill in missing segments, and unify the sampling frequency to form... Adjacency matrix index with boundary; Step S32: Use cross-parent space gated attention to perform global-local fusion to obtain adaptively matched road segment semantics; for road segments Intersection with parent level The calculation is performed using the following formula: ; ; in, For road section In the The hidden state representation after the layer update. For road section In the Hidden state representation of layers, For road section Corresponding parent intersection In the Hidden state representation of layers, For the cross-parent space gating coefficient, This is a local feature mapping function for road segments. This is an element-wise multiplication operation. The learnable weight matrix for the gated mapping; Step S33: Local spatiotemporal refinement is performed using diffuse convolution and multi-scale temporal attention to obtain a representation that is sensitive to both short-term disturbances and periodic patterns; the spatial diffusion effect between road segments is explicitly modeled, and multi-scale window attention is superimposed to take into account both shortwave signal switching and long-period commuting patterns; the explicit modeling formula is as follows: ; in, This is the feature representation of the road segment obtained after multiple levels of diffusion convolution. Ks The maximum order of the diffraction convolution is... For the first The learnable linear mapping weight matrix corresponding to the order diffusion; Step S34: Use dual-scale prior fusion and multi-step decoding to predict the output, and obtain... And the uncertainty interval; inject the intersection layer prior into the decoding end, and combine it with the deep learning inference method MCDropout to generate the confidence interval, as shown in the following formula: ; in, For mapping or broadcasting operators, and These are the learnable linear mapping weight matrices at the decoding end. This represents the hidden state of the road segment layer after spatiotemporal modeling. b This is the bias term for the decoding end.
[0030] Step S4: Optimize the model using joint loss and an adaptive training strategy to obtain a stable and interpretable multi-step predictor under long horizon conditions; the joint loss function formula is as follows: ; in, For joint loss accuracy, To constrain prediction accuracy, To constrain time smoothing, To ensure the consistency of rhythms among clusters with the same function, To constrain spatial gating sparsity, , , These are the weight parameters.
[0031] Step S5: Utilize service-oriented interfaces and visualization to implement online and closed-loop systems, resulting in a real-time prediction system that directly drives signal timing and congestion warnings; provide an inference interface externally via REST or gRPC, and input... and Output The confidence interval is used to calculate the green signal adjustment amount and drive the simulation of the induction screen and strategy; the formula for calculating the green signal adjustment amount is as follows: ; in, Enter the time window length for the history. The green signal adjustment amount for signal timing. For a moment The corresponding predicted traffic flow sequence, The traffic threshold that triggers the adjustment of the green signal; The system front-end displays heatmaps, time profiles, and Sankey diagrams of flow direction, providing an interpretable view of attention weights and gating strength; when or probability of congestion Timely triggering of early warnings and recommended measures, while comparing and ,Evaluate and The KPIs are set, and high-biased samples are fed back into the incremental pool for periodic fine-tuning, forming a closed business loop of prediction-execution-evaluation-retraining; among which... The critical flow threshold for triggering a traffic congestion warning. As a relative latency improvement indicator, The average traffic delay under the baseline control strategy, To optimize the average traffic delay under the control strategy, As a relative indicator of improved traffic capacity, To optimize traffic flow under the control strategy, Traffic volume under the baseline control strategy.
[0032] It is worth noting that all contents not described in detail in this invention are existing technologies and are well known to those skilled in the art.
[0033] Therefore, this invention provides a traffic prediction method based on a dual-granularity hierarchical Transformer. Through a dual-granularity hierarchical Transformer architecture of intersections and road segments, and multiple gating attention and dual-scale prior fusion mechanisms, it achieves a comprehensive improvement in traffic prediction in terms of hierarchical modeling capabilities, prediction stability, interpretability, deployment economy, and scenario scalability. It can simultaneously and accurately capture macro-level road network changes and micro-level traffic fluctuations, providing a stable, accurate, and implementable technical solution for intelligent traffic management.
[0034] 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 preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.
Claims
1. A traffic prediction method based on a dual-granularity hierarchical Transformer, characterized in that, The specific steps are as follows: Step S1: Use CCTV video capture to perform vehicle detection and multi-target tracking to obtain node-level time-series indicators aggregated by time window; Step S2: Use road topology and historical correlation fusion to construct graph structure, and obtain a two-layer hybrid adjacency matrix and hierarchical mapping; Step S3: Use the dual-granularity hierarchical deep learning model Transformer to learn spatiotemporal representations, obtain the global semantics of the intersection layer and the local semantics of the road segment layer, and construct a joint representation of global guidance and local correction. Step S4: Optimize the model using joint loss and adaptive training strategies to obtain a multi-step predictor; Step S5: Use service-oriented interfaces and visualization to go online and close the loop, and obtain a real-time prediction system that directly drives signal timing and congestion warning. In step S1, the specific steps are as follows: Step S11: Deploy cameras at intersections and road sections of the selected urban road network, and use unified time synchronization and fixed frame rate for synchronous data collection. Step S12: Use the target detection and tracking algorithm link to generate a structured trajectory record table. And the trajectory is divided into time windows Aggregate metrics such as traffic, average speed, occupancy, and queue length; among them, A unique identifier for the vehicle's trajectory. The timestamps corresponding to the trajectory points. and These are the spatial coordinates of the vehicle in the image or mapped coordinate system. This is an estimate of the vehicle's instantaneous speed at the corresponding moment. Vehicle category labels; Step S13: Establish image quality labels and weight or mask segments with low light, strong reflections, and rain / fog obstruction at night. Combine this with signal logs, weather and holiday labels to complete feature alignment, and finally construct the input tensor. ;in, N The number of road nodes or intersections. T 1 The length of the time window in the time dimension. F The number of feature dimensions for each node at a single time step; In step S2, at the intersection level respectively With road section layer Establish a physical adjacency matrix And estimate the dynamic relevance adjacency matrix. To form a hybrid adjacency matrix ; through parent-child mapping matrix Each road segment is associated with a parent intersection, and the diffusion operator is calculated to capture multi-order neighborhood propagation; among which... Traffic map at intersection level. For the set of intersection nodes, For the edge set of the intersection layer, This is a road segment level traffic map. For the set of road segment nodes, For the edge set of the road segment layer, The fusion weight coefficient between the physical adjacency matrix and the dynamic related adjacency matrix; The diffusion operator formula is as follows: ; in, The adjacency matrix after multi-order diffusion. K s The maximum order of diffusion, It is the inverse of the degree matrix of the corresponding adjacency matrix. k Index of diffusion order; In step S3, at the intersection layer, temporal rhythm alignment of intersections with similar functions is achieved through cluster-specific key attention. Cluster-gated spatial attention is used to suppress redundant connections and highlight the main interaction channel, resulting in the output. As a global prior, information is adaptively fused between parent intersections and child road segments at the road segment level through cross-parent spatial gating attention. Local short-term dynamics are extracted by combining diffusing convolution and multi-scale temporal attention. Finally, a dual-scale prior fusion mechanism is used to achieve multi-step prediction output. ;in, The time step length for multi-step prediction. The number of output feature dimensions corresponding to each prediction time step; In step S4, the joint loss function formula is as follows: ; in, For joint loss accuracy, To constrain prediction accuracy, To constrain time smoothing, To ensure the consistency of rhythms among clusters with the same function, To constrain spatial gating sparsity, , , These are the weight parameters.
2. The traffic prediction method based on a dual-granularity hierarchical Transformer according to claim 1, characterized in that, The formula for calculating flow rate is as follows: ; in, For traffic, This represents the number of vehicles counted within that time window. i The vehicle index is an integer; The formula for average speed is as follows: ; in, For average speed, For the first The instantaneous or estimated speed of a vehicle within a statistical time window; The formula for calculating market share is as follows: ; in, For market share, This refers to the cumulative time a vehicle occupies the detection area within the statistical time window. This represents the total duration of the corresponding statistical time window; The formula for calculating queue length is as follows: ; in, Queue length The vertical position coordinates of the stop line in the image or mapped coordinate system. The coordinates are the longitudinal positions of the vehicles in the queue in the corresponding coordinate system.
3. The traffic prediction method based on a dual-granularity hierarchical Transformer according to claim 2, characterized in that, The specific steps of step S2 are as follows: Step S21: Use functional profiling and clustering algorithms to group intersections and obtain cluster sets. With soft allocation weights The cluster key matrix is initialized; feature profiles are constructed based on land attributes, passenger and freight vehicle ratios, signal schemes, and historical peak-valley patterns; functional clustering is performed using the K-means algorithm or GMM algorithm; and the key projection matrix of each cluster is learned or pre-set. And soft allocation is introduced to ensure a smooth transition, as shown in the following formula: and ; in, c For functional cluster indexes; Step S22: Use cluster-specific key attention for temporal modeling to obtain a rhythmic consistency temporal representation of intersections with the same function; in the cluster Calculate the query matrix Key matrix Sum matrix and use Obtain time-attention output; where, This is the input feature matrix of the intersection node in the time dimension. and These are the linear mapping weight matrices between the query and the value, respectively. This is an attention computation function based on scaled dot product. For normalized exponential functions, d Let T be the feature dimension of the attention subspace, and T be the matrix transpose. For nodes i Soft allocation fusion is used to achieve adaptive switching of nodes in different functional subspaces, as shown in the following formula: ; in, For nodes Key vector representation after soft-assignment fusion For nodes The input feature vector corresponding to the current time step; Step S23: Use cluster-gated spatial attention to perform spatial filtering to obtain sparse and high-value spatial interaction weights; assign weights to each pair of nodes. The gating factor is constructed using the following formula: ; in, For nodes With nodes Spatial gating factor between It is a non-linear activation function. For nodes With nodes Correlation characteristics between them For nodes With nodes The time synchronization characteristics between them For nodes With nodes Residual information characteristics between For gated bias terms, The learnable weight matrix for the gated mapping; By multiplying the gating factor by the spatial attention and simultaneously incorporating sparsity and rhythm consistency regularization, a synergistic optimization of spatial topology selection and temporal rhythm constraints is achieved, as shown in the following formula: ; 、 ; in, For nodes For nodes Spatial attention weights, and They are nodes Query vectors and nodes The key vector, This is a regularization term used to constrain spatial attention sparsity. This is a regularization term used to constrain the consistency of node representations within the same functional cluster. For functional cluster indexes, and They are nodes With nodes The hidden state representation at the intersection layer; Step S24: Use residual fusion and layer normalization to perform robust output and obtain the global semantics of the intersection layer. It also completes the prior injection preparation for the lower layer; it fuses the temporal and spatial branches and suppresses high-frequency jitter through second-order temporal difference smoothing, as shown in the following formula: ; ; in, This represents the hidden state of the nodes extracted for the time branch. The hidden state representation of nodes extracted for spatial branching. For layer normalization operation, This is a smoothing regularization term based on the second-order difference of time. This is the predicted output sequence of the model at each time step.
4. The traffic prediction method based on a dual-granularity hierarchical Transformer according to claim 3, characterized in that, The specific steps of step S3 are as follows: Step S31: Initialize road segment nodes using parent-child mapping and feature integration to obtain the road segment input base and traceable upstream and downstream relationships; based on Align the parent-level intersection representation with the historical features of the child-level road segments, simultaneously fill in missing segments, and unify the sampling frequency to form... Adjacency matrix index with boundary; Step S32: Use cross-parent space gated attention to perform global-local fusion to obtain adaptive road segment semantics; For road sections Intersection with parent level The calculation is performed using the following formula: ; ; in, For road section In the The hidden state representation after the layer update. For road section In the Hidden state representation of layers, For road section Corresponding parent intersection In the Hidden state representation of layers, For the cross-parent space gating coefficient, This is a local feature mapping function for road segments. This is an element-wise multiplication operation; Step S33: Local spatiotemporal refinement is performed using diffuse convolution and multi-scale temporal attention to obtain a representation that is sensitive to both short-term disturbances and periodic patterns; the spatial diffusion effect between road segments is explicitly modeled, and multi-scale window attention is superimposed to take into account both shortwave signal switching and long-period commuting patterns; the explicit modeling formula is as follows: ; in, This is the feature representation of the road segment obtained after multiple levels of diffusion convolution. For the first The learnable linear mapping weight matrix corresponding to the order diffusion; Step S34: Use dual-scale prior fusion and multi-step decoding to predict the output, and obtain... And the uncertainty interval; inject the intersection layer prior into the decoding end, and combine it with the deep learning inference method MCDropout to generate the confidence interval, as shown in the following formula: ; in, For mapping or broadcasting operators, and These are the learnable linear mapping weight matrices at the decoding end. This represents the hidden state of the road segment layer after spatiotemporal modeling. b This is the bias term for the decoding end.
5. The traffic prediction method based on a dual-granularity hierarchical Transformer according to claim 4, characterized in that, In step S5, an inference interface is provided externally via REST or gRPC, and input is performed. and Output The confidence interval is used to calculate the green signal adjustment amount and drive the simulation of the induction screen and strategy; the formula for calculating the green signal adjustment amount is as follows: ; in, Enter the time window length for the history. The green signal adjustment amount for signal timing. For a moment The corresponding predicted traffic flow sequence, The traffic threshold that triggers the adjustment of the green signal; The system front-end displays heatmaps, time profiles, and Sankey diagrams of flow direction, providing an interpretable view of attention weights and gating strength; when or probability of congestion Timely triggering of early warnings and recommended measures, while comparing and ,Evaluate and The KPIs are set, and high-biased samples are fed back into the incremental pool for periodic fine-tuning, forming a closed business loop of prediction-execution-evaluation-retraining; among which... The critical flow threshold for triggering a traffic congestion warning. As a relative latency improvement indicator, The average traffic delay under the baseline control strategy, To optimize the average traffic delay under the control strategy, As a relative indicator of improved traffic capacity, To optimize traffic flow under the control strategy, Traffic volume under the baseline control strategy.
Citation Information
Patent Citations
Space-time Transform traffic flow prediction method based on dynamic correlation
CN116543554A
Vehicle data prediction method based on GRU and differential privacy federated learning
CN119397593A