Federal learning optimization method and device and medium
Through the federated learning optimization method of self-supervised learning and KL divergence weight allocation, the problem of global model generalization ability decline caused by uneven data distribution is solved, and the performance of local models and the generalization ability of global models are improved.
Patent Information
- Application Number
- CN202411427351.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-02-25
AI Technical Summary
In the case of uneven data distribution, traditional federated learning methods lead to a decline in the generalization ability of the global model. How to effectively optimize the local model and improve its performance on local data is also an important issue.
The local model is trained through self-supervised learning, and the weights of each participant model are calculated using KL divergence, and weighted aggregation is performed to generate a global model. Specific steps include: inputting medical or financial data, using BYOL comparison learning method to train the local model; calculating the predicted distribution of the model based on the local and public test sets, determining the weight through KL divergence; weight aggregation of the local model to generate a global model.
The generalization ability of the global model in the case of uneven data distribution and the performance of the local model are improved, so that the model can learn more distinctive feature representations from local data without sacrificing data privacy.
Smart Images

Figure CN119514648A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of medical finance and artificial intelligence, and in particular to a federated learning optimization method, device and medium. Background Art
[0002] As the requirements for data privacy protection are increasing, federated learning, as a distributed machine learning method, has received widespread attention. Federated learning trains data locally on each participant and collaboratively builds a global model without sharing the original data. However, traditional federated learning methods face challenges brought about by uneven data distribution. The differences in data distribution among participants lead to a decrease in the generalization ability of the global model, which affects the effect of federated learning. In addition, how to effectively optimize the local model and improve its performance on local data is also an important issue in federated learning.
[0003] Existing federated learning methods usually adopt a simple average aggregation strategy, ignoring the differences in data distribution between different participants. This results in poor performance of the global model when data distribution is uneven, and it cannot adapt well to the local data of each participant. To address this problem, researchers introduced a similarity-based weight allocation strategy, attempting to improve the performance of the global model by giving more weight to participants with higher similarity. However, how to effectively measure the similarity of the participant models and make reasonable weight allocations remains a key issue that needs to be addressed. Summary of the invention
[0004] The federated learning optimization method provided by the present invention solves the problem of how to improve the generalization ability of the global model and the performance of the local model in the case of uneven data distribution in a distributed data environment.
[0005] In order to solve the above problems, the present invention provides a federated learning optimization method, comprising:
[0006] Input medical data or financial data and train local models using self-supervised learning;
[0007] Based on the local test set and the public test set of each participant, the prediction distribution of the local model of each participant after training is calculated, and the weight of the local model of the participant is determined by KL divergence;
[0008] All local models are weighted aggregated to generate a global model.
[0009] Furthermore, the calculation of the prediction distribution of the local model of each participant after training based on the local test set of each participant and the public test set, and the determination of the weight of the local model of the participant by KL divergence, includes:
[0010] Based on the local test set of each participant, the prediction accuracy distribution of each participant's local model after training in each category is calculated to obtain the local prediction distribution;
[0011] Based on the public test set, calculate the prediction accuracy distribution of the trained local model to obtain the public prediction distribution;
[0012] Calculating the KL divergence according to the local prediction distribution and the public prediction distribution;
[0013] The KL divergence is mapped to a similarity interval through an exponential function, and the weight of the local model of each participant is allocated according to the similarity value.
[0014] Furthermore, the weighted aggregation of all local models to generate a global model includes:
[0015] Sorting the local models of all participants according to the similarity values to obtain a similarity list;
[0016] grouping the local models of all participants according to the similarity list;
[0017] Perform weighted aggregation on the local models within each group;
[0018] The models after each group aggregation are summarized to obtain the global model.
[0019] Furthermore, the aggregating of each grouped aggregated model comprises the following steps:
[0020] By calculating the average similarity of each group, the similarity index of the group is obtained;
[0021] Counting the number of local models in each group, and calculating a weight for each group based on the number and the average similarity value;
[0022] The model of each group is weighted according to the weight, and the weighted aggregation results of all groups are summarized to generate the global model.
[0023] Furthermore, after performing weighted aggregation on all local models to generate a global model, the method further includes:
[0024] Synchronize the global model to each participant as the initial model for the next round of training;
[0025] Obtain new local test sets and public test sets of each participant, and calculate the prediction distribution of each participant's local model on the new test sets;
[0026] Based on the new local prediction distribution and the public prediction distribution, the KL divergence of each participant is recalculated, the similarity value of each participant is updated, and the weight of the global model is adjusted according to the new similarity value until the performance of the global model reaches the preset standard.
[0027] Furthermore, the local model includes an online network and a target network, and the input medical data or financial data is used to train the local model using self-supervised learning, including:
[0028] Initialize the baseline CNN model and generate the online network and the target network;
[0029] Acquire an input data set, and use the online network to perform feature extraction on the input data set, wherein the input data set includes the medical data or financial data;
[0030] Performing data enhancement processing on the input data set, and using the target network to perform feature extraction on the enhanced input data set;
[0031] Normalizing the feature representations extracted by the online network and the target network, and calculating the Euclidean distance between the two as a loss function;
[0032] The parameters of the online network and the target network are optimized by the loss function to obtain a trained local model.
[0033] Further, the optimizing the parameters of the online network and the target network by the loss function includes:
[0034] Minimizing the loss function by gradient descent method to update the parameters of the online network;
[0035] According to the updated parameters of the online network, the parameters of the target network are updated by soft updating.
[0036] In order to solve the above technical problems, the embodiment of the present application also provides a federated learning optimization device, which adopts the following technical solution:
[0037] The local model training module is used to input medical data or financial data and train the local model using self-supervised learning;
[0038] A similarity calculation and weight distribution module, used to calculate the prediction distribution of each participant's local model after training based on the local test set and the public test set of each participant, and determine the weight of the local model of the participant through KL divergence;
[0039] Aggregation module, used to perform weighted aggregation on all local models to generate a global model.
[0040] In order to solve the above technical problems, an embodiment of the present application also provides a computer device, which adopts the following technical solution: the computer device includes a memory and a processor, the memory stores computer-readable instructions, and the processor implements the steps of the federated learning optimization method as described in any one of the above when executing the computer-readable instructions.
[0041] In order to solve the above technical problems, an embodiment of the present application also provides a computer-readable storage medium, which adopts the following technical solution: the computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the federated learning optimization method described in any one of the above items are implemented.
[0042] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0043] First, the feature capture capability of the local model is enhanced through self-supervised learning, so that the model can learn more discriminative feature representations from local data without sacrificing data privacy, thereby improving the performance of the local model; secondly, the KL divergence is used to dynamically adjust the aggregation weights, so that those participant models that are closer to the predicted distribution of the global model can play a greater role in the aggregation process, thereby improving the generalization ability of the global model. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 Schematic diagram of a federated learning optimization method provided in an embodiment of the present invention.
[0045] Figure 2 yes Figure 1 A flowchart of a specific implementation of step S100 in FIG.
[0046] Figure 3 yes Figure 1 A flowchart of a specific implementation of step S300 in FIG.
[0047] Figure 4 It is a structural block diagram of a federated learning optimization device provided in an embodiment of the present invention.
[0048] Figure 5 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0049] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0050] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0051] Embodiment 1:
[0052] Reference Figure 1 , is a schematic diagram of a federated learning optimization method provided by an embodiment of the present invention, which is applied to scenarios of medical data analysis and financial risk assessment. The method may at least include steps S100-S300:
[0053] S100. Input medical data or financial data and train a local model using self-supervised learning.
[0054] In this embodiment, the electronic device (e.g. Figure 1 The server / terminal device shown in the figure can obtain the execution log of the target task through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 2G / 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0055] In this embodiment, the self-supervised model is a model trained with unlabeled data. It guides the model to learn the intrinsic structure and characteristics of the data by designing various "pre-training tasks" to improve the performance of the model in downstream tasks. Specifically, this application adopts BYOL (Bootstrap Your OwnLatent) comparative learning method to optimize the performance of the local model.
[0056] BYOL is an innovative self-supervised learning method that aims to learn effective representations of images or other data by training the model using only unlabeled data. The core of this method is that it does not rely on negative sample pairs in traditional contrastive learning, but achieves self-supervised learning by building two interacting networks - the online network and the target network.
[0057] The local model in federated learning is a key component of the federated learning architecture. As a distributed machine learning technology, the core idea of federated learning is to use data distributed on multiple local devices for model training while protecting data privacy. In a federated learning environment, each device participating in the training (such as smartphones, tablets, IoT devices, etc.) has one or more local data sets. Local models are machine learning models trained on these devices using local data sets. These models are trained independently on local devices without uploading the original data to the central server.
[0058] Financial data includes private data such as insurance data, bank data, and order data; medical data includes private data such as personal health records, prescriptions, and examination reports. These data are usually distributed in different financial institutions or medical institutions. Federated learning can enable data from different institutions to be shared and collaborated.
[0059] Specifically, regarding the specific implementation process of using self-supervised learning to train the local model, this application will provide further detailed descriptions in subsequent specific embodiments, and will not be elaborated on here.
[0060] S200. Based on the local test set and the public test set of each participant, the prediction distribution of the trained local model of each participant is calculated, and the weight of the local model of the participant is determined by KL divergence.
[0061] In this embodiment, the process of calculating the prediction distribution of the local model of each participant after training based on the local test set of each participant and the public test set, and determining the weight of the local model of the participant by KL divergence specifically includes the following steps:
[0062] Based on the local test set of each participant, the prediction accuracy distribution of each participant's local model after training in each category is calculated to obtain the local prediction distribution;
[0063] Based on the public test set, calculate the prediction accuracy distribution of the trained local model to obtain the public prediction distribution;
[0064] Calculating the KL divergence according to the local prediction distribution and the public prediction distribution;
[0065] The KL divergence is mapped to a similarity interval through an exponential function, and the weight of the local model of each participant is allocated according to the similarity value.
[0066] Specifically, first, based on the local test set of each participant, the prediction accuracy distribution of each participant's local model in each category is calculated. After training, each participant's local model is based on the local test set D local Evaluate and obtain the predicted probability distribution P for each category i local (i).
[0067]
[0068] Among them, P local (i|x j ) is the local model for sample x j The predicted probability of belonging to category i, |D local | represents the number of samples in the local test set.
[0069] Furthermore, based on the public test set D public , calculate the predicted distribution P on the public test set of all participants total (i) To evaluate the performance difference between each participant’s local model and the global model. The public test set is a standard dataset for global model evaluation, ensuring that all participants are compared on a unified benchmark.
[0070]
[0071] Furthermore, according to each participant’s local prediction distribution P local (i) and the public prediction distribution P total (i) Calculate the difference between the local model of each participant and the global model, and use KL divergence to measure this difference. The KL divergence formula is as follows:
[0072]
[0073] KL divergence is used to evaluate the difference in prediction probabilities between the local model and the global model in different categories. The smaller the KL divergence, the higher the similarity between the local model and the global model.
[0074] Furthermore, the calculated KL divergence value is mapped to the similarity interval [0,1] by an exponential function. The KL divergence value is converted to similarity using the following formula:
[0075]
[0076] The weight is assigned to each participant through the similarity value. The weight formula is:
[0077]
[0078] Among them, similarity i represents the similarity of the ith participant, and m represents the total number of participants. The weight is used for weighted aggregation of the subsequent global model to ensure that local models with higher similarity contribute more to the global model.
[0079] S300: Perform weighted aggregation on all local models to generate a global model.
[0080] In this embodiment, weighted aggregation is a method of merging updates (such as weights, gradients, etc.) from different local models according to certain weights to generate new global model parameters. This method aims to more fairly and effectively integrate contributions from various participants to improve the performance and stability of the global model.
[0081] Weighted aggregation generally includes:
[0082] Uniformly weighted aggregation: The local model updates of all participants are merged with the same weight. This method is suitable for cases where the data volume is balanced and the data distribution is similar, but the effect may not be ideal when the data distribution is uneven.
[0083] Data volume weighted aggregation: weights are assigned based on the amount of data of each participant. The larger the amount of data, the greater the weight of its local model update in the global model. This method is suitable for scenarios where the amount of data of each participant varies greatly.
[0084] Performance-weighted aggregation: Weights are assigned based on the performance of each participant's local model on the local test set. The better the local model, the greater the impact of its update on the global model. This method can ensure model performance while taking into account the differences among participants.
[0085] Similarity weighted aggregation: weights are assigned by calculating the similarity between the local model and the global model. The higher the similarity of the participant, the greater the weight of the local model update. This method can effectively deal with the situation of uneven data distribution.
[0086] In this invention, similarity weighted aggregation is adopted, by calculating KL divergence to evaluate the similarity between the local model of each participant and the global model, and converting it into weights for weighted aggregation of the global model. This method can make full use of the effective data of each participant, improve the accuracy and generalization ability of the global model, and is particularly suitable for scenarios with uneven data distribution.
[0087] Different weighted aggregation methods are suitable for different scenarios and needs. In practical applications, the appropriate weighted aggregation method should be selected according to the specific situation to achieve the best effect. At the same time, the selection of weights is also a key issue in weighted aggregation. Reasonable weight allocation can significantly improve the accuracy and reliability of the aggregation results.
[0088] The present invention uses a similarity weighted aggregation method to integrate the local model updates of each participant with reasonable weights, so that the global model can more fairly and effectively utilize the contributions of each participant in the case of uneven data distribution. The similarity calculated by KL divergence ensures that local models with higher similarity have a greater impact on the global model, thereby improving the generalization ability and stability of the global model.
[0089] The present invention uses self-supervised learning (such as BYOL contrastive learning algorithm) to train the local model, which can learn the effective feature representation of the data without labeled data. This self-supervised learning method guides the model to learn the internal structure of the data by designing pre-training tasks, thereby improving the model's feature extraction ability and training effect in an unlabeled environment. Compared with traditional supervised learning, the present invention can more effectively utilize the unlabeled data sets of each participant and improve the performance of the model in a distributed environment.
[0090] The present invention is based on the local test set and public test set of each participant, calculates the similarity between the local model of each participant and the global model through KL divergence, and allocates the weight of each participant accordingly. This can better measure the contribution of the models of different participants to the global model, especially in the case of uneven data distribution. Through this weight allocation mechanism, the present invention can effectively deal with the impact of differences in the amount of data and data distribution of the participants, and avoid the problem of global model performance degradation caused by uneven data distribution in traditional federated learning.
[0091] Through similarity weighted aggregation, the present invention can integrate model updates from various participants more fairly and effectively. In this aggregation method, local models with higher similarity (i.e., models that are closer to the global model) will be given higher weights, and thus play a greater role in the generation of the global model. This method can significantly improve the generalization ability of the global model, enabling it to better adapt to situations with different data distributions. At the same time, the aggregation method of the present invention also improves the stability of the global model and reduces the model instability problem caused by data heterogeneity.
[0092] The present invention adopts a federated learning framework, and each participant only needs to upload model updates (such as model weights and gradients) to the central server for aggregation, without transmitting local original data. Therefore, the present invention can realize model knowledge sharing among the participants under the premise of protecting the data privacy of the participants, reduce the amount of data transmission, and avoid the risk of data privacy leakage.
[0093] The present invention introduces a similarity weighted aggregation method, which can flexibly allocate weights according to the similarity between the local model of each participant and the global model. In practical applications, the weight allocation mechanism of the present invention can adjust the strategy according to different needs. For example, different methods such as uniform weighting, data volume weighting, and performance weighting can be selected to adapt to different scenarios. The flexibility and diversity of the weight allocation mechanism enable the present invention to achieve good model aggregation effects in a variety of application scenarios.
[0094] Since the present invention takes similarity into consideration when allocating weights, the update of models with higher similarity has a greater impact on the global model when aggregated. Therefore, it is possible to improve the performance of the global model more quickly while reducing the number of iterations, achieve better model accuracy and training effects, and improve training efficiency.
[0095] In some optional implementations, the above step S100 includes steps S110-S150:
[0096] S110, initialize the baseline CNN model and generate the online network and target network.
[0097] The CNN model is a deep learning model that is particularly suitable for feature extraction and pattern recognition of structured data (such as images and videos). In the federated learning environment of the present invention, the CNN model is used as the initial network architecture of the local data set of the participant, responsible for extracting meaningful features from the input data.
[0098] The core components of the CNN model include:
[0099] Convolutional Layer: It is used to extract local features from the input data. Through a set of convolution kernels, the convolutional layer can identify different spatial features, such as edges, corners, etc.
[0100] Pooling Layer: It is used to reduce the spatial dimension of feature maps, retain key information and reduce the amount of calculation. Common pooling operations include maximum pooling and average pooling.
[0101] Fully Connected Layer: Maps high-dimensional feature maps to the output space and ultimately completes predictions for specific tasks, such as classification or regression.
[0102] In the present invention, the CNN model is used as the baseline model, and both the online network and the target network are initialized based on this structure.
[0103] First, each participant uses the baseline CNN model as the initial network architecture for local initialization. The baseline CNN model is responsible for processing the local input data set of the participant. Specifically, two networks are generated during the initialization process, namely the online network and the target network. The two networks have the same structure but have different behaviors during the training process.
[0104] Online network: Initialized with the parameters of the baseline CNN model, responsible for subsequent data feature extraction and optimization. In each round of training, the parameters of the online network are updated using the gradient descent method.
[0105] Target network: maintains the same structure and initialization parameters as the online network, and its parameters remain frozen during training and are not updated. The target network is used to generate stable reference feature representations to help the online network perform comparative learning.
[0106] S120, obtaining an input data set, and performing feature extraction on the input data set using the online network, wherein the input data set includes the medical data or financial data;
[0107] S130, performing data enhancement processing on the input data set, and using the target network to perform feature extraction on the enhanced input data set.
[0108] In this embodiment, the input data set is local data of each participant, and the data may contain samples of different categories.
[0109] Furthermore, the input data set is passed to the online network and the target network for training, but the data input to different networks is different. The original data needs to be enhanced when input to the target network. Through the enhancement method, the scale of the data set can be effectively expanded and the generalization ability of the model can be improved.
[0110] Specifically, a variety of enhancement methods are used, including random cropping, rotation, flipping and other operations, to generate multiple enhanced versions of the input data set to simulate data diversity in different situations.
[0111] Furthermore, the input data set is passed to the online network and the target network for processing respectively, but the input methods are different. The online network receives the original input data, while the target network receives the input data after data enhancement. Through enhancement methods (such as random cropping, rotation, flipping, etc.), the data set size can be effectively expanded and the generalization ability of the model can be improved. For the input sample x, its enhanced version is denoted as x aug1 ,x aug2 ,…, the versions will be input into the online network and the target network respectively.
[0112] The online network generates feature representation z by processing the original input data x on , while the target network processes the input x after data enhancement aug , generate the corresponding target feature representation z tar Through such a design, the online network and the target network can generate different feature representations in different input spaces, thus providing a basis for loss calculation in contrastive learning. This process ensures that the local model can be effectively trained in an unlabeled contrastive learning environment.
[0113] The generated diverse data input enables the online network and the target network to generate different feature representations in different data spaces, thus providing input for subsequent loss calculations. This process ensures that the local model can be effectively trained in an unlabeled contrastive learning environment.
[0114] Specifically, the input local data D local Multiple versions are generated through data enhancement processing. For input data x, its enhanced version is denoted as x aug1 ,x aug2 ,…the data will be input into the online network and the target network respectively.
[0115] The online network processes the input data x 1 ,x 2 ,…generate the corresponding feature representation z on1 ,z on2 ,….
[0116] The target network processes the enhanced version x aug1 ,x aug2 ,…, generate target feature representation z tar1 ,z tar2 ,….
[0117] S140, normalizing the feature representations extracted from the online network and the target network, and calculating the Euclidean distance between the two as a loss function.
[0118] When the input data x1, x2, ..., the enhanced input data xaug1 ,x aug2 ,…are input into the online network and the target network respectively, and the two networks generate feature representations z on and z tar Here, z on represents the feature vector extracted by the online network, and z tar Represents the feature vector of the target network. Furthermore, these two feature representations are L2 normalized.
[0119] The normalized feature representations are recorded as and Its definition is as follows:
[0120]
[0121]
[0122] in,‖·‖ 2 Represents the L2 norm, ensuring that the length of each feature representation is a unit vector.
[0123] Furthermore, after normalization, the feature representations of the online network and the target network can be compared using the Euclidean distance. Specifically, the Euclidean distance d is defined as the loss function:
[0124]
[0125] Among them, L pred is the squared Euclidean distance between the feature representations of the online network and the target network. This distance is used to measure the difference in the feature representations extracted by the two networks.
[0126] S150. Optimizing the parameters of the online network and the target network through the loss function to obtain a trained local model.
[0127] Specifically, the parameters of the online network are optimized by minimizing the Euclidean distance (i.e., loss function) of the feature representation between the online network and the target network. In this process, the online network is updated by the gradient descent method according to the minimization of the loss function, gradually making the feature representation of the online network closer to the feature representation of the target network, and improving the comparative learning ability of the model.
[0128] This application realizes the dynamic update of the online network and the stable reference feature generation of the target network by independently processing the online network and the target network and optimizing the differences in feature representation, which can effectively improve the feature extraction effect of the local model in unsupervised learning tasks.
[0129] The present invention adopts the BYOL (Bootstrap Your Own Latent) contrastive learning algorithm in self-supervised learning, generates multi-view data input by initializing the online network and the target network, and introducing data enhancement processing. The online network processes the original data set, and the target network processes the input data after data enhancement. By comparing the feature representations between the two, the internal structure and features of the data can be effectively captured, thereby improving the feature extraction capability of the model in an unsupervised environment.
[0130] Unlike traditional contrastive learning methods (such as SimCLR), BYOL does not rely on negative samples for training, but learns the potential representation of data by building an online network and a target network. Under this mechanism, even without the participation of negative samples, the model can achieve effective feature learning in the interaction between the online network and the target network, thereby improving the representation ability of the model. This feature enables the present invention to achieve good training results in scenarios with less data or uneven distribution of sample categories.
[0131] The present invention simulates a variety of input samples by performing various data enhancement processing (such as random cropping, rotation, flipping, etc.) on the input data set. By inputting these enhanced data into the target network, the target feature representation can be generated under different perspectives. The Euclidean distance between the feature representation of the online network and the target network is used as a loss function to measure the difference between the two, and by optimizing the loss function, the feature representation of the online network gradually approaches the feature representation of the target network, thereby improving the generalization ability of the model and reducing the risk of overfitting.
[0132] When optimizing the online network parameters, the present invention uses the gradient descent method to minimize the Euclidean distance between the online network and the target network, thereby updating the parameters of the online network. At the same time, the target network parameters are adjusted through a soft update strategy (SoftUpdate) to ensure that the target network can provide a stable feature representation for the online network. This strategy can effectively prevent the target network from fluctuating frequently during the model training process, ensuring the stability and efficiency of the model training.
[0133] During the training process, the present invention dynamically adjusts the parameters of the online network and the target network, so that the model can continuously optimize the feature representation according to the changes in the input data in each iteration. This dynamic adjustment mechanism enhances the robustness of model training, allowing the model to maintain good training results and convergence speed even when the data distribution changes or the sample diversity increases.
[0134] Since the present invention uses self-supervised learning for local model training, it can efficiently complete model training on the local devices of each participant without relying on data labels. In a federated learning environment, this unlabeled training can significantly reduce the cost of data annotation, and even when the data distribution of each participant is different, it can still optimize the training effect of the global model through comparative learning and similarity measurement, thereby improving the generalization ability and stability of the global model.
[0135] In some optional implementations, S150 includes the following steps:
[0136] Minimizing the loss function by gradient descent method to update the parameters of the online network;
[0137] According to the updated parameters of the online network, the parameters of the target network are updated by soft updating.
[0138] In this embodiment, the online network is updated by the gradient descent method. That is, according to the loss function L pred The parameters are updated by minimizing:
[0139]
[0140] Among them, θ on represents the parameters of the online network, η represents the learning rate, It represents the gradient of the loss function to the online network parameters. The purpose is to make the feature representation extracted by the online network gradually approach the feature representation of the target network and improve the comparative learning ability of the model.
[0141] The parameters of the target network θtar\theta_{tar}θtar are not trained directly, but are "soft updated" through the update of the online network. After each update, the parameters of the target network are adjusted according to the following formula:
[0142] θ tar =τθ on +(1-τ)θ tar
[0143] Among them, τ is a hyperparameter less than 1, which controls the update speed of the target network. This soft update mechanism ensures that the target network can always provide a stable reference feature representation, thereby maintaining the effectiveness of contrastive learning.
[0144] By updating the online network through the gradient descent method and adjusting the parameters of the target network in combination with the soft update mechanism, the present invention ensures that the online network can learn the optimal feature representation through continuous iteration, while the target network provides a stable comparison reference, ultimately improving the training effect of the local model and the generalization ability of the global model. This method is particularly suitable for federated learning scenarios, and can more effectively balance the differences in multi-party data and improve the overall model performance.
[0145] By introducing a grouping strategy based on similarity values, the local models of all participants are sorted and grouped according to similarity, so as to perform weighted aggregation within the group, and summarize the aggregation results of each group to generate the final global model. This method can:
[0146] Improve the aggregation effect and stability of the global model: By grouping models with high similarity into a group for aggregation, model updates from different participants can be more effectively integrated, reducing the impact of data heterogeneity on the global model and improving the aggregation effect and stability of the model.
[0147] Reduce the negative impact of uneven data distribution on the global model: The grouping strategy allows the impact of participants with uneven data distribution on the global model to be limited to their respective groups, thereby preventing participants with large data differences from causing excessive interference to the overall performance of the global model.
[0148] Improve the generalization ability of the global model: Through hierarchical weighted aggregation and summarization, the contributions of various participants can be more effectively integrated, thereby improving the generalization ability and performance of the global model in different data distribution scenarios.
[0149] In some optional implementations, S300 includes the following steps:
[0150] S310, obtaining a similarity index of the groups by calculating the average similarity of each group;
[0151] S320, counting the number of local models in each group, and calculating a weight for each group according to the number and the average similarity value;
[0152] S330, weighting the model of each group according to the weight, summarizing the weighted aggregation results of all groups to generate the global model.
[0153] Specifically, the aggregate models in all groups are weighted and aggregated again to generate the final global model. The formula is as follows:
[0154]
[0155] Among them, K represents the number of levels, weight k is the weight of group k, Represents the model parameters after group k aggregation.
[0156] The present invention calculates the average similarity of each group model and the number of models, and assigns a weight to each group, so that when aggregating the group models, it can more accurately reflect the contribution of each group in the global model. This aggregation method can more fairly and effectively integrate the differences within the group, improve the performance of the global model in data heterogeneity scenarios, and reduce the impact of differences between groups on the aggregation effect of the global model.
[0157] In some optional implementations, after step S300, the method further includes:
[0158] Synchronize the global model to each participant as the initial model for the next round of training;
[0159] Obtain new local test sets and public test sets of each participant, and calculate the prediction distribution of each participant's local model on the new test sets;
[0160] Based on the new local prediction distribution and the public prediction distribution, the KL divergence of each participant is recalculated, the similarity value of each participant is updated, and the weight of the global model is adjusted according to the new similarity value until the performance of the global model reaches the preset standard.
[0161] After the global model is generated, the present invention synchronizes it to each participant as the initial model for a new round of local model training, and recalculates the similarity value and weight of each participant after each round of training, thereby dynamically adjusting the model weight and aggregation strategy. Through such iterative optimization, the present invention can continuously improve the performance of the global model, and ultimately ensure that the global model reaches the preset standard after multiple rounds of training, thereby achieving adaptive optimization and performance improvement of the model.
[0162] The following are its main beneficial effects:
[0163] First, the feature capture ability of the local model is enhanced through contrastive learning, so that the model can learn more discriminative feature representations from local data without sacrificing data privacy, thereby improving the performance of the local model; secondly, the KL divergence is used to measure the similarity between the prediction distributions of different participant models, and the aggregation weights are dynamically adjusted accordingly, so that those participant models that are closer to the prediction distribution of the global model can play a greater role in the aggregation process, thereby improving the generalization ability of the global model.
[0164] The present invention is particularly suitable for scenarios of medical data analysis and financial risk assessment. For example, in the medical field, cross-institutional disease prediction can be performed by using data from different institutions to improve local models, thereby improving the accuracy and generalization of disease prediction while protecting data privacy. In cross-institutional medical image analysis, medical image data from different institutions can be fully utilized to improve the performance of the model in processing complex features, biases, and unbalanced data, and enhance the ability to identify rare cases and specific diseases. In the financial field, when risk assessment and prediction are required, such as credit scoring and fraud detection, the contribution of local devices can be weighted and aggregated to ensure greater contribution to devices with better performance, further improving the performance of the risk assessment model.
[0165] Embodiment 2:
[0166] Figure 4 is a structural block diagram of a federated learning optimization device provided by an embodiment of the present invention. The block diagram may include the following modules:
[0167] A local model training module 41, used for inputting medical data or financial data and training a local model using self-supervised learning;
[0168] A similarity calculation and weight distribution module 42, for calculating the prediction distribution of each participant's local model after training based on the local test set of each participant and the public test set, and determining the weight of the local model of the participant through KL divergence;
[0169] The aggregation module 43 is used to perform weighted aggregation on all local models to generate a global model.
[0170] The federated learning optimization device of the present invention includes a local model training module, a similarity calculation and weight distribution module, and an aggregation module, which can realize the complete process from local model training, similarity calculation and weight distribution to the final global model aggregation, ensuring the effective execution and connection of each step of federated learning. The device can effectively improve the training efficiency and accuracy of the global model in the federated learning environment under the premise of ensuring data privacy and distributed training, and is suitable for a variety of distributed data processing scenarios.
[0171] Embodiment three:
[0172] To solve the above technical problems, the present application also provides a computer device. Figure 5 , Figure 5 This is a basic structural block diagram of the computer device in this embodiment.
[0173] The computer device 5 includes a memory 51, a processor 52, and a network interface 53 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 5 with a memory 51, a processor 52, and a network interface 53, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0174] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0175] The memory 51 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 51 can be an internal storage unit of the computer device 5, such as a hard disk or memory of the computer device 5. In other embodiments, the memory 51 can also be an external storage device of the computer device 5, such as a plug-in hard disk equipped on the computer device 5, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 51 can also include both the internal storage unit of the computer device 5 and its external storage device. In this embodiment, the memory 51 is generally used to store the operating system and various application software installed on the computer device 5, such as computer-readable instructions of the data tilt processing method, etc. In addition, the memory 51 can also be used to temporarily store various types of data that have been output or are to be output.
[0176] The processor 52 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 52 is generally used to control the overall operation of the computer device 5. In this embodiment, the processor 52 is used to run computer-readable instructions stored in the memory 51 or process data, such as computer-readable instructions of the federated learning optimization method.
[0177] The network interface 53 may include a wireless network interface or a wired network interface. The network interface 53 is generally used to establish a communication connection between the computer device 5 and other electronic devices.
[0178] The computer device provided in the embodiment of the present application is capable of running each module of the federated learning optimization method.
[0179] Through the computer equipment provided in this application, the various steps of the federated learning optimization method can be executed in parallel on different participating devices, ensuring that model training and aggregation operations can be completed efficiently and securely in a distributed environment, thereby achieving the goals of data privacy protection and global model optimization.
[0180] Embodiment 4
[0181] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the above-mentioned federated learning optimization method.
[0182] The computer-readable storage medium and computer-readable instructions provided in the embodiments of the present application enable the computer device to perform each step of the federated learning optimization by storing the relevant instructions of the federated learning optimization method in the storage medium. Through the description of the above implementation mode, those skilled in the art can clearly understand that the above-mentioned embodiment method can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation mode. Based on this understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), including a number of instructions to enable a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to perform the steps of the federated learning optimization method described in each embodiment of the present application.
[0183] The present invention implements each step of the federated learning optimization method by storing the relevant computer-readable instructions of the federated learning optimization method in a computer-readable storage medium (such as ROM / RAM, disk, CD, etc.) so that these instructions can be executed by at least one processor. The solution can:
[0184] The federated learning optimization method is stored in a computer-readable storage medium in the form of a software product, so that the present invention can be executed on a variety of computing devices (such as mobile phones, computers, servers, etc.), thereby improving the portability and applicability of the solution.
[0185] By storing relevant instructions on computer-readable storage media, the federated learning optimization method can be easily loaded and executed on different hardware platforms, reducing the implementation and deployment costs of the solution.
[0186] Since the solution can store and call instructions in the storage medium, the system can flexibly adjust the steps and details of the solution execution according to actual needs, thereby ensuring the effectiveness and stability of the federated learning optimization method in a variety of data environments.
[0187] This solution can not only be implemented through software, but can also be further optimized in combination with the hardware platform, providing a flexible and efficient implementation method, which significantly reduces the development difficulty and further enhances the application value and industry competitiveness of the federated learning optimization method.
[0188] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to replace some of the technical features therein with equivalents. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
[0189] The non-Company software tools or components appearing in the embodiments of this application are merely examples and do not represent actual use.
Claims
1. A federated learning optimization method, applied to the scenarios of medical data analysis and financial risk assessment, characterized in that: The following steps are involved: Input medical data or financial data and train local models using self-supervised learning; Based on the local test set and the public test set of each participant, the prediction distribution of the local model of each participant after training is calculated, and the weight of the local model of the participant is determined by KL divergence; All local models are weighted aggregated to generate a global model.
2. The federated learning optimization method according to claim 1, characterized in that: The method of calculating the prediction distribution of the local model of each participant after training based on the local test set and the public test set of each participant, and determining the weight of the local model of the participant by KL divergence, includes the following steps: Based on the local test set of each participant, the prediction accuracy distribution of each participant's local model after training in each category is calculated to obtain the local prediction distribution; Based on the public test set, calculate the prediction accuracy distribution of the trained local model to obtain the public prediction distribution; Calculating the KL divergence according to the local prediction distribution and the public prediction distribution; The KL divergence is mapped to a similarity interval through an exponential function, and the weight of the local model of each participant is allocated according to the similarity value.
3. The federated learning optimization method according to claim 2, characterized in that: The weighted aggregation of all local models to generate a global model includes the following steps: Sorting the local models of all participants according to the similarity values to obtain a similarity list; grouping the local models of all participants according to the similarity list; Perform weighted aggregation on the local models within each group; The models after each group aggregation are summarized to obtain the global model.
4. The federated learning optimization method according to claim 3, characterized in that: The aggregating model after each group aggregation includes the following steps: By calculating the average similarity of each group, the similarity index of the group is obtained; Counting the number of local models in each group, and calculating a weight for each group based on the number and the average similarity value; The model of each group is weighted according to the weight, and the weighted aggregation results of all groups are summarized to generate the global model.
5. The federated learning optimization method according to claim 2, characterized in that: After weighted aggregation of all local models to generate a global model, the method further comprises the following steps: Synchronize the global model to each participant as the initial model for the next round of training; Obtain new local test sets and public test sets of each participant, and calculate the prediction distribution of each participant's local model on the new test sets; Based on the new local prediction distribution and the public prediction distribution, the KL divergence of each participant is recalculated, the similarity value of each participant is updated, and the weight of the global model is adjusted according to the new similarity value until the performance of the global model reaches the preset standard.
6. The federated learning optimization method according to any one of claims 1 to 5, characterized in that: The local model includes an online network and a target network. The input medical data or financial data is used to train the local model using self-supervised learning, including the following steps: Initialize the baseline CNN model and generate the online network and the target network; Acquire an input data set, and use the online network to perform feature extraction on the input data set, wherein the input data set includes the medical data or financial data; Performing data enhancement processing on the input data set, and using the target network to perform feature extraction on the enhanced input data set; Normalizing the feature representations extracted by the online network and the target network, and calculating the Euclidean distance between the two as a loss function; The parameters of the online network and the target network are optimized by the loss function to obtain a trained local model.
7. The federated learning optimization method according to claim 6, characterized in that: Optimizing the parameters of the online network and the target network by using the loss function comprises the following steps: Minimizing the loss function by gradient descent method to update the parameters of the online network; According to the updated parameters of the online network, the parameters of the target network are updated by soft updating.
8. A federated learning optimization device, characterized in that: include: The local model training module is used to input medical data or financial data and train the local model using self-supervised learning; A similarity calculation and weight distribution module, used to calculate the prediction distribution of each participant's local model after training based on the local test set and the public test set of each participant, and determine the weight of the local model of the participant through KL divergence; Aggregation module, used to perform weighted aggregation on all local models to generate a global model.
9. A computer device, characterized in that: It includes a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the federated learning optimization method as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the federated learning optimization method according to any one of claims 1 to 7.
Citation Information
Cited By
Fishery intelligent monitoring analysis and dynamic optimization method based on federated learning
CN120409625A
A fishery intelligent monitoring analysis and dynamic optimization method based on federated learning
CN120409625B