Federal contrast learning method based on double-branch network and global negative sample queue
By employing a federated contrastive learning method with a global dual-branch model and a global negative sample queue, the training challenge of non-independent and identically distributed data in federated learning is solved. This approach improves model performance and generalization ability while protecting privacy, resolves client drift, and safeguards client privacy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XINJIANG UNIVERSITY
- Filing Date
- 2026-02-03
- Publication Date
- 2026-06-05
AI Technical Summary
Existing federated learning methods struggle to effectively train a global model when faced with non-independent and identically distributed client data, leading to client drift, which affects model performance and generalization ability, while also posing a risk of privacy leaks.
A federated contrastive learning method using a global dual-branch model and a global negative sample queue is adopted. The global dual-branch model and negative sample queue are initialized by the server module, the client module trains the master encoding model locally and uploads the feature representation data, and the server module updates the global model and queue, realizing the joint optimization of supervised learning and contrastive learning, and protecting data privacy through encryption mechanisms.
While protecting data privacy, the model's performance and generalization ability in non-independent and identically distributed data environments have been improved, feature bias has been effectively corrected, the model's discriminativeness and robustness have been enhanced, and privacy information leakage has been avoided.
Smart Images

Figure CN122154844A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of federated learning technology, and in particular to a federated contrastive learning method based on a dual-branch network and a global negative sample queue. Background Technology
[0002] With the rapid development of edge computing, IoT, and privacy computing technologies, massive amounts of distributed data are generated across various terminal devices. Federated learning, as a privacy-preserving distributed machine learning paradigm, allows clients to collaboratively train models through parameter or gradient aggregation without uploading raw data. However, the privacy information of client modules can still be deduced from the parameters or gradients. Furthermore, in practical applications, the data from different clients often exhibits non-independent and identically distributed characteristics. For example, medical image data from different hospitals differ significantly in disease category, imaging equipment, and image quality; production line inspection data from different factories may also be offset due to environmental differences. This data heterogeneity leads to a significant decrease in the performance of global models based on traditional algorithms such as FedAvg, resulting in client drift and difficulty in converging the training process, thus limiting the application of federated learning in critical real-world scenarios. Summary of the Invention
[0003] This application proposes a global dual-branch model, introduces a global negative sample queue maintained by the server module, and provides a method to ensure the data security of data uploaded by the client module. The aim is to improve the problem caused by the non-independent and identically distributed nature of data from multiple clients while protecting privacy information.
[0004] This application provides a federated contrastive learning method based on a dual-branch network and a global negative sample queue, including the following steps:
[0005] S1. The server module initializes a global dual-branch model and a global negative sample queue;
[0006] S2. The server module selects several client modules from all client modules and distributes the current global dual-branch model and global negative sample queue to these client modules.
[0007] S3. Each client module that receives the global dual-branch model trains the main encoding model and updates the momentum encoding model locally. After completing the training, it uploads the parameter update data of the main encoding model and the local feature representation data to the server module.
[0008] S4. The server module updates the global bi-branch model based on all parameter update data and updates the global negative sample queue based on all feature representation data. Before the global bi-branch model converges, it jumps to S2.
[0009] In a preferred embodiment, the model structure of the main encoding model is the same as that of the global two-branch model, which includes a shared feature encoder, a supervised learning branch, and a contrastive learning branch.
[0010] In a preferred embodiment, the momentum coding model includes a shared feature encoder and a contrastive learning branch projection head (MLP).
[0011] In a preferred embodiment, the client module trains the master encoding model locally and updates the momentum encoding model, including the following steps:
[0012] S311. Set the parameters of the main coding model and the momentum coding model according to the parameters of the received global dual-branch model;
[0013] S312. Perform weak enhancement processing on the original images in the same batch to obtain the first enhanced image in the same batch, and perform strong enhancement processing on the original images in the same batch twice to obtain the second enhanced image and the third enhanced image in the same batch.
[0014] S313. Input the first enhanced image, the second enhanced image, and the third enhanced image of the same batch into the shared feature encoder to obtain the first feature vector, the second feature vector, and the third feature vector of the same batch, respectively.
[0015] S314. Input the first feature vector of the same batch into the supervised learning branch to obtain several classification prediction results, and use the cross-entropy loss function to calculate the supervised loss. Input the second feature vector and the third feature vector of the same batch into the contrastive learning branch to obtain several output feature vector pairs, and calculate the contrastive loss.
[0016] S315. Assign corresponding weights to the supervised loss and the contrastive loss respectively to calculate the total loss. Update the parameters of the shared feature encoder, the supervised learning branch and the contrastive learning branch through the backpropagation algorithm. Weight the parameters of the main encoding model and the momentum encoding model to update the parameters of the momentum encoding model.
[0017] S316. Determine if there are other batches of original images that have not been processed. If yes, proceed to S312. If no, continue to determine if the preset number of training rounds has been completed. If no, proceed to S312. If yes, generate parameter update data for the main encoding model and local feature representation data.
[0018] In a preferred embodiment, calculating the contrastive loss includes: for each pair of output feature vectors, taking one of the output feature vectors as an anchor point, taking the other output feature vector as a positive sample, taking all other output feature vectors as negative samples, calculating the loss in combination with the global negative sample queue, and calculating the mean of all losses to obtain the contrastive loss.
[0019] In a preferred embodiment, generating local feature representation data includes: inputting a batch of untrained raw images into a momentum coding model to obtain local feature representation data.
[0020] In a preferred embodiment, the client module uploads the parameter update data of the main coding model and the local feature representation data to the server module, including the following steps:
[0021] S321. The client module and the server module securely store shared password 1 and shared password 2 in advance.
[0022] S322 and the client module generate arbitrary value 1 and arbitrary value 2 respectively. They perform scrambling calculation on arbitrary value 1 and shared secret value 1 to obtain the sending secret value 1, and perform scrambling calculation on arbitrary value 2 and shared secret value 2 to obtain the sending secret value 2.
[0023] S323, the client module performs mixed processing on any value 1 and any value 2 to obtain the sending secret value 3, uses the sending secret value 3 to encrypt the processing parameters to update the data and feature representation data to obtain encrypted data, and uploads the sending secret value 1, sending secret value 2, and encrypted data to the server module.
[0024] In a preferred embodiment, the method of mixing any value 1 and any value 2 to obtain the transmission encryption value 3 includes the following modules:
[0025] S3231. Divide any value 1 and any value 2 into the same number of value blocks 1 and value blocks 2 respectively, arrange all value blocks 1 and value blocks 2 to obtain the value block sequence, and set n = 1;
[0026] S3232. Circularly shift the value block that is a preset distance away from the nth value block in the value block sequence to the left by n bits to obtain the process value block. Perform scrambling calculation on the nth value block and the process value block to obtain a new value block. Determine whether there are other value blocks that have not been processed. If yes, set n = n+1 and repeat this step. If no, continue to S3233.
[0027] S3233: Sequentially connect each new value block to obtain a new value block sequence, and extract the transmission cipher value 3 from the new value block sequence.
[0028] Compared with the prior art, the beneficial effects of this application are at least as follows:
[0029] In the technical solution provided in this application, the first step is that the server module initializes a global dual-branch model and a global negative sample queue. The second step is that the server module selects several client modules from all client modules and distributes the current global dual-branch model and global negative sample queue to these client modules. The third step is that each client module receiving the global dual-branch model trains the main encoding model and updates the momentum encoding model locally. After training is complete, it uploads the parameter update data of the main encoding model and the local feature representation data to the server module. The fourth step is that the server module updates the global dual-branch model based on all the parameter update data and updates the global negative sample queue based on all the feature representation data. Before the global dual-branch model converges, it jumps back to the second step to continue execution. This application jointly optimizes supervised learning and contrastive learning within the same model, achieving real-time collaboration between task-driven learning and feature regularization. It innovatively introduces a global negative sample queue maintained by the server module, enabling each client to obtain diverse feature references from the entire network during local training. This allows for the learning of a unified feature representation that is robust to distributional differences and highly discriminative from the root, effectively improving the model's performance and generalization ability in non-independent and identically distributed data environments. Furthermore, this application also protects the security of data uploaded by the client module, preventing the inference of the client module's privacy information based on the uploaded data. Attached Figure Description
[0030] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1 This is a flowchart of the federated contrastive learning method based on a dual-branch network and a global negative sample queue in this application;
[0032] Figure 2 This is a graph showing the distribution of non-independent and identically distributed data when α=0.1;
[0033] Figure 3 The graph shows the change in accuracy with the number of communication rounds when α=0.1.
[0034] Figure 4 The graph shows the change in Loss with the number of communication rounds when α=0.1;
[0035] Figure 5 The graph shows the distribution of non-independent and identically distributed data when α=0.3;
[0036] Figure 6 The graph shows the change in accuracy with the number of communication rounds when α=0.3.
[0037] Figure 7 The graph shows the change in Loss with the number of communication rounds when α=0.3;
[0038] Figure 8 This is a graph showing the distribution of non-independent and identically distributed data when α=0.5;
[0039] Figure 9 The graph shows the change in accuracy with the number of communication rounds when α=0.5;
[0040] Figure 10 This is a graph showing the distribution of non-independent and identically distributed data when α=0.5;
[0041] Figure 11 This is a graph showing the distribution of non-independent and identically distributed data when α=1.
[0042] Figure 12 The graph shows the change in accuracy with the number of communication rounds when α=1.
[0043] Figure 13 This is a graph showing the distribution of non-independent and identically distributed data when α=1. Detailed Implementation
[0044] This application provides a federated contrastive learning method based on a dual-branch network and a global negative sample queue. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data used can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" or "having" and any variations thereof are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0045] For ease of understanding, the specific process of the embodiments of this application is described below. Please refer to [link / reference]. Figure 1 The federated contrastive learning method based on a dual-branch network and a global negative sample queue in this application embodiment includes the following main steps:
[0046] S1. The server module initializes a global dual-branch model and a global negative sample queue;
[0047] S2. The server module selects several client modules from all client modules and distributes the current global dual-branch model and global negative sample queue to these client modules.
[0048] S3. Each client module that receives the global dual-branch model trains the main encoding model and updates the momentum encoding model locally. After completing the training, it uploads the parameter update data of the main encoding model and the local feature representation data to the server module.
[0049] S4. The server module updates the global bi-branch model based on all parameter update data and updates the global negative sample queue based on all feature representation data. Before the global bi-branch model converges, it jumps to S2.
[0050] This application focuses on maintaining a global dynamic dictionary or prototype in the server module to aggregate feature information from all client modules, thereby providing each client module with high-quality, globally consistent negative samples. The aim is to bridge the gap in data distribution and collaboratively learn a unified and discriminative global feature space, which is the essence of the deep integration of federated learning and self-supervised learning to eradicate the problem of data heterogeneity.
[0051] Currently, research combining self-supervised learning and federated learning is still in its early stages. Most mainstream methods employ a "two-stage training" approach: first, federated self-supervised training, followed by supervised fine-tuning. This approach suffers from two problems: the separation of self-supervised representation and task learning makes end-to-end optimization difficult; and due to the different data distributions of each client, negative sample bias is severe, leading to an imbalanced learned representation space. Therefore, this application, without violating privacy constraints, provides globally shared, diverse negative samples to all clients, addressing a core problem that current federated self-supervised learning urgently needs to solve.
[0052] Specifically, in step S1, the server module initializes a global bi-branch model (the structure of which will be described below) and a global negative sample queue. The initial global negative sample queue is empty; the server module pre-fills it with a zero vector or a random vector following a standard normal distribution. In step S2, the server module selects several client modules from all client modules and distributes the current global bi-branch model and global negative sample queue to these selected client modules. In step S3, for each client module that receives the global bi-branch model, it trains the main encoding model locally and updates the momentum encoding model. The structures of the main encoding model and momentum encoding model will be described below. After training is complete, the client module uploads the parameter update data of the main encoding model and the local feature representation data to the server module. In step S4, the server module updates the global bi-branch model based on all received parameter update data, updates the global negative sample queue based on all received feature representation data, and updates the global negative sample queue according to the limited capacity of the global negative sample queue. Specifically, the first-in-first-out principle is adopted to update the global negative sample queue to ensure representation diversity. The module then determines whether the global bi-branch model has converged. Before the global bi-branch model converges, the module jumps to step S2 to continue execution.
[0053] Furthermore, the model structure of the main encoding model is the same as that of the global two-branch model, which includes a shared feature encoder, a supervised learning branch, and a contrastive learning branch.
[0054] Furthermore, the momentum coding model includes a shared feature encoder and a contrastive learning branch projection head MLP.
[0055] Specifically, the main encoding model in this application maintains the same model structure as the global dual-branch model. The global dual-branch model includes a shared feature encoder, a supervised learning branch, and a contrastive learning branch. The shared feature encoder is a ResNet backbone network, which abstracts and extracts high-level, semantically rich feature representations from pixel-level information layer by layer through its deep convolutional neural network architecture. The supervised learning branch includes a classification head, typically composed of one or more fully connected layers, used to map the features extracted by the shared feature encoder to a category space for a specific task, such as image classification. The contrastive learning branch includes a projection head MLP, typically a multilayer perceptron, used to map features to a low-dimensional contrastive learning space, followed by a normalization layer to ensure that the magnitude of the output feature vector is 1. In addition, a momentum encoding model is used to extract and contribute feature representations to local data, including the shared feature encoder and the contrastive learning branch projection head MLP.
[0056] Furthermore, the client module trains the master encoding model locally and updates the momentum encoding model, including the following steps:
[0057] S311. Set the parameters of the main coding model and the momentum coding model according to the parameters of the received global dual-branch model;
[0058] S312. Perform weak enhancement processing on the original images in the same batch to obtain the first enhanced image in the same batch, and perform strong enhancement processing on the original images in the same batch twice to obtain the second enhanced image and the third enhanced image in the same batch.
[0059] S313. Input the first enhanced image, the second enhanced image, and the third enhanced image of the same batch into the shared feature encoder to obtain the first feature vector, the second feature vector, and the third feature vector of the same batch, respectively.
[0060] S314. Input the first feature vector of the same batch into the supervised learning branch to obtain several classification prediction results, and use the cross-entropy loss function to calculate the supervised loss. Input the second feature vector and the third feature vector of the same batch into the contrastive learning branch to obtain several output feature vector pairs, and calculate the contrastive loss.
[0061] S315. Assign corresponding weights to the supervised loss and the contrastive loss respectively to calculate the total loss. Update the parameters of the shared feature encoder, the supervised learning branch and the contrastive learning branch through the backpropagation algorithm. Weight the parameters of the main encoding model and the momentum encoding model to update the parameters of the momentum encoding model.
[0062] S316. Determine if there are other batches of original images that have not been processed. If yes, proceed to S312. If no, continue to determine if the preset number of training rounds has been completed. If no, proceed to S312. If yes, generate parameter update data for the main encoding model and local feature representation data.
[0063] Specifically, this section describes how the client module trains the main encoding model locally and updates the momentum encoding model. In step S311, the parameters of the main encoding model and the momentum encoding model are set based on the received parameters of the global dual-branch model. In step S312, weak enhancement processing is performed on the original images in the same batch to obtain the first enhanced image of the same batch. Weak enhancement processing includes geometric transformation, color and contrast adjustment, etc. Strong enhancement processing is performed on the original images in the same batch twice to obtain the second enhanced image and the third enhanced image of the same batch. It should be noted that two different strong enhancement processing is applied to each original image. Strong enhancement processing includes spatial and geometric distortion, noise injection, etc. In step S313, the first enhanced image, the second enhanced image, and the third enhanced image of the same batch are respectively input into the shared feature encoder to obtain the first feature vector, the second feature vector, and the third feature vector of the same batch. The shared feature encoder performs feature extraction operations based on a deep convolutional neural network architecture, mapping high-dimensional image data into a fixed-dimensional deep feature representation. In step S314, the first feature vector of the same batch is input into the supervised learning branch to obtain several classification prediction results. The supervised loss is calculated using the cross-entropy loss function. The second feature vector and the third feature vector of the same batch are input into the contrastive learning branch to obtain several output feature vector pairs. The contrastive loss is calculated, and the calculation method will be described below. In step S315, corresponding weights are configured for the supervised loss and the contrastive loss, respectively. The supervised weight is 1, and the contrastive weight is a value between 0.1 and 0.5. The total loss is obtained by calculating {supervised loss + contrastive weight * contrastive loss}. Then, the parameters of the shared feature encoder, the supervised learning branch, and the contrastive learning branch are updated through the backpropagation algorithm. The parameters of the main encoding model and the momentum encoding model are weighted and combined to update the parameters of the momentum encoding model. Specifically, the parameters of the momentum encoding model are updated according to the formula θm = mθm + (1−m)θ. This realizes the use of the current parameters of the main encoding model to slowly pull the parameters of the momentum encoding model. Here, θm is the parameter of the momentum encoding model, θ is the parameter of the main encoding model, and m∈[0.9,0.999] is the momentum coefficient. In step S316, it is determined whether there are other batches of original images that have not been processed. If yes, proceed to step S312. If no, since a federated communication round usually includes multiple local training epochs, it is determined whether the preset number of training rounds has been completed. If no, proceed to step S312. If yes, generate parameter update data for the master coding model and local feature representation data. How to generate local feature representation data will be described below.
[0064] It should also be noted that during the federated training process, the client module employs a dynamic scheduling mechanism to finely control the learning process: the learning rate first increases gradually through linear warm-up to avoid initial oscillations, and then gradually decreases according to a cosine annealing strategy to ensure the stability of later convergence; at the same time, the weight of the contrastive loss increases linearly from a low initial value of 0.1 to a maximum target value of 0.5, allowing the model to focus more on mastering basic supervised tasks in the early stages of training, and then gradually strengthens contrastive learning to improve the discriminative power of features; the temperature parameter in the contrastive loss decreases in a cosine manner with each communication round, which means that the model is more tolerant of differences in feature similarity in the early stages of training, which helps to stabilize the start, and gradually becomes more sensitive and strict as training progresses, forcing intra-class aggregation and inter-class separation in the feature space to become clearer and more explicit, thereby synergistically ensuring the smooth adaptation of the training process and the high quality of the final feature representation.
[0065] Furthermore, the calculation of the contrastive loss includes: for each pair of output feature vectors, each time one of the output feature vectors is used as the anchor point, the other output feature vector is used as the positive sample, and all other output feature vectors are used as negative samples. The loss is calculated by combining the global negative sample queue, and the mean of all losses is calculated to obtain the contrastive loss.
[0066] Specifically, this section describes how to calculate the contrastive loss. For each pair of output feature vectors from the contrastive learning branch, one output feature vector is used as the anchor point, the other output feature vector is used as the positive sample, and all other output feature vectors are used as negative samples. All other output feature vectors refer to all output feature vectors contained in all other output feature vector pairs. In addition, the received global negative sample queue is also used to calculate the InfoNCE loss. That is, each output feature vector pair corresponds to two InfoNCE losses. Finally, the mean of all losses is calculated to obtain the contrastive loss.
[0067] Furthermore, generating local feature representation data includes: inputting a batch of untrained raw images into the momentum coding model to obtain local feature representation data.
[0068] Specifically, this section explains how to generate local feature representation data. A batch of raw images is acquired locally. This batch is extracted from a pre-reserved set of raw images not used in training. No augmentation is applied to this batch of raw images; they are directly input into the momentum encoding model to obtain local feature representation data. By uploading only the abstract feature vectors generated by the momentum encoding model, rather than the raw data, data privacy and security are protected. Simultaneously, these features, as diverse negative samples, are fed into a global queue, providing all client modules with a global perspective beyond the local data distribution. This effectively corrects feature bias caused by non-independent and identically distributed data, promoting alignment and unification of feature spaces across client modules. Therefore, without sharing raw data, the overall model performance and generalization ability of the federated learning system are significantly improved.
[0069] Furthermore, the client module uploads the parameter update data of the main encoding model and the local feature representation data to the server module, including the following steps:
[0070] S321. The client module and the server module securely store shared password 1 and shared password 2 in advance.
[0071] S322 and the client module generate arbitrary value 1 and arbitrary value 2 respectively. They perform scrambling calculation on arbitrary value 1 and shared secret value 1 to obtain the sending secret value 1, and perform scrambling calculation on arbitrary value 2 and shared secret value 2 to obtain the sending secret value 2.
[0072] S323, the client module performs mixed processing on any value 1 and any value 2 to obtain the sending secret value 3, uses the sending secret value 3 to encrypt the processing parameters to update the data and feature representation data to obtain encrypted data, and uploads the sending secret value 1, sending secret value 2, and encrypted data to the server module.
[0073] Specifically, the process of the client module uploading data to the server module is described. In step S321, the client module and the server module securely store shared key value 1 and shared key value 2 in advance, and the lengths of shared key value 1 and shared key value 2 are the same. In step S322, the client module generates arbitrary value 1 and arbitrary value 2 respectively. Specifically, arbitrary value 1 and arbitrary value 2 can be generated by using a cryptographically secure PRNG. The lengths of arbitrary value 1 and arbitrary value 2 are the same as the lengths of shared key value 1 and shared key value 2. Scrambling calculation is performed on arbitrary value 1 and shared key value 1 to obtain the sending key value 1. Scrambling calculation is also performed on arbitrary value 2 and shared key value 2 to obtain the sending key value 2. For ease of understanding, for example, scrambling calculation is performed on "10100" and "11111" to obtain "01011". In step S323, the client module performs mixed processing on arbitrary value 1 and arbitrary value 2 to obtain sending key value 3. Based on this, the sending key value 3 can be used to encrypt the parameter update data and feature representation data. For example, the sending key value 3 can be used as the key of the AES algorithm to encrypt the parameter update data and feature representation data to obtain encrypted data. Finally, the sending key value 1, sending key value 2, and encrypted data are uploaded to the server module.
[0074] Furthermore, the transmission cipher value 3 is obtained by mixing any value 1 and any value 2, including the following modules:
[0075] S3231. Divide any value 1 and any value 2 into the same number of value blocks 1 and value blocks 2 respectively, arrange all value blocks 1 and value blocks 2 to obtain the value block sequence, and set n = 1;
[0076] S3232. Circularly shift the value block that is a preset distance away from the nth value block in the value block sequence to the left by n bits to obtain the process value block. Perform scrambling calculation on the nth value block and the process value block to obtain a new value block. Determine whether there are other value blocks that have not been processed. If yes, set n = n+1 and repeat this step. If no, continue to S3233.
[0077] S3233: Sequentially connect each new value block to obtain a new value block sequence, and extract the transmission cipher value 3 from the new value block sequence.
[0078] Specifically, the specific process of the mixing process is described. In step S3231, arbitrary value 1 and arbitrary value 2 are divided into the same number of numerical blocks 1 and numerical blocks 2, respectively. The length of each numerical block 1 is the same, the length of each numerical block 2 is the same, and the length of each numerical block 1 is also the same as the length of each numerical block 2. All numerical blocks 1 and numerical blocks 2 are arranged according to a preset rule to obtain a numerical block sequence. For ease of understanding, assume that arbitrary value 1 is 10010101 and arbitrary value 2 is 11001010. The numerical blocks 1 are 10 01 01 01 and the numerical blocks 2 are 11 00 10 10. The numerical blocks 1 and numerical blocks 2 are arranged in a cross-tabulation manner to obtain the numerical block sequence 10 11 01 00 01 10 01 10. Then, n = 1 is set. In step S3232, a value block that is at a preset distance from the nth value block in the value block sequence is determined. The preset distance is half the length of the value block sequence. Continuing with the example above, the preset distance is 4. The value block is cyclically shifted left by n bits to obtain the process value block. The nth value block and the process value block are scrambled to obtain a new value block. Continuing with the example above, the value block 01 that is at a distance of 4 from the first value block 10 is cyclically shifted left by 1 bit to obtain the process value block 10. The process value block 10 and the first value block 10 are scrambled to obtain a new value block 00. Then it is determined whether there are other value blocks that have not undergone the above processing. If so, n = n+1 is set and this step is repeated. If not, step S3233 is continued. It should be noted that, for example, regarding the 5th value block, there is no value block at a distance of 4 from it because 5 + 4 = 9, and the length of the value block sequence is 8. In this case, the length of the value block sequence should be moduloed to determine the 1st value block. In step S3233, each new value block is connected sequentially to obtain a new value block sequence. Specifically, each new value block is connected sequentially according to the order in which they are generated. The transmission cipher value 3 is extracted from the new value block sequence. Continuing with the example above, for example, four value blocks located at the center of the new value block sequence are extracted to form the transmission cipher value 3.
[0079] Using the above methods, it is difficult for third parties to extract parameter update data and feature representation data from the data sent by the client module, thus preventing third parties from reverse-engineering the client module's privacy information based on this data, thereby protecting the client module's privacy information.
[0080] It should also be noted that after receiving the sent cipher value 1, sent cipher value 2, and encrypted data, the server module also needs to recover the parameter update data of the main coding model and the local feature representation data. Specifically, the following steps are taken: Scrambling is performed on sent cipher value 1 and shared cipher value 1 to obtain arbitrary value 1; scrambling is performed on sent cipher value 2 and shared cipher value 2 to obtain arbitrary value 2; the above mixing process is then applied to arbitrary value 1 and arbitrary value 2 to obtain sent cipher value 3; sent cipher value 3 is then used to decrypt the encrypted data, for example, using sent cipher value 3 as the key for the AES algorithm to decrypt the encrypted data.
[0081] In summary, this application jointly optimizes supervised learning and contrastive learning within the same model, achieving real-time collaboration between task-driven learning and feature regularization. It innovatively introduces a global negative sample queue maintained by the server module, enabling each client to obtain diverse feature references from the entire network during local training. This allows for the learning of robust and highly discriminative unified feature representations that are robust to distributional differences, while protecting data privacy. This effectively improves the model's performance and generalization ability in non-independent, identically distributed data environments. Furthermore, this application protects the security of data uploaded by the client module, preventing the inference of the client module's privacy information based on uploaded data.
[0082] Furthermore, to verify the method proposed in this application, experiments were conducted with α values of 0.1, 0.3, 0.5, and 1.0, respectively. α is the Dirichlet concentration, representing the degree of non-independent and identically distributed data. The smaller the value, the more unbalanced the data distribution. Detailed experimental results are shown below. Figures 2 to 13 As shown in Table 1, the experimental results are summarized below. It can be clearly seen that the method proposed in this application achieves better results than FedAvg and FedProx under different levels of non-IID, providing an innovative solution for performance optimization of distributed machine learning in heterogeneous data scenarios, and possessing significant theoretical value and broad application prospects.
[0083] For example, in the field of intelligent manufacturing, multiple factories under the same manufacturing group often face the challenge of collaborative quality control: although producing the same products, the production line configurations, visual inspection systems, and lighting environments differ among factories, and the types and frequencies of defects appearing on different production lines also show a significant uneven distribution. To address this complex situation, the supervised learning branch focuses on accurately identifying specific defect categories to ensure the reliability of basic inspection tasks; while the contrastive learning branch, through data augmentation and feature invariance learning, effectively removes interference from non-critical factors such as production line environment and lighting conditions, allowing the model to focus on the essential morphological characteristics of defects. Crucially, a cross-factory knowledge-sharing channel is constructed through a global negative sample queue mechanism. When a factory primarily experiences "scratch" type defects, its local model can still access rare defect features such as "dents" and "impurities" from other factories through the global queue. This cross-site feature-level knowledge fusion enables the system to establish a general quality inspection model that is highly sensitive to all types of defects, significantly improving its adaptability in identifying new defects and deploying on unknown production lines.
[0084] Table 1
[0085] method α = 0.1 (High-level non-IID) α = 0.3 (Moderate non-IID) α = 0.5 (mild non-IID) α = 1.0 (IID) stability FSIM 58.2% 68.4% 76.3% 84.1% 0.92 FedProx 52.1% 65.2% 73.1% 81.2% 0.85 FedAvg 45.3% 62.5% 70.2% 78.3% 0.75
[0086] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0087] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0088] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
[0089] It should be noted that all information or data obtained and processed in this application are carried out in compliance with relevant national data protection laws and regulations and with authorization from the owner of the relevant device.
Claims
1. A federated contrastive learning method based on a dual-branch network and a global negative sample queue, characterized in that, The method includes the following steps: S1. The server module initializes a global dual-branch model and a global negative sample queue; S2. The server module selects several client modules from all client modules and distributes the current global dual-branch model and global negative sample queue to these client modules. S3. Each client module that receives the global dual-branch model trains the main encoding model and updates the momentum encoding model locally. After completing the training, it uploads the parameter update data of the main encoding model and the local feature representation data to the server module. S4. The server module updates the global bi-branch model based on all parameter update data and updates the global negative sample queue based on all feature representation data. Before the global bi-branch model converges, it jumps to S2.
2. The method according to claim 1, characterized in that, The main encoder model has the same model structure as the global two-branch model, which includes a shared feature encoder, a supervised learning branch, and a contrastive learning branch.
3. The method according to claim 2, characterized in that, The momentum coding model includes a shared feature encoder and a contrastive learning branch projection head MLP.
4. The method according to claim 3, characterized in that, The client module trains the master encoding model locally and updates the momentum encoding model, including the following steps: S311. Set the parameters of the main coding model and the momentum coding model according to the parameters of the received global dual-branch model; S312. Perform weak enhancement processing on the original images in the same batch to obtain the first enhanced image in the same batch, and perform strong enhancement processing on the original images in the same batch twice to obtain the second enhanced image and the third enhanced image in the same batch. S313. Input the first enhanced image, the second enhanced image, and the third enhanced image of the same batch into the shared feature encoder to obtain the first feature vector, the second feature vector, and the third feature vector of the same batch, respectively. S314. Input the first feature vector of the same batch into the supervised learning branch to obtain several classification prediction results, and use the cross-entropy loss function to calculate the supervised loss. Input the second feature vector and the third feature vector of the same batch into the contrastive learning branch to obtain several output feature vector pairs, and calculate the contrastive loss. S315. Assign corresponding weights to the supervised loss and the contrastive loss respectively to calculate the total loss. Update the parameters of the shared feature encoder, the supervised learning branch and the contrastive learning branch through the backpropagation algorithm. Weight the parameters of the main encoding model and the momentum encoding model to update the parameters of the momentum encoding model. S316. Determine if there are other batches of original images that have not been processed. If yes, proceed to S312. If no, continue to determine if the preset number of training rounds has been completed. If no, proceed to S312. If yes, generate parameter update data for the main encoding model and local feature representation data.
5. The method according to claim 4, characterized in that, The calculation of contrastive loss involves: for each pair of output feature vectors, taking one of the output feature vectors as the anchor point, taking the other output feature vector as the positive sample, and taking all other output feature vectors as negative samples. The loss is calculated by combining the global negative sample queue, and the mean of all losses is calculated to obtain the contrastive loss.
6. The method according to claim 4, characterized in that, Generating local feature representation data involves inputting a batch of untrained raw images into the momentum coding model to obtain local feature representation data.
7. The method according to claim 1, characterized in that, The client module uploads the parameter update data of the main encoding model and the local feature representation data to the server module, including the following steps: S321. The client module and the server module securely store shared password 1 and shared password 2 in advance. S322 and the client module generate arbitrary value 1 and arbitrary value 2 respectively. They perform scrambling calculation on arbitrary value 1 and shared secret value 1 to obtain the sending secret value 1, and perform scrambling calculation on arbitrary value 2 and shared secret value 2 to obtain the sending secret value 2. S323, the client module performs mixed processing on any value 1 and any value 2 to obtain the sending secret value 3, uses the sending secret value 3 to encrypt the processing parameters to update the data and feature representation data to obtain encrypted data, and uploads the sending secret value 1, sending secret value 2, and encrypted data to the server module.
8. The method according to claim 7, characterized in that, The module that performs mixed processing on any value 1 and any value 2 to obtain the transmitted secret value 3 includes the following: S3231. Divide any value 1 and any value 2 into the same number of value blocks 1 and value blocks 2 respectively, arrange all value blocks 1 and value blocks 2 to obtain the value block sequence, and set n = 1; S3232. Circularly shift the value block that is a preset distance away from the nth value block in the value block sequence to the left by n bits to obtain the process value block. Perform scrambling calculation on the nth value block and the process value block to obtain a new value block. Determine whether there are other value blocks that have not been processed. If yes, set n = n+1 and repeat this step. If no, continue to S3233. S3233: Sequentially connect each new value block to obtain a new value block sequence, and extract the transmission cipher value 3 from the new value block sequence.