City traffic detection system, method, medium and electronic device based on bidirectional memory federated learning
By using a bidirectional memory federated learning system, combined with data acquisition, global prediction head update, forward inheritance and contrastive learning modules, the system solves the problems of detection accuracy and real-time performance of urban road status and anomaly detection systems under dynamic heterogeneous features. It achieves personalized model optimization and data privacy protection, and improves detection accuracy and system adaptability.
Patent Information
- Application Number
- CN202411968825.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2044-12-30
AI Technical Summary
Existing urban road condition and anomaly detection systems lack the ability to personalize when faced with dynamic and heterogeneous features, resulting in insufficient detection accuracy and real-time performance, and also posing a risk of data privacy leakage.
A city road status and anomaly detection system based on bidirectional memory federated learning is adopted. Through data acquisition module, global prediction head update module, forward inheritance module and contrastive learning module, personalized model optimization and knowledge transfer are realized. By combining forward memory mechanism and contrastive learning, the adaptability of model to dynamic heterogeneous features and detection accuracy are improved.
It significantly improves the accuracy and real-time performance of abnormal event detection, reduces the risk of data privacy leaks, and enhances the system's monitoring effectiveness and learning efficiency in complex traffic scenarios.
Smart Images

Figure CN119989111B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of federated learning, city road state and anomaly detection, and particularly relates to a city road state and anomaly detection system and method based on bidirectional memory federated learning, a medium and an electronic device. BACKGROUND
[0002] The rapid development of intelligent transportation and smart city makes it a core requirement for current intelligent transportation system optimization to efficiently and accurately monitor city road state, especially to quickly detect abnormal events such as traffic accidents. Road state and anomaly detection systems based on federated learning have gradually emerged and made significant progress in privacy protection. However, such systems still have obvious deficiencies in anomaly detection accuracy. The core problem is that the models of each traffic node are homogeneous, and lack the ability to be individually adjusted according to the dynamic heterogeneous characteristics of the nodes, which cannot meet the needs of dynamic heterogeneous characteristics self-adaptive adjustment of each node.
[0003] For example, at a high-flow intersection, the system needs to improve the accident detection sensitivity through a flow density adaptive adjustment mechanism to more quickly identify traffic accident conditions. At some low-flow road sections, especially at night or intersections with poor lighting, the system needs to enhance the low-speed vehicle dynamic perception sensitivity according to the lighting intensity adaptive adjustment mechanism. In the complex and variable urban traffic environment, the homogeneous model is deficient in detection accuracy and response speed, and it is difficult to achieve rapid response to abnormal events.
[0004] Therefore, for the field, how to provide a detection technology that not only needs to adapt to the global environment, but also makes corresponding adjustments according to the dynamic heterogeneous characteristics of each traffic node, so that it can be individually optimized according to the dynamic heterogeneous characteristics such as flow density characteristics and lighting intensity characteristics of different nodes, to improve the accuracy and real-time performance of the system in anomaly event detection, has become a problem to be solved. SUMMARY
[0005] To effectively solve the problem of homogeneous traffic model of nodes in the prior art, the present application provides a city road state and anomaly detection system and method based on bidirectional memory federated learning, a medium and an electronic device. By using the technical solution of the present application, each traffic node can realize individualized model optimization according to its own flow characteristics and environmental conditions, thereby significantly improving the accuracy and real-time performance of different nodes in anomaly event detection.
[0006] In addition, the application utilizes federated learning technology to realize distributed model training under the premise of ensuring the privacy of public data, avoiding the privacy leakage risk of centralizing all public data to the server. At the same time, through the bidirectional memory mechanism, the application establishes a more efficient knowledge transfer path between the nodes and the server, making the node model update faster and more accurate. In addition, the bidirectional memory strategy designed by the application further optimizes the adaptability of the node traffic model to dynamic traffic data, which can significantly reduce the burden of the central server and improve the monitoring effect of the system in high-frequency and complex traffic scenarios.
[0007] The application adopts the following technical solutions:
[0008] A city traffic detection system based on bidirectional memory federated learning, comprising the following modules:
[0009] Data acquisition module: This module is deployed at each node of the urban road, responsible for real-time data acquisition from the equipment of each road section, and converts the original data into prototype representation vectors through the extractor, and then uploads these vectors to the city room server.
[0010] Global prediction head update module: This module is located in the city room server, responsible for receiving mean prototype representation vectors uploaded from each road node, and based on these uploaded prototype representation vectors, the module optimizes and updates the global prediction head, generating a new global prediction head model to provide global guidance for subsequent node training.
[0011] Forward inheritance module: This module is deployed at each node of the urban road, and maintains a super network model inside, which is used to store and transmit information in the historical training process. The super network model stacks all local prediction heads generated by the road node in the previous training rounds, thereby integrating the historical learning experience of the node. These stacked historical information provides a basis for generating the intermediate prediction head in the current round, so that the model can fully utilize past knowledge when performing current training, improving learning efficiency and prediction accuracy. Through the forward memory mechanism, the model can dynamically absorb and utilize historical experience, thereby avoiding dependence on outdated information and enhancing the model's time sequence and continuity. In the task of road traffic state and anomaly detection, the forward memory mechanism effectively improves the model's generalization ability in different environments, significantly improving the accuracy and robustness of prediction.
[0012] The contrastive learning module, deployed at various nodes of urban roads, aims to achieve knowledge transfer between the global prediction head and intermediate prediction heads. Working in conjunction with the forward inheritance module, it implements a bidirectional memory mechanism. Specifically, through contrastive learning, this module calculates the contrastive loss between the global prediction head and the intermediate prediction heads generated by the forward inheritance module, and constructs a joint loss function by combining it with supervised learning loss. If the joint loss is less than a threshold, training is complete, resulting in a personalized anomaly detection model for local dynamic heterogeneous features. Local real-time road data is input into this model to obtain the local real-time road detection status. During training, the global prediction head represents the model's understanding and generalization ability of global data, while the intermediate prediction heads carry the knowledge accumulated during the historical training of that road node. Through contrastive learning, the model promotes consistency between the two in the feature space, ensuring that they can share valuable information in similar tasks or environments. This contrastive optimization process not only strengthens knowledge transfer but also improves the model's personalized adaptability through loss function optimization, enabling the local model to better meet the needs of dynamic heterogeneous features.
[0013] The combination of the contrastive learning module and the forward inheritance module constitutes the system's bidirectional memory mechanism. In the forward inheritance module, historical information is stacked into the intermediate prediction head through a hypernetwork, while in the contrastive learning module, the comparison between the global prediction head and the intermediate prediction heads further enhances the transfer and updating of knowledge. Working together, these two modules enable each road node's local prediction head to better integrate the global perspective and historical experience, significantly improving the model's accuracy and robustness in road condition and anomaly detection tasks.
[0014] Preferably, the data acquisition module is used to extract the prototype representation vector, as follows:
[0015] In the detection system, N road nodes are set as C = {C1, C2, C3, ...} … C N} represents the local dataset of each road node as set D = {D1, D2, D3, ... … D N} represents, where N represents a natural number greater than zero, and C i Let D represent the i-th road node. i This indicates the corresponding local dataset.
[0016] For any road node C i In other words, such as Figure 2 As shown in step ①, its local dataset D i Extracted as a prototype representation vector R by the local extractor. i Specifically, node C i A sample image (class y) will be extracted as the corresponding prototype representation vector where y is the picture label category, m is the index of the picture sample in category y, 0≤m<|M|, |M| represents the number of pictures of category y in the road node C i These prototype representation vectors condense the feature information of each category of samples, which is extracted from the local data set by the local extractor, and finally forms a prototype representation vector that can represent the category features.
[0017] Next, for category y, the mean prototype representation vector This mean prototype representation vector can be regarded as the overall feature representation of category y in the local data set of the node C i
[0018]
[0019] Finally, as shown in step ② of Figure 2 , the node C i will calculate and report the mean prototype representation vector set of all categories, denoted as where Y is the set of all categories in the local data set D i of the node C i , which contains the mean prototype representation vector of all categories in D i , which is used for subsequent training of the server-side global prediction head.
[0020] Preferably, the global prediction head update module is used for training the server global prediction head, as follows:
[0021] After the server collects the mean prototype representation vector set uploaded by each road node , these mean prototype representation vectors form a small training sample, which is used to update the global prediction head to learn the global knowledge throughout the nodes. The following A1-A3 are specific processes:
[0022] A1, collect mean prototype representation vectors:
[0023] The mean prototype representation vector is the overall feature representation of category y in the local data of the road node C i , which can comprehensively summarize the dynamic heterogeneous features of category y in the local data set of C i . For traffic density, lighting intensity and other characteristics in the road node, the mean prototype representation vector can condense the dynamic heterogeneous features of category y in the local data set of C i The core features of the local dataset reveal the distribution of these features in space and time. Each node reports the mean prototype representation vector, effectively transmitting dynamic heterogeneous features to the server. On the one hand, this transmission method reduces the communication overhead caused by uploading raw data; on the other hand, it provides key support for the server to integrate different node characteristics and train the global prediction head.
[0024] A2, Constructing a small training sample:
[0025] The server receives the mean prototype representation vector reported by the node , and integrates these vectors and their corresponding class labels y into a small training sample set. Each mean prototype representation vector condenses the core characteristics of data of a specific class on the road node, such as the peak trend of traffic density or the specific distribution pattern under lighting conditions. This small training sample not only retains the global heterogeneous information across nodes, but also significantly reduces the communication cost. At the same time, the diverse dynamic heterogeneous features in the set provide a rich source of information for the optimization of the global prediction head, enabling it to capture complex and variable traffic patterns between different nodes.
[0026] The construction of this small training sample embodies the collaborative expression of dynamic heterogeneous features, which is both lightweight and diverse. In the training process of the global prediction head, the small training sample set acts as a bridge, providing the server model with distributed knowledge across nodes to improve the generalization ability and adaptability of the global prediction head in complex traffic scenarios.
[0027] A3, Training of the global prediction head:
[0028] Finally, as shown in step ③ of Figure 2 , the server optimizes and trains the global prediction head using the constructed small training sample set. The global prediction head aims to extract common features across road nodes to improve the model's generalization ability and adaptability to diverse traffic scenarios. During the training process, the server uses the cross-entropy loss function to iteratively optimize the global prediction head through the correspondence between the mean prototype representation vector and its class label y.
[0029] The server inputs the small training sample into the global prediction head, predicts the class probability distribution through the global prediction head, and compares it with the actual class label. The error is calculated and the parameters are updated through backpropagation. In this process, the global prediction head gradually captures the consistency of feature distribution across nodes. For example, in nodes with high traffic density, the feature distribution may tend to exhibit high dynamic changes, while in nodes with low traffic, it may exhibit stable patterns. Through learning of these dynamic heterogeneous features, the global prediction head can construct a global model that integrates features of various road nodes.
[0030] Preferably, a forward inheritance module is used for the generation of the intermediate prediction head, as follows:
[0031] As Figure 2 shown in step 4, the generation of the intermediate prediction head is achieved through the hypernetwork structure in the forward inheritance module. The main goal of the forward inheritance module is to generate the intermediate prediction head of the current round using historical model parameters, thereby effectively integrating historical information and enhancing the adaptability to dynamic heterogeneous traffic data.
[0032] To clearly describe the process of generating the intermediate prediction head, it is divided into the following B1-B3 stages:
[0033] B1, Hypernetwork input stage:
[0034] The input of the hypernetwork structure includes the local prediction head of the node in the previous round and the earlier historical prediction head parameters:
[0035]
[0036] where HN represents the hypernetwork function, and the stacked historical parameter vector is the only input source. These historical parameters carry the knowledge of previous rounds, and the hypernetwork generates the intermediate prediction head of the current round by analyzing the feature distribution. The stacked historical parameters not only improve the depth of forward memory, but also enhance the ability to capture long-term dynamic features.
[0037] In each round, the local prediction head parameters are stored and added to the historical record, updated as:
[0038]
[0039] where is the node C i in the historical parameter stacking set in the t-th round. The hypernetwork takes the stacking set as input and dynamically adjusts the weights to generate new intermediate prediction head parameters.
[0040] B2, Intermediate prediction head generation stage:
[0041] After obtaining the historical parameter stacking , the hypernetwork generates the intermediate prediction head
[0042] The hypernetwork first encodes the stacked historical parameters and extracts high-order features through a multi-layer perceptron (MLP):
[0043]
[0044] where Z i is the extracted high-order feature representation, capturing both global and local characteristics of historical parameters.
[0045] The super-network then generates the intermediate prediction head based on the high-order feature Z i Dynamic allocation of importance weights for historical parameters:
[0046] ω j = Softamx(WZ i +b), j ∈ {0, 1, …, t-1}
[0047] where ω j is the weight assigned to the j-th round of historical parameters, and W and b are the learnable parameters of the super-network. The Softmax function ensures weight normalization, such that ∑ω j = 1.
[0048] Finally, the super-network generates the intermediate prediction head by weighted sum of historical parameters with dynamic weights:
[0049]
[0050] This stage ensures that the generated intermediate prediction head can integrate historical information and adapt to current data characteristics according to dynamic weight distribution.
[0051] B3, forward memory and dynamic adjustment stage:
[0052] To enhance the model's adaptability to dynamic characteristics, the forward inheritance module further introduces a smoothing adjustment mechanism to balance the influence of historical and current parameters when generating the intermediate prediction head.
[0053]
[0054] where α is the smoothing coefficient, used to control the influence of historical parameters in the current round. Typically, α can be determined through linear decay or dynamic adjustment strategies based on data characteristics.
[0055] The dynamic adjustment feature of the forward memory mechanism enables the model to adapt flexibly to data heterogeneity in time and space. For example, in high-peak traffic surges or low-peak stable patterns, the importance distribution of historical parameters will adjust with data changes, thereby improving the prediction head's individualized adaptability to different traffic nodes.
[0056] Preferably, the contrastive learning module is used for updating the local prediction head, as follows:
[0057] For example, Figure 2The local prediction head update of the traffic node is implemented by a contrast learning module on the basis of the foregoing steps, as shown in step 5. The core goal of the contrast learning module is to migrate global knowledge into the local prediction head while retaining the characteristics of the local data, thereby improving the prediction performance and generalization ability of the model. The process of the local prediction head update will be described in detail in the following two steps (C1-C2):
[0058] C1, positive and negative sample selection
[0059] In contrast learning, the selection of positive and negative samples directly determines the effect of knowledge migration. In order to effectively realize the migration and integration of the global prediction head knowledge, the system of the present application pays attention to the following three key points in the design of positive and negative samples: globality, history and difference. The specific selection method is as follows:
[0060] The positive sample is the global prediction head parameter θ t of the current round, which is based on the following two considerations. First, the global prediction head θ t is trained by the mean prototype representation vector uploaded by all road nodes, which contains dynamic heterogeneous features and shared knowledge of different nodes, helping the local prediction head to calibrate and absorb global knowledge. Second, by taking the global prediction head as the positive sample, the local prediction head can integrate global shared information while being personalized, thereby improving the generalization ability of the model in a heterogeneous data scenario.
[0061] The negative sample is the local prediction head parameter θ of the road node itself in the last round, which emphasizes history and difference. The local prediction head is the final result of the local model in the last round, which completely retains the characteristics and historical information of the local data. By introducing the negative sample, the model can be prevented from over-relying on historical characteristics in optimization, avoiding falling into a local optimal solution. At the same time, the difference between the negative sample and the positive sample can provide a clear optimization direction for the contrast loss, i.e., to pull apart the distance between the current prediction head and the historical prediction head, prevent the model from overfitting to the historical data, and enhance the absorption ability of global knowledge.
[0062] C2, contrast learning loss and local prediction head update
[0063] The basic framework of contrast learning is shown in Figure 3 , and the key is to define a reasonable loss function to quantify the similarity and difference between model parameters. Following the idea of minimizing the objective function δ(I + ,I a ) and maximizing the objective function δ(I - ,I a ), the contrast loss function l con is defined as follows:
[0064]
[0065] wherein: sim(·,·) represents a similarity function, usually cosine similarity, τ is a temperature coefficient, used to adjust the sensitivity of similarity.
[0066] The optimization goal of the loss function is to maximize the similarity between the local prediction head and the global prediction head, and to minimize the similarity with the historical prediction head, so as to realize the effective transfer of knowledge.
[0067] In the optimization process of the local prediction head, in addition to the contrast learning loss e con , the supervised learning loss e sup of the local data also needs to be considered, and the total loss function is:
[0068] e=μ*e con +(1-μ)*l sup
[0069] Wherein, μ is a balance coefficient, used to adjust the weight of contrast learning and supervised learning in the total loss.
[0070] After calculating the total loss, the local prediction head parameters are updated by the back propagation algorithm:
[0071]
[0072] Wherein, η is the learning rate, controlling the parameter update step. Through the balance of contrast learning loss and supervised learning loss, the road node can learn global knowledge and local characteristics at the same time, so as to optimize the individualization performance and generalization ability of the model.
[0073] The application also discloses a city traffic detection method based on bidirectional memory federal learning, which is used for executing the above system, and comprises the following steps:
[0074] S1, real-time collection of road original data, and conversion of the original data into prototype representation vectors, and uploading of the prototype representation vectors to a server;
[0075] S2, the server collects the uploaded mean prototype representation vectors, trains by using a global prediction head, optimizes and updates, and generates a new global prediction head;
[0076] S3, the super network stacks all the local prediction heads generated by the road nodes in the previous training rounds to generate an intermediate prediction head in the current round; in this step, each terminal stacks the historical local prediction heads by the super network combined with the forward inheritance mechanism to generate the intermediate prediction head.
[0077] S4, utilizing the contrast learning, calculating the contrast loss between the global prediction head and the intermediate prediction head generated by the forward inheritance module, combining the supervised learning loss to construct a joint loss, if the joint loss is greater than or equal to a threshold value, then generating the local prediction head, and at the same time stacking the local prediction head to the super network, returning to step S1; if the joint loss is less than the threshold value, then the training is completed, obtaining the individualized anomaly detection model for the local dynamic heterogeneous features, inputting the local real-time road data into the model to obtain the local real-time road detection state. In this step, the terminal device performs knowledge transfer on the intermediate prediction head and the global prediction head through the contrast learning, optimizes and generates the local prediction head, and at the same time stacks the local prediction head to the super network, realizing the bidirectional memory mechanism.
[0078] The application further discloses a storage medium storing computer instructions for causing a computer to execute the system or the method.
[0079] The application further discloses an electronic device comprising:
[0080] a processor;
[0081] a memory for storing a program, when the program is called and executed by the processor, causing the processor to execute the system or the method.
[0082] The urban traffic detection system and method based on the bidirectional memory federated learning provided by the application have the following significant advantages compared with the existing centralized system:
[0083] 1. Data privacy protection: the application adopts a distributed training architecture, ensures that the traffic data of each intersection is always processed locally, avoids the possible privacy leakage problem in the transmission and storage process of data from the source, and provides strong protection for user data security.
[0084] 2. Improve detection accuracy: through the introduction of the bidirectional memory technology, the application realizes the organic combination of the local model and the global model in the optimization training, not only inherits the generalization ability of the global model, but also adjusts the dynamic heterogeneous characteristics of each intersection, thereby significantly improving the detection accuracy of the road state and the abnormal event. As shown in the figure, Figure 4 the application reaches the 0.62 accuracy rate that the traditional federated average algorithm can reach after 100 rounds of training only after 21 rounds of training, the convergence speed is improved by 4.76 times, and the learning efficiency and detection ability of the system are significantly enhanced.
[0085] 3. Improved real-time performance: The invention separates local training from global model updating, enabling efficient processing and rapid response to massive real-time traffic data while protecting data privacy. This architecture ensures that the system can quickly adapt to dynamic traffic changes and output high-quality state monitoring and anomaly detection results in a timely manner, significantly enhancing the system's real-time performance and resilience.
[0086] 4. System adaptability and scalability: The invention can flexibly select and adapt extractor models according to the computing power configuration of different intersections, and perform adaptive optimization and adjustment based on the dynamic heterogeneous characteristics of each intersection (such as traffic density, lighting intensity, etc.). This personalized adaptation capability for dynamic heterogeneous characteristics enables the system to efficiently operate in complex and variable urban traffic environments, not only meeting diverse needs but also having good deployment and expansion capabilities, further improving the system's robustness and adaptability. BRIEF DESCRIPTION OF DRAWINGS
[0087] Figure 1 A flowchart of a road state and anomaly detection system processing method based on bidirectional memory federated learning for a preferred embodiment of the invention;
[0088] Figure 2 A schematic diagram of the overall flow of a bidirectional memory federated learning method for a preferred embodiment of the invention;
[0089] Figure 3 A schematic diagram of local prediction head loss calculation for a comparative learning module update;
[0090] Figure 4 An experimental comparison chart of the existing federated averaging method and the method proposed in the invention. DETAILED DESCRIPTION
[0091] The preferred embodiment of the invention will be described in detail below.
[0092] The invention solves the problem of node model homogenization in existing systems through a bidirectional memory federated learning framework, fully utilizing node computing resources to achieve efficient fusion of local knowledge and global knowledge in a dynamic heterogeneous environment.
[0093] To better understand the system of the invention, first, the bidirectional memory federated learning method proposed in the invention will be described in detail, and its specific training process is as follows:
[0094]
[0095]
[0096] Among them, represents node C i The intermediate prediction head generated at the tth round, HN represents the super network structure, lsup a loss representing a supervised task, e con a loss representing a contrastive learning task, and η represents a learning rate.
[0097] The application will be described in more detail below with reference to the drawings, which are presented for the purpose of illustration only and are not intended to limit the scope of the application.
[0098] First, briefly outline the workflow of the system of the application, the system of the application solves the problem of road node model homogenization by constructing a framework based on a bidirectional memory federated learning method. The system of the application is composed of multiple modules in cooperation, including a data acquisition module, a forward inheritance module, a contrastive learning module and a global prediction head updating module. In each round of training, the data acquisition module is responsible for extracting local road data of each node and generating prototype representation vectors, and simultaneously calculating mean prototype representation vectors of each category and reporting to the server. The server side uses the uploaded mean prototype representation vectors to train and update the global prediction head through the global prediction head updating module. At the same time, the node side forward inheritance module generates an intermediate prediction head through a hypernetwork structure, which enters the contrastive learning module for optimization and generates a local prediction head, and finally the local prediction head is stacked to the hypernetwork structure, completing a round of training. Among them, the contrastive learning module promotes the knowledge transfer between the global prediction head and the intermediate prediction head through the contrastive learning method, thereby optimizing the local prediction head, and finally generating a personalized anomaly detection model for local dynamic heterogeneous features. The local real-time road data is input into the model to obtain the local real-time road detection state.
[0099] According to the preferred embodiment of the application, as Figure 1 shown, the steps of updating the local prediction head in each round of bidirectional memory federated learning of the system are as follows: data acquisition module, global prediction head updating module, forward inheritance module, contrastive learning module. The following will be combined with the workflow of Figure 1 , introduce in detail the implementation process of each round of bidirectional memory federated learning method from the four steps, and describe the embodiment of the city traffic detection system based on bidirectional memory federated learning.
[0100] I. Extract prototype representation vectors (data acquisition module):
[0101] In the detection system, N road nodes are represented by a set C = {C1, C2, C3, …, C N}, and the local data set of each road node is represented by a set D = {D1, D2, D3, … , D N}, wherein N represents a natural number greater than zero, C i represents the i-th road node, and D i represents its corresponding local data set.
[0102] For any road node C i In other words, such as Figure 2 As shown in step ①, its local dataset D i Extracted as a prototype representation vector R by the local extractor. i Specifically, node C i A sample image (Category y) will be extracted into the corresponding prototype representation vector. Where y is the image label category, m is the index of the image sample in category y, 0≤m<|M|, and |M| represents the index of category y in road node C. i The number of images. These prototype representation vectors condense the feature information of each class of samples, which is extracted from the local dataset by a local extractor, and finally form prototype representation vectors that can represent the features of the class.
[0103] Next, for category y, calculate its mean prototype representation vector. The mean prototype representation vector can be viewed as the node C. i Overall feature representation of category y:
[0104]
[0105] Ultimately, as Figure 2 As shown in step ②, node C i It will calculate and report the set of prototype representation vectors of the mean for all categories, denoted as Where Y is node C i Local dataset D i A set of all categories in D, which contains D i The mean prototype representation vectors of all categories are used for training the subsequent server-side global prediction head.
[0106] II. Training the server's global prediction head (global prediction head update module):
[0107] The server collects the set of mean prototype representation vectors uploaded from each road node. Then, these mean prototype representation vectors are combined into a small training sample to update the global prediction head, in order to learn global knowledge across nodes. The following A1-A3 are the specific processes:
[0108] A1. Collect the prototype representation vector of the mean:
[0109] Mean prototype representation vector Is category y at road node C? i The overall feature representation on local data can comprehensively summarize category y in C iDynamic heterogeneous features in local dataset. For the characteristics such as traffic density and lighting intensity in road nodes, the mean prototype representation vector can condense C i Core features of local dataset, showing the distribution of these features in space and time. Each node reports the mean prototype representation vector to effectively transfer dynamic heterogeneous features to the server. On the one hand, this transmission method reduces the communication overhead caused by uploading raw data; on the other hand, it provides key support for the server to integrate different node characteristics and train the global prediction head.
[0110] A2, build small training samples:
[0111] After receiving the mean prototype representation vectors reported by the nodes , these vectors and their corresponding class labels y are integrated into a small training sample set. Each mean prototype representation vector condenses the core characteristics of specific class data on the road node, such as the peak trend of traffic density or specific distribution patterns under lighting conditions. This small training sample not only retains the global heterogeneous information across nodes, but also significantly reduces the communication cost. At the same time, the diverse dynamic heterogeneous features in the set provide a rich source of information for the optimization of the global prediction head, enabling it to capture complex and variable traffic patterns between different nodes.
[0112] The construction of this small training sample embodies the collaborative expression of dynamic heterogeneous features, which is both lightweight and diverse. In the training process of the global prediction head, the small training sample set acts as a bridge, providing the server model with distributed knowledge across nodes to improve the generalization ability and adaptability of the global prediction head in complex traffic scenarios.
[0113] A3, training of global prediction head:
[0114] Finally, as shown in step ③ of Figure 2 , the server optimizes and trains the global prediction head using the small training sample set constructed. The global prediction head aims to extract common features across road nodes to improve the model's generalization ability and adaptability to diverse traffic scenarios. In the training process, the server uses the cross-entropy loss function to iteratively optimize the global prediction head through the correspondence between the mean prototype representation vector and its class label y.
[0115] The server inputs small training samples into the global prediction head, which predicts the class probability distribution and compares it with the actual class labels. The error is then calculated and backpropagated to update the parameters. In this process, the global prediction head gradually captures the consistency of feature distributions across nodes. For example, in nodes with high traffic density, the feature distribution may exhibit more dynamic changes, while in nodes with lower traffic volume, it shows a stable pattern. By learning from these dynamic and heterogeneous features, the global prediction head can construct a global model that integrates features from various road nodes.
[0116] III. Generation of intermediate prediction heads (forward inheritance module):
[0117] like Figure 2 As shown in step ④, the intermediate prediction head The generation is achieved through the hypernetwork structure in the forward inheritance module. The main goal of the forward inheritance module is to generate intermediate prediction heads for the current round using historical model parameters, thereby effectively integrating historical information and enhancing the adaptability to dynamic and heterogeneous traffic data.
[0118] To clearly illustrate the process of generating the intermediate prediction head, it is divided into three stages, B1-B3:
[0119] B1. Hypernetwork Input Stage:
[0120] The input to the hypernetwork structure includes the local prediction head of the node in the previous round. And earlier historical prediction head parameters:
[0121]
[0122] Where HN represents the hypernetwork function, and the stacked historical parameter vectors. It is its sole input source. These historical parameters carry knowledge from previous rounds, and the hypernetwork generates intermediate prediction heads for the current round by analyzing their feature distribution. Stacking historical parameters not only increases the depth of forward memory but also enhances the ability to capture long-term dynamic features.
[0123] In each round, the local prediction header parameters It will be stored and added to the history, updated as follows:
[0124]
[0125] in, It is node C i The historical parameter stack set from round t is used as input to the supernetwork, which dynamically adjusts the weights to generate new intermediate prediction head parameters.
[0126] B2, Intermediate prediction head generation stage:
[0127] After obtaining the history parameter stack , the hypernetwork generates the intermediate prediction head by the following steps
[0128] The hypernetwork first encodes the stacked history parameters , extracting high-order features through a multi-layer perceptron (MLP):
[0129]
[0130] where Z i is the extracted high-order feature representation, containing global and local features of the history parameters.
[0131] Then the hypernetwork dynamically assigns importance weights to the history parameters based on the high-order features Z i :
[0132] ω j = Softmax(WZ i + b), j ∈ {0, 1, …, t-1}
[0133] where ω j is the weight assigned to the j-th round of history parameters, W and b are the learnable parameters of the hypernetwork. The Softmax function ensures the weights are normalized, so that ∑ω j = 1.
[0134] Finally, the hypernetwork generates the intermediate prediction head by weighted sum of the history parameters with the dynamic weights:
[0135]
[0136] This stage ensures that the generated intermediate prediction head can integrate historical information and adapt to the current data features according to the dynamic weight distribution.
[0137] B3, Forward memory and dynamic adjustment stage:
[0138] To enhance the model's ability to adapt to dynamic features, the forward inheritance module further introduces a smoothing adjustment mechanism to balance the influence of historical and current parameters when generating the intermediate prediction head.
[0139]
[0140] where α is the smoothing coefficient, used to control the influence of historical parameters in the current round. Usually, α can be determined by linear decay or dynamic adjustment strategy based on data features.
[0141] The dynamic adjustment characteristics of the forward memory mechanism enable the model to flexibly adapt to data heterogeneity in time and space. For example, during peak traffic surges or off-peak stable patterns, the importance distribution of historical parameters adjusts with data changes, thereby improving the predictor's ability to adapt to different traffic nodes in a personalized manner.
[0142] IV. Local prediction head update (contrastive learning module):
[0143] like Figure 2 As shown in step ⑤, the local prediction head update for traffic nodes is implemented through the contrastive learning module, building upon the preceding steps. The core objective of the contrastive learning module is to transfer global knowledge to the local prediction head while preserving the characteristics of the local data, thereby improving the model's prediction performance and generalization ability. The process of updating the local prediction head is explained in detail below in two steps (C1-C2):
[0144] C1. Selection of positive and negative samples
[0145] In contrastive learning, the selection of positive and negative samples directly determines the effectiveness of knowledge transfer. To effectively achieve the transfer and integration of global prediction head knowledge, this invention's system emphasizes the following three key points in the design of positive and negative samples: globality, historical context, and diversity. The specific selection method is as follows:
[0146] Positive samples are selected as the global prediction head parameter θ for this round. t This design is based on the following two considerations. First, the global prediction head θ t It is trained from the mean prototype representation vector uploaded by all road nodes, containing dynamic heterogeneous features and shared knowledge of different nodes, which helps the local prediction head to calibrate and absorb global knowledge. Secondly, by using the global prediction head as positive samples, the local prediction head can integrate globally shared information while being trained in a personalized manner, thereby improving the model's generalization ability in heterogeneous data scenarios.
[0147] Negative samples are selected from the local prediction header parameters of the road node itself in the previous round. This design emphasizes historicity and diversity. Local forecast head. As the final result of the previous round of the local model, it fully preserves the characteristics and historical information of the local data. By introducing negative samples, the optimization process can prevent the model from over-relying on historical characteristics and avoid getting trapped in local optima. At the same time, the difference between negative and positive samples can provide a clear optimization direction for the contrastive loss, namely, widening the gap between the current predictor and the historical predictor, preventing the model from overfitting to historical data, and enhancing its ability to absorb global knowledge.
[0148] C2. Comparison of learning loss and local prediction head update
[0149] The basic framework of contrastive learning is as follows: Figure 3 As shown, the key lies in defining a reasonable loss function to quantify the similarity and differences between model parameters. This follows the principle of minimizing the objective function δ(I). + ,I a ) and maximizing the objective function δ(I) - ,I a The idea of ) is compared with the loss function l con The specific definitions are as follows:
[0150]
[0151] Where: sim(·,·) represents the similarity function, usually cosine similarity, and τ is a temperature coefficient used to adjust the sensitivity of the similarity.
[0152] The optimization objective of the loss function is to maximize the similarity between the local predictor and the global predictor, while minimizing the similarity with historical predictors, thereby achieving effective knowledge transfer.
[0153] In the optimization process of the local prediction head, besides the contrastive learning loss l con It is also necessary to consider the supervised learning loss of local data. sup The total loss function is:
[0154] l=μ*l con +(1-μ)*l sup
[0155] Where μ is the balancing coefficient, used to adjust the weights of contrastive learning and supervised learning in the total loss.
[0156] After calculating the total loss, the local prediction head parameters are updated using the backpropagation algorithm:
[0157]
[0158] Here, η is the learning rate, controlling the step size for parameter updates. By balancing the learning loss and supervised learning loss, road nodes can simultaneously learn global knowledge and local characteristics, thereby optimizing the model's personalized performance and generalization ability.
[0159] If the total loss is less than the threshold after the above calculation, the training is complete, and a personalized anomaly detection model for local dynamic heterogeneous features is obtained. Local real-time road data is input into the model to obtain the local real-time road detection status.
[0160] In summary, the embodiment proposes a bidirectional memory federated learning method, and applies it to a city road state and anomaly detection system. By dividing the model structure into an extractor and a prediction head, the computing resources of each node are fully utilized, and the performance overhead is reduced. The design of the extractor allows each road node to select an appropriate model according to its data characteristics, thereby solving the problem of inconsistent model sizes among different nodes in personalized federated learning and simplifying the integration and convergence process of the model.
[0161] In the algorithm implementation, the local prediction head of the node generates a combination of local historical data and global migration knowledge, realizing a bidirectional memory mechanism. The forward inheritance module generates an intermediate prediction head through a hypernetwork (HN), and through stacking and dynamic weighting processing of the historical prediction head parameters, the adaptability to dynamic heterogeneous traffic data is improved. In the global contrast learning process, the node takes the global prediction head of the last round as the positive sample and the local prediction head of the last round as the negative sample, and through the optimization of the contrast loss function, the accuracy and generalization ability of the local prediction head are further improved, ensuring that the model can effectively absorb global knowledge while retaining local characteristics.
[0162] The invention effectively improves the performance of the local personalized model of each node by synthesizing local and global information through a bidirectional memory mechanism, achieving higher applicability and accuracy. The separation design of the extractor and the prediction head and the efficient contrast learning mechanism minimize the communication overhead while fully utilizing the computing resources, so that the invention can maintain high efficiency in a resource-constrained environment.
[0163] The embodiment also compares the test effect with the prior art, as shown in Figure 4 The invention only needs 21 rounds of training to achieve an accuracy of 0.62 that the traditional federated average algorithm can achieve after 100 rounds of training, with a convergence speed improvement of 4.76 times, significantly enhancing the learning efficiency and detection ability of the system.
[0164] The preferred embodiment of the invention also discloses a city traffic detection method based on bidirectional memory federated learning, for executing the above-mentioned system, comprising the following steps:
[0165] S1, real-time collection of road original data, and conversion of the original data into a prototype representation vector, and uploading the prototype representation vector to a server;
[0166] S2, the server collects the uploaded mean prototype representation vector, trains it using a global prediction head, optimizes and updates it, and generates a new global prediction head;
[0167] S3, the super network stacks all the local prediction heads generated by the road nodes in the previous training round to generate the intermediate prediction head of the current round; in this step, each terminal stacks the historical local prediction head by the super network combined with the forward inheritance mechanism to generate the intermediate prediction head.
[0168] S4, the contrast learning is used to calculate the contrast loss between the global prediction head and the intermediate prediction head generated by the forward inheritance module, and a joint loss is constructed combined with the supervised learning loss, if the joint loss is greater than or equal to the threshold, the local prediction head is generated, and the local prediction head is stacked to the super network, and the step S1 is returned; if the joint loss is less than the threshold, the training is completed, and the personalized anomaly detection model for the local dynamic heterogeneous features is obtained, the local real-time road data is input into the model, and the local real-time road detection state is obtained. In this step, the terminal device performs knowledge transfer on the intermediate prediction head and the global prediction head by contrast learning, optimizes and generates the local prediction head, stacks the local prediction head to the super network, and realizes the bidirectional memory mechanism.
[0169] The other contents of the embodiment can refer to the above-mentioned system embodiment.
[0170] The preferred embodiment of the present application also discloses a storage medium which stores computer instructions for making a computer execute the above-mentioned system or method.
[0171] The preferred embodiment of the present application also discloses an electronic device which comprises:
[0172] a processor;
[0173] a memory for storing a program, when the program is called and executed by the processor, the processor executes the above-mentioned system or method.
[0174] The above-mentioned content is only the preferred embodiment of the present application, and the person skilled in the art can make various changes and improvements after understanding the basic idea of the present application, and these changes and improvements should be regarded as the protection scope of the present application.
Claims
1. A city traffic detection system based on bidirectional memory federated learning, characterized by: Includes the following modules: Data acquisition module: Deployed at nodes on urban roads, responsible for collecting raw road data in real time, converting the raw data into prototype representation vectors, and then uploading the vectors to the server; Global prediction head update module: Deployed on the server, it is responsible for receiving the prototype representation vector uploaded from the road node, and optimizing and updating the global prediction head based on the uploaded prototype representation vector to generate a new global prediction head; Forward Inheritance Module: Nodes deployed on city roads maintain a hypernet inside, which stores and transmits information from the historical training process; the hypernet stacks all the local prediction heads generated by the road nodes in previous training rounds to generate the intermediate prediction head for the current round. Contrastive learning module: Deployed at nodes on urban roads, it calculates the contrast loss between the global prediction head and the intermediate prediction head generated by the forward inheritance module through contrastive learning, and constructs a joint loss by combining the supervised learning loss. If the joint loss is less than the threshold, the training is complete, and a personalized anomaly detection model for local dynamic heterogeneous features is obtained. Local real-time road data is input into the model to obtain the local real-time road detection status. In the forward inheritance module, the process of generating intermediate prediction heads is as follows: B1. Hypernetwork Input Stage: The input to the hypernetwork includes the node's local prediction head from the previous round. And historical prediction head parameters: Where HN represents the hypernetwork function, and the stacked historical parameter vectors. These historical parameters, which are its sole input source, carry knowledge from previous rounds. The hypernetwork generates intermediate prediction heads for the current round by analyzing their feature distribution. ; In each round, the local prediction header parameters It will be stored and added to the history, updated as follows: in, It is node C i The historical parameter stack set in round t; the supernetwork takes the stack set as input and dynamically adjusts the weights to generate new intermediate prediction head parameters; B2. Intermediate Prediction Head Generation Stage: Obtaining historical parameter stacking Then, the supernetwork generates intermediate prediction heads through the following steps: Hypernetwork stacked historical parameters Encode the data and extract higher-order features using a multilayer perceptron: Among them, Z i It is the extracted high-order feature representation, which includes global and local features of historical parameters; Hypernetworks based on higher-order features Z i Dynamically assign importance weights to historical parameters: Among them, w j Σw represents the weights assigned to the historical parameters in the j-th round, where W and b are learnable parameters of the hypernetwork; the Softmax function ensures that the weights are normalized, such that Σw j =1; The hypernetwork uses dynamic weights to perform a weighted summation of historical parameters to generate an intermediate prediction head. B3. Forward Memory and Dynamic Adjustment Stage: The forward inheritance module introduces a smoothing adjustment mechanism to balance the influence of historical and current parameters when generating intermediate prediction heads; in, This is a smoothing coefficient used to control the degree of influence of historical parameters in the current round.
2. The urban traffic detection system based on bidirectional memory federated learning as described in claim 1, characterized in that, The data acquisition module is as follows: Let there be N road nodes in a set C = {C1, C2, C3, ..., C}. N } represents the local dataset of each road node as set D={D1,D2,D3,…,D…} N } represents, where N represents a natural number greater than zero, and C i Let D represent the i-th road node. i This indicates the corresponding local dataset; For any road node C i In terms of its local dataset D i Extracted as a prototype representation vector R by the local extractor. i Specifically, node C i A sample image It will be extracted into the corresponding prototype representation vector Where y is the image label category, and m is the index of the image sample in category y. , |M| represents category y at road node C i The number of images; For category y, calculate its mean prototype representation vector. The mean prototype representation vector is considered as the node C. i Overall feature representation of category y: Node C i It will calculate and report the set of prototype representation vectors of the mean for all categories, denoted as Where Y is node C i Local dataset D i The collection of all categories.
3. The urban traffic detection system based on bidirectional memory federated learning as described in claim 2, characterized in that, In the global prediction head update module, the server collects the set of mean prototype representation vectors uploaded by road nodes. Then, the mean prototype representation vectors are used to form a training sample to update the global prediction head. The specific process is as follows: A1. Collect the prototype representation vector of the mean: Mean prototype representation vector Is category y at road node C? i The overall feature representation on local data can comprehensively summarize category y in C i Dynamic heterogeneous features in a local dataset, the mean prototype representation vector can condense C i Core features of the local dataset; Each node effectively transmits dynamic heterogeneous features to the server by reporting the mean prototype representation vector; A2. Constructing training samples: The server reports the prototype representation vector of the mean from the receiving node. Then, the vectors and their corresponding class labels y are integrated into a training sample set; A3. Training the global prediction head: The server optimizes and trains the global prediction head using a constructed set of training samples; during training, the server uses the mean prototype to represent the vectors. The correspondence between the global prediction head and its category label y is used to iteratively optimize the global prediction head using the cross-entropy loss function.
4. The urban traffic detection system based on bidirectional memory federated learning as described in claim 1, characterized in that, In the contrastive learning module, the process of updating the local prediction head is divided into two steps: C1. Selection of positive and negative samples Positive samples are selected as the global prediction head parameter θ for this round. t ; Negative samples are selected from the local prediction header parameters of the road node itself in the previous round. ; C2. Comparison of learning loss and local prediction head update Contrast loss function The specific definitions are as follows: Where: sim(•,•) represents the similarity function. It is the temperature coefficient; In the optimization process of the local prediction head, in addition to comparing the learning loss... We also need to consider the supervised learning loss of local data. The total loss function is: in, μ This is the balance coefficient; After calculating the total loss, the local prediction head parameters are updated using the backpropagation algorithm: in, η It is the learning rate.
5. A city traffic detection method based on bidirectional memory federated learning, used to execute the system as described in any one of claims 1-4, characterized in that, Includes the following steps: S1. Collect raw road data in real time, convert the raw data into a prototype representation vector, and then upload the prototype representation vector to the server. S2. The server collects the uploaded mean prototype representation vector, trains it using the global prediction head, optimizes and updates it, and generates a new global prediction head. S3. The super network stacks all the local prediction heads generated by the road nodes in the previous training rounds to generate the intermediate prediction head for the current round. S4. Using contrastive learning, calculate the contrastive loss between the global prediction head and the intermediate prediction head generated by the forward inheritance module, and construct a joint loss by combining it with the supervised learning loss. If the joint loss is greater than or equal to the threshold, generate a local prediction head and stack the local prediction head to the super network, then return to step S1. If the joint loss is less than the threshold, the training is complete, and a personalized anomaly detection model for local dynamic heterogeneous features is obtained. Input the local real-time road data into the model to obtain the local real-time road detection status.
6. A storage medium, characterized in that, The computer instructions are stored to cause the computer to perform the system according to any one of claims 1 to 4 or the method according to claim 5.
7. An electronic device, characterized in that, include: processor; A memory for storing a program that, when invoked and executed by a processor, causes the processor to perform the system as described in any one of claims 1 to 4 or the method as described in claim 5.
Citation Information
Patent Citations
Internet of vehicles intrusion detection model construction method based on federated learning
CN118784305A
Distributed traffic flow prediction method based on personalized federal learning
CN118840871A