A long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning
Through the dual-branch space-time comparison learning method, combined with dynamic data and static service capabilities, the problem of difficulty in detecting long-term traffic abnormalities in the existing technology is solved, and accurate detection of long-term traffic abnormalities and improved traffic efficiency is achieved.
Patent Information
- Application Number
- CN202411043780.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-07-31
AI Technical Summary
Existing traffic anomaly detection methods are difficult to effectively detect long-term traffic anomalies, especially in urban environments where dynamic data and static service capabilities are complex.
Using a method based on dual-branch spatiotemporal comparison learning, the first branch of the pre-trained detection model obtains global dynamic spatiotemporal dependency information, and the second branch obtains static area spatiotemporal dependency information, and combines this information to calculate the anomaly scores of each node to detect long-term traffic anomalies.
This method can combine the spatiotemporal heterogeneity of dynamic data and the static service capabilities of nodes to accurately detect long-term traffic anomalies, improve traffic mobility and road utilization efficiency, and reduce traffic congestion and abnormalities.
Smart Images

Figure CN119007436B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of traffic detection, and in particular to a long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning. Background Art
[0002] In recent years, the increase of urban traffic anomalies has led to frequent traffic congestion and accidents, affecting traffic efficiency and public safety. Therefore, traffic anomaly detection plays a vital role in intelligent traffic management, such as adjusting signal timing and re-planning traffic routes in advance. Urban traffic anomalies can be divided into two categories: (i) short-term anomalies, which are usually caused by emergencies, such as traffic accidents and special social activities, and (ii) long-term anomalies, such as long-term traffic congestion, which is caused by the long-term mismatch of expected traffic services caused by changes in traffic structure and urban layout development. For example, the traffic demand in the area where a newly built shopping mall is located has increased dramatically. However, the existing public transportation routes have not been adjusted to adapt to this change, and the traffic signal system at the intersection cannot meet the current demand, resulting in insufficient bus services and long-term traffic congestion. Therefore, detecting long-term traffic anomalies can significantly improve traffic mobility and road utilization efficiency, and fundamentally reduce traffic congestion and anomalies. Various data-driven and time series-based anomaly detection methods have been developed in the past for short-term non-recurrent traffic anomalies, such as traffic congestion and accidents. However, these methods are difficult to use in long-term anomaly detection due to the following problems.
[0003] On the technical level, the patterns of long-term traffic anomalies are diverse because they are caused by different types of changes in urban context information, such as unbalanced bus services or sudden increases in population in certain areas. Therefore, the model needs to learn the static service capacity of regions / road segments based on multiple factors. On the other hand, it needs to learn dynamic data-driven spatiotemporal heterogeneity based on adaptive and self-supervised learning. Then, how to detect the contrasting differences between static associations and dynamic self-learned spatiotemporal dependencies is a unique challenge in detecting long-term traffic anomalies. Summary of the invention
[0004] The purpose of the present invention includes, for example, providing a long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning, which can accurately detect abnormal long-term traffic flow in combination with the spatiotemporal heterogeneity of dynamic data and the static services of nodes.
[0005] The embodiments of the present invention can be implemented as follows:
[0006] In a first aspect, the present invention provides a long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning, the method comprising:
[0007] Obtaining a plurality of views based on the traffic network to be detected, each of the views comprising a plurality of nodes;
[0008] For each of the views, obtain the traffic signal of each of the nodes in the view, and obtain an adjacency matrix between the nodes;
[0009] Based on the first branch of the pre-trained detection model, global dynamic spatiotemporal dependency information is obtained according to the traffic signals of each of the nodes;
[0010] Based on the second branch of the detection model, and according to the traffic signal of each node and the adjacency matrix between nodes, the static regional spatiotemporal dependency information is obtained;
[0011] Based on the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information, an anomaly score corresponding to each of the nodes is obtained, and the anomaly score indicates whether there is a long-term traffic anomaly at the node.
[0012] In an optional implementation, the step of obtaining the traffic signal of each of the nodes in the view includes:
[0013] Obtaining multidimensional traffic information of a plurality of nodes in the view at a plurality of consecutive time steps;
[0014] Dividing the traffic information into a plurality of spatiotemporal blocks that are continuous and non-overlapping on a time axis based on the time step;
[0015] The traffic information of each of the nodes in each of the time-space blocks is obtained as the traffic signal of the corresponding node.
[0016] In an optional embodiment, the first branch includes a temporal self-attention encoder, a clustering layer, and a spatial self-attention encoder connected in sequence;
[0017] The step of obtaining global dynamic spatiotemporal dependency information based on the first branch of the pre-trained detection model and the traffic signals of each node comprises:
[0018] Using the temporal self-attention encoder in the first branch of the pre-trained detection model, the traffic signal of each node is processed to output the temporal self-attention output information;
[0019] Using the clustering layer in the first branch to cluster multiple nodes to obtain multiple clusters;
[0020] For each of the clusters, the temporal self-attention output information of each node in each of the clusters is input into the spatial self-attention encoder in the first branch for processing, and the temporal and spatial self-attention output information of each of the nodes is output;
[0021] Based on the spatiotemporal self-attention output information of each of the nodes, the global dynamic spatiotemporal dependency information of each of the nodes is obtained.
[0022] In an optional embodiment, the temporal self-attention encoder includes a plurality of attention heads;
[0023] The step of processing the traffic signal of each node using the temporal self-attention encoder in the first branch of the pre-trained detection model and outputting the temporal self-attention output information comprises:
[0024] Using each attention head in the temporal self-attention encoder to process the traffic signal of the node in parallel, respectively obtaining a query matrix, a key matrix and a value matrix corresponding to the traffic signal;
[0025] The query matrix, key matrix and value matrix are multiplied and then scaled to output the temporal self-attention output information.
[0026] In an optional implementation, the step of obtaining global dynamic spatiotemporal dependency information based on the spatiotemporal self-attention output information includes:
[0027] Normalizing the spatiotemporal self-attention output information;
[0028] The normalized spatiotemporal self-attention output information is processed using a multi-level structure containing residual connections to obtain global dynamic spatiotemporal dependency information.
[0029] In an optional implementation, the second branch is a graph convolutional network model;
[0030] The step of obtaining the spatiotemporal dependency information of the static area based on the second branch of the detection model and according to the traffic signal of each node and the adjacency matrix between nodes includes:
[0031] Based on the second branch of the detection model, the region adaptive spatial relationship information is calculated according to the adjacency matrix between the nodes;
[0032] Based on the regional adaptive spatial relationship information and the traffic signals of each of the nodes, a multi-view graph matrix under multiple views is obtained;
[0033] The multi-view graph matrix is fused with the weight matrix of the graph convolution in the second branch to obtain the spatiotemporal dependency information of the static area.
[0034] In an optional implementation, the step of obtaining a multi-view graph matrix under multiple views based on the regional adaptive spatial relationship information and the traffic signal of each of the nodes includes:
[0035] Based on the regional adaptive spatial relationship information, the traffic signal of each node, and the weight matrix of the graph convolution in the second branch, the static representation information of the node in each view is obtained by using an activation function calculation;
[0036] The static representation information under multiple views is combined to obtain a multi-view image matrix under multiple views.
[0037] In an optional implementation, the step of obtaining an anomaly score corresponding to each of the nodes based on the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information includes:
[0038] Fusing the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information to obtain fused information;
[0039] Restoring the dimension of the fused information to the original dimension of the traffic signal of each node;
[0040] The abnormality score corresponding to each of the nodes is obtained based on the restored fusion information.
[0041] In an optional implementation, the detection model is pre-trained based on training samples and under the guidance of a loss function;
[0042] The loss function is obtained by accumulating the contrast heterogeneity loss function, the dual-stream contrast loss function and the reconstruction loss function according to different weights.
[0043] In an optional embodiment, the comparative heterogeneity loss function is used to characterize the excellence of clustering results when multiple nodes are clustered;
[0044] The dual-stream contrast loss function is used to characterize the difference between the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information;
[0045] The reconstruction loss function is used to characterize the reconstruction accuracy during the encoding process and the decoding process of the detection model.
[0046] The beneficial effects of the embodiments of the present invention include, for example:
[0047] The present application provides a long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning, and multiple views are obtained based on the traffic network to be detected, and each view includes multiple nodes. For each view, the traffic signal of each node in the view and the adjacency matrix between the nodes are obtained. Based on the first branch of the detection model obtained by pre-training, the global dynamic spatiotemporal dependency information is obtained according to the traffic signal of each node, and based on the second branch of the detection model, the static regional spatiotemporal dependency information is obtained according to the traffic signal of each node and the adjacency matrix between the nodes. Finally, based on the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information, the anomaly score of each node is obtained to characterize whether there is a long-term traffic anomaly. This scheme can combine the spatiotemporal heterogeneity of dynamic data and the static service of nodes to perform long-term traffic anomaly detection, and accurately detect abnormal long-term traffic flow. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0049] Figure 1 A flowchart of a long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning provided in an embodiment of the present application;
[0050] Figure 2 for Figure 1 A flowchart of the sub-steps included in S12;
[0051] Figure 3 for Figure 1 A flowchart of the sub-steps included in S13;
[0052] Figure 4 for Figure 1 A flowchart of the sub-steps included in S14;
[0053] Figure 5 for Figure 1 Flowchart of the sub-steps included in S15. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0055] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0056] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0057] In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear to indicate an orientation or position relationship, they are based on the orientation or position relationship shown in the accompanying drawings, or are the orientation or position relationship in which the product of the invention is usually placed when used. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0058] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.
[0059] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.
[0060] Figure 1 The flowchart of the long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning provided by the embodiment of the present application is shown. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning can be implemented by a detection device, which can be implemented by software and / or hardware and can be configured in an electronic device, which can be a computer device. The detailed steps of the long-term traffic anomaly detection method are introduced as follows.
[0061] S11, obtaining a plurality of views based on the traffic network to be detected, each of the views including a plurality of nodes.
[0062] S12, for each of the views, obtaining the traffic signal of each of the nodes in the view, and obtaining an adjacency matrix between the nodes.
[0063] S13, based on the first branch of the pre-trained detection model, and according to the traffic signals of each of the nodes, obtaining global dynamic spatiotemporal dependency information.
[0064] S14, based on the second branch of the detection model and according to the traffic signal of each node and the adjacency matrix between nodes, obtaining static regional spatiotemporal dependency information.
[0065] S15, based on the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information, obtaining an anomaly score corresponding to each of the nodes, wherein the anomaly score indicates whether there is a long-term traffic anomaly at the node.
[0066] In this embodiment, the traffic network to be detected can be the traffic network of a certain city, which has multiple nodes. The nodes can be multiple areas divided according to spatial information in the traffic network, or they can be sensors set at different locations. The sensors are used to detect the flow, speed and other information of people and vehicles passing through their locations.
[0067] First, the data in the obtained transportation network is preprocessed. Specifically, multiple different views are constructed based on the transportation network, and each view is used to describe different heterogeneous relationships between nodes. Heterogeneous relationships refer to multiple different types of interactions or connections between nodes to reflect the diversity and complexity of the transportation network.
[0068] In each view, there are multiple nodes, and there are edges between the mutually related nodes, and each edge has a corresponding weight value. The weight value of each edge can be set according to the level of correlation between the nodes at both ends of the edge. The correlation can be distance correlation, functional attribute correlation, etc.
[0069] In this implementation, the multiple views constructed can be represented as Where i represents the edge set between nodes in the i-th view, A i represents the adjacency matrix between nodes in the i-th view, N view Indicates the number of views. The elements in the adjacency matrix represent the connection status between nodes. For example, if there is a direct connection between two nodes, the corresponding matrix element can be 1 (or other values representing the connection, such as weight, distance, capacity, etc.). If there is no direct connection between two nodes, the corresponding matrix element can be 0.
[0070] In this embodiment, the traffic signal of each node in the view can be obtained. The traffic signal can be the flow, speed and other information of the traffic or pedestrian flow in a certain area or at a certain sensor location. The traffic signal is defined as a tensor R N×T×D , represents the D-dimensional traffic signal of N areas in a certain city at T time steps. In this way, the traffic signal of the node at time t can be expressed as X t ∈R N×D , the traffic signal at all time steps of the nth node can be expressed as X (n) ∈R T×D .
[0071] In addition, in this embodiment, a detection model is pre-trained, and the detection model includes a first branch and a second branch. The first branch and the second branch perform tasks in parallel, and some network parameters can be shared between the two branches.
[0072] In this embodiment, based on the first branch of the detection model, global dynamic spatiotemporal dependency information is obtained according to the traffic signals of each node. The global dynamic spatiotemporal dependency information represents the global and long-term spatiotemporal interaction information between nodes in the traffic network.
[0073] In addition, based on the second branch of the detection model, static regional spatiotemporal dependency information is obtained according to the traffic signal of each node and the adjacency matrix between nodes. The static regional spatiotemporal dependency information represents the correspondence between the traffic signal of a node in the traffic network and its expected service level. The expected service level can be obtained based on the service level of other nodes associated with the node, and can be understood as an average service level in the global range obtained through learning and training.
[0074] Finally, the anomaly score corresponding to the node can be obtained by combining the obtained global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information. The anomaly score can reflect whether the node has long-term traffic anomalies. Specifically, an anomaly threshold can be set in advance, and the obtained anomaly score can be compared with the set anomaly threshold. If the anomaly score is greater than the anomaly threshold, it can be determined that the node has long-term traffic anomalies.
[0075] Based on each view, the anomaly score of each node can be obtained. For a certain node, if the anomaly score of the node obtained from any view indicates that it has long-term traffic anomaly, it can be determined that the node has long-term traffic anomaly.
[0076] In order to alleviate the computational complexity brought by the self-attention mechanism, in this embodiment, the traffic signal of each node can be preprocessed. Figure 2 Specifically, the step of obtaining the traffic signal of each node in the view can be implemented in the following way:
[0077] S121, obtaining multi-dimensional traffic information of a plurality of nodes in the view at a plurality of consecutive time steps.
[0078] S122: Divide the traffic information into a plurality of spatiotemporal blocks that are continuous and non-overlapping on a time axis based on the time step.
[0079] S123, obtaining the traffic information of each of the nodes in each of the time-space blocks as the traffic signal of the corresponding node.
[0080] In this embodiment, based on the definition of the traffic signal of the node, the traffic information of the node in the obtained view should be multidimensional traffic information over multiple continuous time steps. Assuming that the time step of the original traffic information is T, the traffic information can be divided into multiple spatiotemporal blocks according to the time step, and the length of each spatiotemporal block is P. In this way, the original input length of T can be reduced to T / P. During subsequent processing, the memory usage and computational complexity of the temporal attention map decrease with the square of the factor P. Under the same training time and GPU memory capacity conditions, the model can effectively and robustly process and learn more long-term traffic signal data.
[0081] On this basis, subsequent processing is performed based on the traffic information obtained for each node. Figure 3 , the step of obtaining global dynamic spatiotemporal dependency information based on the first branch of the detection model and the traffic signals of each node can be implemented in the following ways:
[0082] S131, using the temporal self-attention encoder in the first branch of the pre-trained detection model, the traffic signal of each node is processed to output the temporal self-attention output information.
[0083] S132: clustering the multiple nodes using the clustering layer in the first branch to obtain multiple clusters.
[0084] S133, for each of the clusters, respectively input the temporal self-attention output information of each node in the cluster into the spatial self-attention encoder in the first branch for processing, and output the spatiotemporal self-attention output information of each of the nodes.
[0085] S134, based on the spatiotemporal self-attention output information of each of the nodes, obtain the global dynamic spatiotemporal dependency information of each of the nodes.
[0086] In this embodiment, the first branch of the detection model includes a temporal self-attention encoder, a clustering layer, and a spatial self-attention encoder connected in sequence. In addition, the detection model also includes a convolution layer, a serialization processing layer, and a position encoding layer connected to the front end of the first branch, which can respectively implement convolution operations on the traffic signals of the nodes, convert the traffic signals into a serialized form, obtain the position information of each element in the sequence, and other processing.
[0087] On this basis, the processed traffic signal enters the temporal self-attention encoder, and after being processed by the temporal self-attention encoder, the temporal self-attention output information is output.
[0088] In this embodiment, the temporal self-attention encoder includes multiple attention heads, and the implementation method of the temporal self-attention encoder for processing traffic signals can be as follows:
[0089] The traffic signals of the nodes are processed in parallel by the attention heads in the temporal self-attention encoder to obtain the query matrix, key matrix and value matrix corresponding to the traffic signals respectively; the query matrix, key matrix and value matrix are multiplied and then scaled to output the temporal self-attention output information.
[0090] In this embodiment, the traffic signal of the node is represented as After being processed by each attention head of the self-attention encoder, the traffic signal is converted into a query matrix Key Matrix Sum Matrix Among them, W Q , W K , W V Respectively represent the learned weight matrix. Then the query matrix, key matrix and value matrix are processed by the following formula to obtain the temporal self-attention output information O (n) :
[0091]
[0092] Among them, d k The dimension of the traffic signal representing the node.
[0093] The above formula means that the inner product of the query matrix and the key matrix is first calculated, and then the normalization function softmax is used for processing. The processing result is multiplied by the value matrix to obtain the final temporal self-attention output information O (n) .
[0094] Due to the different functions of various areas in the traffic network, the traffic flow distribution in different areas is very different. This spatial heterogeneity significantly affects the representation quality of traffic signals. Therefore, in order to effectively extract abnormal spatiotemporal patterns in the traffic network, in this embodiment, a clustering layer is designed, through which each area can be mapped to multiple potential representation spaces corresponding to the diverse functions of urban areas.
[0095] In this embodiment, when clustering nodes, multiple cluster centers may be generated first, which may be represented as Among them, C k ∈R T×d , k = 1, 2, ..., K. Traffic signals based on cluster centers and nodes The processed representation) can define the following clustering assignment matrix S:
[0096] S=( <Z (n) ,C k > F ) N×K
[0097] Among them, <,>F means calculating the inner product of two elements.
[0098] In order to measure the quality of the clustering results, this embodiment designs a comparative heterogeneity loss function L when training the detection model. hetero , the contrast heterogeneity loss function can be shown as follows:
[0099]
[0100] Among them, γ represents the temperature parameter, which is used to control the smoothness of the softmax output. Based on the contrast heterogeneity loss function, the clustering between nodes can be continuously optimized.
[0101] After clustering the nodes, multiple clusters can be obtained, each of which includes at least one node.
[0102] Each cluster is imported into the spatial self-attention encoder respectively. In the spatial self-attention encoder, the temporal self-attention output information of each node imported into the same cluster is also processed by multiple attention heads. The processing method is the same as that of the above-mentioned temporal self-attention encoder, and this embodiment will not be repeated here.
[0103] In this embodiment, by clustering nodes with the same passenger flow pattern together for learning, better learning can be achieved.
[0104] The spatiotemporal self-attention output information output by the spatial attention encoder is information with spatiotemporal correlation of nodes.
[0105] In this embodiment, the back end of the first branch of the first detection model also includes a normalization processing layer and a plurality of hierarchical structures including residual connections.
[0106] The spatiotemporal self-attention output information is normalized and processed using a multi-level structure containing residual connections to obtain global dynamic spatiotemporal dependency information.
[0107] In addition, in this embodiment, the detection model also includes a second branch, and the second branch performs processing in parallel with the first branch. The second branch is a graph convolutional network model. Figure 4 , when obtaining the spatiotemporal dependency information of the static region based on the second branch, it can be achieved in the following ways:
[0108] S141, based on the second branch of the detection model, the region adaptive spatial relationship information is calculated according to the adjacency matrix between the nodes.
[0109] S142, obtaining a multi-view graph matrix under multiple views based on the regional adaptive spatial relationship information and the traffic signal of each of the nodes.
[0110] S143, fusing the multi-view graph matrix with the weight matrix of the graph convolution in the second branch to obtain the spatiotemporal dependency information of the static area.
[0111] The second branch in this embodiment can be understood as a static service branch, which aims to learn the correspondence between traffic flow and its expected service level, and relies on prior regional relationships based on distance, connectivity, and functional similarity between nodes. In order to fully capture these spatial dependencies, in this embodiment, the second branch is a scalable multi-view graph convolutional neural network, which is used to learn static spatial dependencies and expected service levels of cities, including a variety of heterogeneous relationships.
[0112] In this embodiment, based on the adjacency matrix A of the nodes in the view, the regional adaptive spatial relationship information is calculated according to the following formula:
[0113]
[0114] Among them, σ represents a learnable parameter, which is used to reflect the sensitivity of the relationship between nodes in the view. The above formula uses scale to convert the dependency relationship represented by the static adjacency matrix into a discrete distribution.
[0115] Based on the above, we use a scalable graph structure and graph convolution to learn traffic flow and expected service level. Based on the traffic signal of each node and the regional adaptive spatial relationship information, a multi-view graph matrix under multiple views is obtained. Specifically, the multi-view graph matrix can be obtained by:
[0116] Based on the regional adaptive spatial relationship information, the traffic signals of each node, the weight matrix of the graph convolution in the second branch, and the activation function calculation, the static representation information of the nodes under each view is obtained; the static representation information under multiple views is combined to obtain a multi-view graph matrix under multiple views.
[0117] In this embodiment, the spatial relationship information can be adaptively determined based on the region. Traffic signal Z of each node, weight matrix W of graph convolution in the second branch (1) and W (2) , and calculate the static representation information according to the following formula:
[0118]
[0119] Where f represents the activation function. The obtained static representation information is combined to obtain the multi-view image matrix
[0120] The obtained multi-view graph matrix is fused with the weight matrix of graph convolution to obtain the spatiotemporal dependency information of static regions.
[0121] In this embodiment, after obtaining the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information respectively through the above methods, refer to Figure 5 , the anomaly score corresponding to each node can be obtained by the following method:
[0122] S151, fusing the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information to obtain fused information.
[0123] S152, restoring the dimension of the fused information to the original dimension of the traffic signal of each node.
[0124] S153, obtaining an abnormality score corresponding to each of the nodes based on the restored fusion information.
[0125] In this embodiment, a gating mechanism may be set at the back end of the first branch and the second branch to achieve the fusion of the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information.
[0126] Since the dimensions of the traffic signals of the nodes of each spatiotemporal block may change relative to the original dimensions after being processed by each level of the detection model, it is necessary to restore the dimensions of the obtained fused information to the original dimensions of the traffic signals. Then, the detection model processes the fused information and outputs the final anomaly score.
[0127] In this embodiment, the detection model is pre-trained based on the training samples and under the guidance of the loss function. The loss function L is obtained by comparing the heterogeneity loss function L hetero , two-stream contrast loss function L dual And the reconstruction loss function L recon Obtained by accumulating different weights. The constructed loss function is as follows:
[0128] L=L recon +αL hetaro +βL dual
[0129] Among them, α and β represent weights, which are used to control the relative importance of the three parts.
[0130] The reconstruction loss function is used to characterize the reconstruction accuracy during the encoding and decoding process of the detection model. Since the detection model is an encoder plus decoder framework, the reconstruction loss function aims to accurately reconstruct non-abnormal data instances, and therefore aims to detect the difference between the real data distribution and the reconstructed data distribution.
[0131] The two-stream contrast loss function is used to characterize the difference between the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information. The two-stream contrast loss function can be constructed based on the Kullback-Leibler divergence (KL divergence) to measure the difference between the dynamic spatiotemporal dependency of adaptive learning and the static service area.
[0132] The contrast heterogeneity loss function is used to characterize the excellence of clustering results when multiple nodes are clustered.
[0133] In this embodiment, based on the detection model obtained through preliminary training, in the actual detection stage, each node in the traffic network to be detected can be detected based on the detection model to determine whether there is long-term traffic anomaly at each node.
[0134] The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning provided in this embodiment is used to detect abnormal long-term traffic flow based on the difference between the traffic flow and the global context and the expected traffic service capacity. On the one hand, a dynamic global context flow is proposed to learn complex and long-term spatiotemporal interactions based on spatiotemporal attention blocks. In order to capture the potential data-driven spatial heterogeneity between regions, a self-supervised contrast clustering method is proposed for clustering between regions. On the other hand, a static service flow is proposed to learn the correspondence between traffic flow and its expected service, which includes a scalable multi-view graph convolutional network and a temporal attention mechanism. In the detection model training process, a loss function composed of three weighted loss functions is used to train a detection model that can accurately detect whether there is a long-term traffic anomaly.
[0135] In summary, the long-term traffic anomaly detection method based on dual-branch spatiotemporal contrast learning provided in the embodiment of the present application obtains multiple views based on the traffic network to be detected, and each view includes multiple nodes. For each view, the traffic signal of each node in the view and the adjacency matrix between the nodes are obtained. Based on the first branch of the detection model obtained by pre-training, the global dynamic spatiotemporal dependency information is obtained according to the traffic signal of each node, and based on the second branch of the detection model, the static regional spatiotemporal dependency information is obtained according to the traffic signal of each node and the adjacency matrix between the nodes. Finally, based on the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information, the anomaly score of each node is obtained to characterize whether there is a long-term traffic anomaly. This scheme can combine the spatiotemporal heterogeneity of dynamic data and the static service of nodes to perform long-term traffic anomaly detection and accurately detect abnormal long-term traffic flows.
[0136] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning, characterized in that: The method comprises: Obtaining a plurality of views based on the traffic network to be detected, each of the views comprising a plurality of nodes; For each of the views, obtain the traffic signal of each of the nodes in the view, and obtain an adjacency matrix between the nodes; Based on the first branch of the pre-trained detection model, global dynamic spatiotemporal dependency information is obtained according to the traffic signals of each of the nodes; Based on the second branch of the detection model, and according to the traffic signal of each node and the adjacency matrix between nodes, the static regional spatiotemporal dependency information is obtained; Based on the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information, obtaining an anomaly score corresponding to each of the nodes, the anomaly score indicating whether the node has a long-term traffic anomaly; The first branch includes a temporal self-attention encoder, a clustering layer, and a spatial self-attention encoder connected in sequence. The first branch of the detection model obtained by pre-training and the step of obtaining global dynamic spatiotemporal dependency information according to the traffic signals of each node include: The temporal self-attention encoder in the first branch of the pre-trained detection model is used to process the traffic signals of each node and output the temporal self-attention output information; the clustering layer in the first branch is used to cluster multiple nodes to obtain multiple cluster clusters; for each cluster cluster, the temporal self-attention output information of each node in each cluster cluster is input into the spatial self-attention encoder in the first branch for processing, and the spatiotemporal self-attention output information of each node is output; based on the spatiotemporal self-attention output information of each node, the global dynamic spatiotemporal dependency information of each node is obtained.
2. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 1 is characterized in that: The step of obtaining the traffic signal of each node in the view includes: Obtaining multidimensional traffic information of a plurality of nodes in the view at a plurality of consecutive time steps; Dividing the traffic information into a plurality of spatiotemporal blocks that are continuous and non-overlapping on a time axis based on the time step; The traffic information of each of the nodes in each of the time-space blocks is obtained as the traffic signal of the corresponding node.
3. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 1 is characterized in that: The temporal self-attention encoder comprises a plurality of attention heads; The step of processing the traffic signal of each node using the temporal self-attention encoder in the first branch of the pre-trained detection model and outputting the temporal self-attention output information comprises: Using each attention head in the temporal self-attention encoder to process the traffic signal of the node in parallel, respectively obtaining a query matrix, a key matrix and a value matrix corresponding to the traffic signal; The query matrix, key matrix and value matrix are multiplied and then scaled to output the temporal self-attention output information.
4. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 1 is characterized in that: The step of obtaining global dynamic spatiotemporal dependency information based on the spatiotemporal self-attention output information comprises: Normalizing the spatiotemporal self-attention output information; The normalized spatiotemporal self-attention output information is processed using a multi-level structure containing residual connections to obtain global dynamic spatiotemporal dependency information.
5. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 1 is characterized in that: The second branch is a graph convolutional network model; The step of obtaining the spatiotemporal dependency information of the static area based on the second branch of the detection model and according to the traffic signal of each node and the adjacency matrix between nodes includes: Based on the second branch of the detection model, the region adaptive spatial relationship information is calculated according to the adjacency matrix between the nodes; Based on the regional adaptive spatial relationship information and the traffic signals of each of the nodes, a multi-view graph matrix under multiple views is obtained; The multi-view graph matrix is fused with the weight matrix of the graph convolution in the second branch to obtain the spatiotemporal dependency information of the static area.
6. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 5 is characterized in that: The step of obtaining a multi-view graph matrix under multiple views based on the regional adaptive spatial relationship information and the traffic signals of each of the nodes comprises: Based on the regional adaptive spatial relationship information, the traffic signal of each node, and the weight matrix of the graph convolution in the second branch, the static representation information of the node in each view is obtained by using an activation function calculation; The static representation information under multiple views is combined to obtain a multi-view image matrix under multiple views.
7. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 1 is characterized in that: The step of obtaining an abnormality score corresponding to each of the nodes based on the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information includes: Fusing the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information to obtain fused information; Restoring the dimension of the fused information to the original dimension of the traffic signal of each node; The abnormality score corresponding to each of the nodes is obtained based on the restored fusion information.
8. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 1 is characterized in that: The detection model is obtained by training in advance based on training samples and under the guidance of a loss function; The loss function is obtained by accumulating the contrast heterogeneity loss function, the dual-stream contrast loss function and the reconstruction loss function according to different weights.
9. The long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning according to claim 8 is characterized in that: The comparative heterogeneity loss function is used to characterize the excellence of clustering results when multiple nodes are clustered; The dual-stream contrast loss function is used to characterize the difference between the global dynamic spatiotemporal dependency information and the static regional spatiotemporal dependency information; The reconstruction loss function is used to characterize the reconstruction accuracy during the encoding process and the decoding process of the detection model.
Citation Information
Patent Citations
Traffic prediction method based on multi-scale space-time fusion graph network
CN115240425A
Traffic flow anomaly detection method based on graph contrast learning network
CN117894168A