Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The embodiment of the application provides a federated learning modeling optimization method, which is applied to a first device, and in the first embodiment of the federated learning modeling optimization method, referring to fig. 1, the federated learning modeling optimization method includes:
step S10, acquiring a trained feature extraction model and a classification model, and extracting a first training sample, first noise data and a first real classification label corresponding to the first training sample;
in this embodiment, it should be noted that the federal learning modeling optimization method is applied to a federal learning scenario, the federal learning scenario may be a horizontal federal learning scenario, the first device is a party involved in federal learning, the second device is a federal server involved in federal learning, the feature extraction model and the classification model are local models that are locally iteratively trained on the first device, the first noise data is used to be mixed with the first real classification label as an input of the feature generation model to be trained, and even if the second device reversely pushes the privacy data of the party according to the trained feature generation model, the obtained privacy data is also a mixture of the first noise data and the first real classification label, the first real classification label of the party cannot be obtained, and the leakage risk of the first real classification label can be reduced.
In addition, the process of local iterative training of the feature extraction model and the classification model is as follows:
extracting a local training sample and a local classification label corresponding to the local training sample, then enabling the local training sample to sequentially pass through a feature extraction model to be trained and a classification model to be trained to obtain a training output classification label, further calculating model loss according to the training output classification label and the local classification label corresponding to the local training sample, if the model loss is converged, taking the feature extraction model to be trained as a feature extraction model and taking the classification model to be trained as a classification model, if the model loss is not converged, updating the feature extraction model to be trained and the classification model to be trained according to a model gradient calculated by the model loss, and returning to the execution step: and extracting local training samples and local classification labels corresponding to the local training samples.
Step S20, obtaining a first sample feature generated by the feature extraction model for the first training sample, and a second sample feature generated by the feature generation model to be trained for the first noise data and the first real classification label;
in this embodiment, specifically, feature extraction is performed on the first training sample according to the feature extraction model to obtain a first sample feature, a model is generated according to a feature to be trained, and the first noise data and the first real classification label are jointly converted into a second sample feature.
Step S30, performing feature discrimination on the first sample feature and the second sample feature through a feature discrimination model to be trained, and iteratively optimizing the feature generation model to be trained under the condition of fixing the feature extraction model to obtain a feature generation model;
in this embodiment, specifically, according to a feature identification model to be trained, feature identification is performed on the first sample feature and the second sample feature respectively to determine whether the first sample feature and the second sample feature are from a feature generation model or a feature extraction model, so as to obtain a feature identification prediction label, further, according to the feature identification prediction label and a feature identification real label corresponding to the first sample feature and the second sample feature together, a feature identification loss is calculated, and according to the feature identification loss, the feature generation model to be trained is iteratively updated under the condition that the feature extraction model is fixed, so as to obtain a feature generation model. Fig. 2 is a schematic flow chart of a first device building a feature generation model in an embodiment of the present application, where x is the first training sample, i.e., data, z is the first noise data, i.e., noise, y is the first real classification label, i.e., label, f is the first sample feature, g is the second sample feature,

discriminating the predictive label for a feature, L
ganA loss is identified for the feature.
The step of iteratively updating the feature generation model to be trained under the condition of fixing the feature extraction model according to the feature discrimination loss to obtain the feature generation model comprises the following steps:
judging whether the characteristic discrimination loss is converged, if so, taking a characteristic generation model to be trained as the characteristic generation model, if not, fixing the characteristic extraction model unchanged, updating the characteristic generation model to be trained and the characteristic discrimination model to be trained according to the model gradient calculated by the characteristic discrimination loss, and returning to the execution step: and extracting a first training sample, first noise data and a first real classification label corresponding to the first training sample so as to carry out next round of model training iteration.
The step of performing feature discrimination on the first sample feature and the second sample feature through a feature discrimination model to be trained, and iteratively optimizing the feature generation model to be trained under the condition of fixing the feature extraction model to obtain a feature generation model includes:
step S31, performing feature discrimination on the first sample feature and the second sample feature through the feature discrimination model to be trained, and calculating feature discrimination loss;
in this embodiment, it should be noted that the feature discrimination loss may be a cross entropy loss or a counternetwork loss.
Specifically, according to a feature discrimination model to be trained, feature discrimination is performed on the first sample feature and the second sample feature respectively to obtain a first feature discrimination prediction result corresponding to the first sample feature and a second feature discrimination prediction result corresponding to the second sample feature, and then a feature discrimination loss is calculated according to the first feature discrimination prediction result, the first feature discrimination real label corresponding to the first sample feature, the second feature discrimination prediction result, and the second feature discrimination real label corresponding to the second sample feature.
In addition, if the feature discrimination loss generates a countering network loss, the feature discrimination loss needs to be calculated according to a preset generated countering network loss function, where the preset generated countering network loss function is as follows:
v is the generation countermeasure network loss, G represents the feature generation model to be trained, D represents the feature discrimination model to be trained, Q represents the feature extraction model, and x-PdataRepresents the firstA training sample, z represents the first noise data and the first real classification label, q (x) represents the first sample feature, g (z) represents the second sample feature, the first feature discrimination real label is 1, the second feature discrimination real label is 0, and further the feature to be trained generation model and the feature to be trained discrimination model are optimized through the feature discrimination loss, so that the loss of the feature to be trained generation model can be maximized and the loss of the feature to be trained discrimination model can be minimized, wherein the first feature discrimination prediction result is the probability that the first sample feature is generated by a feature extraction model, and the second feature discrimination prediction result is the probability that the second sample feature is generated by a feature extraction model.
The step of calculating the characteristic discrimination loss comprises the following steps of performing characteristic discrimination on the first sample characteristic and the second sample characteristic through the characteristic discrimination model to be trained:
step S311, according to the feature discrimination model to be trained, performing secondary classification on the first sample feature and the second sample feature respectively to obtain a secondary classification result;
in this embodiment, it should be noted that the feature identification model to be trained is a binary classification model, and is used to perform binary classification on the sample features, and determine whether the sample features are from the feature generation model or the feature extraction model, that is, whether the sample features are from the real sample or from the mixed fictive sample composed of noise and labels, for example, it is assumed that the real binary classification labels (positive and negative sample labels) are labels 0 and 1, respectively, where 0 represents the corresponding sample feature as the output of the feature generation model, 1 represents the corresponding sample feature as the output of the feature extraction model, and the output of the feature identification model may be represented as a probability value of the corresponding sample feature as the output of the feature extraction model.
Specifically, according to the feature discrimination model to be trained, the first sample feature and the first sample feature are respectively subjected to second classification to respectively discriminate whether the first sample feature and the second sample feature come from the feature discrimination model to be trained or from the feature extraction model, so as to obtain a first second-class prediction label corresponding to the first sample feature and a second-class prediction label corresponding to the second sample feature, where the second classification result includes the first second-class prediction label corresponding to the first sample feature and the second-class prediction label corresponding to the second sample feature.
Step S312, calculating the feature discrimination loss according to the two classification results and the positive and negative sample labels corresponding to the first sample feature and the second sample feature.
In this embodiment, it should be noted that the positive and negative sample labels include a positive sample label corresponding to the first sample feature and a negative sample label corresponding to the second sample feature.
Specifically, feature discrimination loss is calculated according to the difference between the first binary prediction label and the positive sample label and the difference between the second binary prediction label and the negative sample label.
Step S32, according to the characteristic discrimination loss, the characteristic discrimination model to be trained and the characteristic generation model to be trained are iteratively updated under the condition that the characteristic extraction model is fixed, so as to optimize the characteristic generation model to be trained, and obtain the characteristic generation model.
In this embodiment, specifically, whether the feature discrimination loss converges is determined; if the feature generation model is converged, taking the feature generation model to be trained as the feature generation model; if not, updating the feature discrimination model to be trained and the feature generation model to be trained according to the model gradient calculated by the feature discrimination loss, and returning to the execution step: and extracting a first training sample, first noise data and a first real classification label corresponding to the first training sample.
Step S40, sending the feature generation model and the classification model to a second device, so that the second device iteratively optimizes and aggregates a global classification model obtained from each of the classification models according to the feature generation model sent by each of the first devices, and iteratively optimizes and aggregates a global feature generation model obtained from each of the feature generation models according to the classification model sent by each of the first devices, thereby obtaining a target global feature generation model and a target global classification model;
in this embodiment, specifically, the feature generation model and the classification model are sent to a second device, and then the second device aggregates the feature generation models sent by each first device to obtain a global feature generation model, and aggregates the classification models sent by each first device to obtain a global classification model, and then under the condition that each feature generation model is fixed, the output of each feature generation model is classified according to the global classification model, a first global classification loss is calculated, and then the global classification model is iteratively optimized according to the first global classification loss to prompt the global classification model to indirectly learn knowledge of all first devices through all feature generation models, so as to obtain a target global classification model; under the condition of fixing each classification model, classifying the output of the global feature generation model according to each classification model respectively, calculating a second global classification loss, and further iteratively optimizing the global feature generation model according to the second global classification loss so as to enable the global feature generation model to indirectly learn the knowledge of all the first devices through all the classification models, thereby obtaining a target global feature generation model, wherein the specific process of constructing the target global feature generation model and the target global classification model by the second device can refer to the specific contents in the following steps D10 to D40, which are not described in detail herein, wherein the second device does not directly possess the feature extraction model but possesses the feature generation models of all the participants, and the input of the feature generation model is a mixed fictional sample of noise data and labels, furthermore, even if the second device performs reverse deduction according to the feature generation model, only the label mixed with the noise data can be obtained, and the specific label and the specific sample owned by the first device cannot be deduced reversely, so that the data privacy of the first device can be protected.
In addition, under the condition that each feature generation model is fixed, the output of each feature generation model is classified according to the global classification model, a first global classification loss is calculated, then the global classification model is iteratively optimized according to the first global classification loss to obtain a target global classification model, and then the target global classification model is matched with all the feature generation models, namely the target global classification model can make accurate classification decisions for the output of all the feature generation models, so that the target global classification model carries the classification model knowledge of all the first equipment; since the output of the global feature generation model is classified according to each classification model under the condition that each classification model is fixed, a second global classification loss is calculated, further, the global feature generation model is iteratively optimized according to the second global classification loss to obtain a target global feature generation model, and then the target global feature generation model is matched with all the classification models, namely, each classification model can make accurate classification decision for the output of the target global feature generation model, the target global feature generation model carries knowledge of the feature generation models of all the first devices, further realizing the purpose of aggregating the feature generation model knowledge of all federal participants to a target global feature generation model, and aggregating the classification model knowledge of all federal participants to a target global classification model.
Step S50, receiving the target global feature generation model and the target global classification model fed back by the second device, and iteratively optimizing the feature extraction model and the classification model according to the target global feature generation model and the target global classification model to obtain a target feature extraction model and a target classification model.
In this embodiment, specifically, a target global feature generation model and a target global classification model fed back by the second device are received, and the feature extraction model and the classification model are iteratively optimized according to the target global feature generation model and the target global classification model, so as to enable the feature extraction model to learn the model knowledge of the target global feature generation model, and enable the classification model to learn the model knowledge of the target global classification model, thereby obtaining the target feature extraction model and the target classification model.
Additionally, as each classification model can make an accurate classification decision for the output of the target global feature generation model, the target global feature generation model learns the output feature distribution (global sample feature distribution) of all the feature extraction models, the first device iteratively optimizes the feature extraction models and the classification models according to the target global classification model and the target global feature generation model, the local feature extraction model of the first device can learn the global sample feature distribution, and the local classification model can learn the global classification model knowledge, so that the purpose of sharing knowledge by federal participants is realized, and the federal learning modeling is realized. Meanwhile, the feature discrimination model ensures that the output of the feature generation model and the output of the feature extraction model have certain difference, and even if the second equipment reversely deduces the private data of the first equipment by using the feature generation model, only a mixed construction sample of noise data and a label can be obtained, but not a training sample.
The step of iteratively optimizing the feature extraction model and the classification model according to the target global feature generation model and the target global classification model to obtain a target feature extraction model and a target classification model comprises:
step S51, performing knowledge distillation between the classification model and the target global classification model to optimize the classification model and obtain the target classification model;
and step S52, performing knowledge distillation between the feature extraction model and the target global feature generation model to optimize the feature extraction model to obtain the target feature extraction model.
In this embodiment, specifically, in the case of fixing the target global feature generation model, knowledge distillation is performed between the classification model and the target global classification model to cause the classification model to learn the model knowledge of the target global classification model to obtain the target classification model, and in the case of fixing the target global classification model, knowledge distillation is performed between the feature extraction model and the target global feature generation model to cause the feature extraction model to learn the model knowledge of the target global feature generation model to obtain the target feature extraction model.
In addition. Fig. 3 is a schematic flowchart illustrating a process of constructing a target feature extraction model and a target classification model by a first device in an embodiment of the present application, where x is the first training sample, i.e., data, z is the first noise data, i.e., noise, y is the first real classification label, i.e., label, f is the first sample feature, g is the second sample feature,
in order to output the feature discrimination model,
for the output of the classification model, L
ganDiscriminating loss for said global feature, L
taskIs the global classification penalty.
Additionally, it should be noted that, in order to protect data privacy in federal learning, federal learning may be performed in a homomorphic encryption environment at present, however, computation overhead involved in homomorphic encryption is extremely large, and data involved in the first device and the second device in the embodiment of the present application is plaintext data, so that the computation overhead is significantly reduced compared with a mode of federal learning based on homomorphic encryption, and thus, the efficiency of federal learning is improved. In addition, in order to protect data privacy in federal learning, federal learning can be performed based on multi-party safety calculation at present, however, calculation overhead and communication overhead involved in multi-party safety calculation are extremely large, and data involved in the first device and the second device in the embodiment of the application are all complete plaintext data and do not involve a secret sharing process in multi-party safety calculation, so that compared with a mode of performing federal learning based on multi-party safety calculation, calculation overhead and communication overhead are obviously reduced, and the efficiency of federal learning is improved; in addition, in order to protect data privacy in federal learning, currently federal learning can be performed based on differential privacy, but the differential privacy needs to realize privacy protection by adding noise, which affects usability and accuracy of the model, but the embodiment of the application obviously does not directly add noise in the feature extraction model and the classification model, and only inputs the feature generation model together with noise data and a tag to simulate the output of the feature extraction model, so that the accuracy and the availability of the feature extraction model and the classification model are not affected, and the usability and the accuracy of the federal learning model are improved compared with the federal learning mode based on the differential privacy.
In addition, the federal learning modeling optimization method can be used in the field of image processing, and further comprises the following steps:
step Q10, acquiring a trained image feature extraction model and an image classification model, and extracting a first training image sample, first image noise data and a first real image classification label corresponding to the first training image sample;
step Q20, obtaining a first image sample feature generated by the image feature extraction model for the first training image sample, and a second image sample feature generated by the image feature generation model to be trained for the first image noise data and the first real image classification label;
step Q30, performing feature discrimination on the first image sample feature and the second image sample feature through an image feature discrimination model to be trained, and iteratively optimizing the image feature generation model to be trained under the condition of fixing the image feature extraction model to obtain an image feature generation model;
step Q40, sending the image feature generation model and the image classification model to a second device, so that the second device can generate a global image classification model obtained by iteratively optimizing and aggregating the image classification models according to the image feature generation model sent by each first device, and iteratively optimize and aggregate the global image feature generation model obtained by each image feature generation model according to the image classification model sent by each first device, so as to obtain a target global image feature generation model and a target global image classification model;
and step Q50, receiving the target global image feature generation model and the target global image classification model fed back by the second device, and iteratively optimizing the image feature extraction model and the image classification model according to the target global image feature generation model and the target global image classification model to obtain a target image feature extraction model and a target image classification model.
In this embodiment, it should be noted that the feature extraction model may be an image feature extraction model, the classification model may be an image classification model, the first training sample may be a first training image sample, the first noise data may be first image noise data, the first real classification label may be a first real image classification label, the feature generation model to be trained may be an image feature generation model to be trained, the second sample feature may be a second image sample feature, the feature discrimination model to be trained may be an image feature discrimination model to be trained, the feature generation model may be an image feature generation model, the target global feature generation model may be a target global image feature generation model, and the target global classification model may be a target global image classification model, the target feature extraction model may be a target image feature extraction model, and the target classification model may be a target image classification model. The detailed implementation of steps Q10 through Q50 can refer to the contents of steps S10 through S50, and will not be described herein again.
The embodiment of the application provides a method for constructing an image feature extraction model and an image classification model based on federal learning, which comprises the steps of firstly obtaining a trained image feature extraction model and an image classification model, extracting a first training image sample, first image noise data and a first real image classification label corresponding to the first training image sample, further obtaining a first image sample feature generated by the image feature extraction model aiming at the first training image sample and a second image sample feature generated by an image feature generation model aiming at the first image noise data and the first real image classification label, further carrying out feature discrimination on the first image sample feature and the second image sample feature through an image feature discrimination model to be trained, and iteratively optimizing the image feature generation model to be trained under the condition of fixing the image feature extraction model, and obtaining an image feature generation model. That is, a generation countermeasure network is formed between the image feature generation model and the image feature discrimination model, so that the image feature generation model can accurately convert the first image noise data and the first real image classification label into image sample features, the purpose of constructing the image feature generation model with the same function of outputting the image sample features as the image feature extraction model is achieved, and meanwhile, the image feature generation model is not directly constructed according to original image sample data of a participant. Further, the image feature generation model and the image classification model are sent to a second device, so that the second device generates a model according to the image features sent by each first device, iteratively optimizes and aggregates a global image classification model obtained by each image classification model, and iteratively optimizes and aggregates a global image feature generation model obtained by each image feature generation model according to the image classification model sent by each first device, so that the global image classification model can learn knowledge from all federal participants, and iteratively optimizes and aggregates a global image feature generation model obtained by each image feature generation model according to the image classification model sent by each first device, so that the global image feature generation model can learn knowledge from all federal participants, and the purpose of sharing knowledge of all federal participants is achieved, and obtaining a target global image feature generation model and a target global image classification model. And then receiving a target global image feature generation model and a target global image classification model fed back by the second device, and iteratively optimizing the image feature extraction model and the image classification model according to the target global image feature generation model and the target global image classification model, so that the image feature extraction model and the image classification model can learn the knowledge of all participants in the target global image feature generation model and the target global image classification model, and the target image feature extraction model and the target image classification model are obtained. The method and the device achieve the purpose of sharing knowledge of all the participants through the global model, do not reveal local original sample data, and reduce the risk that each participant reveals own original image sample data while achieving the construction of the image feature extraction model and the image classification model based on the federal learning. The problem of data island in the process of constructing the image feature extraction model and the image classification model is solved, and the accuracy of the image feature extraction model and the image classification model is improved while the data privacy of the original image sample data of each party is protected.
Compared with the image processing model (an image feature generation model and an image classification model) constructed in a federal learning mode based on homomorphic encryption, the calculation overhead is obviously reduced, and the efficiency of constructing the image processing model based on the federal learning is improved. Compared with the image processing model constructed in a federal learning mode based on multi-party safety calculation, the calculation overhead and the communication overhead are obviously reduced, and the efficiency of constructing the image processing model based on federal learning is improved; compared with the image processing model constructed based on the difference privacy in the federal learning mode, the image processing model constructed based on the federal learning mode is obviously improved in the embodiment of the application without directly adding noise in the image feature extraction model and the image classification model, and only the noise data and the label are input into the image feature generation model together to simulate the output of the image feature extraction model, so that the accuracy and the usable rows of the image feature extraction model and the image classification model are not affected, and the usability and the accuracy of the image processing model constructed based on the federal learning mode are improved.
The embodiment of the application provides a federated learning modeling optimization method, and compared with the prior art, each participant maintains a local model and a global model in a federated learning scene. According to the technical means that all participants learn local peculiar knowledge through a local model, share the knowledge of all the participants through a global model, and then combine the local model and the global model, the embodiment of the application firstly obtains a trained feature extraction model and a classification model, extracts a first training sample, first noise data and a first real classification label corresponding to the first training sample, further obtains a first sample feature generated by the feature extraction model aiming at the first training sample and a second sample feature generated by a to-be-trained feature generation model aiming at the first noise data and the first real classification label, further carries out feature discrimination on the first sample feature and the second sample feature through the to-be-trained feature discrimination model, and iteratively optimizes the to-be-trained feature generation model under the condition of fixing the feature extraction model, obtaining a feature generation model, namely, forming a generation countermeasure network between the feature generation model and the feature discrimination model, so that the feature generation model can accurately convert the first noise data and the first real classification label into sample features, achieving the purpose of constructing the feature generation model with the same function of outputting the sample features as the feature extraction model, and meanwhile, the feature generation model is not directly constructed according to the original sample data of the participators, and further sending the feature generation model and the classification model to the second equipment, so that the second equipment generates the model according to the features sent by each first equipment, iteratively optimizes and aggregates the global classification model obtained by each classification model, so that the global classification model can learn knowledge from all federal participators, and according to the classification model sent by each first equipment, iteratively optimizing a global feature generation model obtained by aggregating each feature generation model so that the global feature generation model can learn knowledge from all federal participants, and the purpose of sharing the knowledge of all federal participants is achieved, so as to obtain a target global feature generation model and a target global classification model, wherein the feature generation model is not directly constructed according to original sample data of the participants, so that the second equipment cannot reversely push the original sample data of the first equipment, and further receives the target global feature generation model and the target global classification model fed back by the second equipment, and iteratively optimizing the feature extraction model and the classification model according to the target global feature generation model and the target global classification model, so that the feature extraction model and the classification model can learn the knowledge of all participants in the target global feature generation model and the target global classification model, and then obtaining a target feature extraction model and a target classification model, realizing the purpose of prompting a local model to learn the model knowledge of a global model, namely realizing the purpose of sharing the knowledge of all participants through the global model, and simultaneously not revealing local original sample data, so that the technical defect that a federal server can reversely deduce the original data of the participants through the global model of each participant, so that the risk of data disclosure is present is overcome, and the risk of revealing the privacy data of the participants in federal learning is reduced.
Further, referring to fig. 4, based on the first embodiment of the present application, in another embodiment of the present application, the step of iteratively optimizing the feature extraction model and the classification model according to the target global feature generation model and the target global classification model to obtain a target feature extraction model and a target classification model includes:
step A10, taking the target global classification model as a new classification model and the target global feature generation model as a new feature generation model, and extracting a second training sample, second noise data and a second real classification label corresponding to the second training sample;
in this embodiment, specifically, the classification model is directly replaced with a target global classification model to obtain a new classification model, the feature generation model is directly replaced with a target global feature generation model to obtain a new feature generation model, and a second training sample, second noise data, and a second real classification label corresponding to the second training sample are extracted.
Step A20, extracting the features of the second training sample according to the feature extraction model to obtain a third sample feature, generating a model according to the new features, and converting the second noise data and the second real classification label into a fourth sample feature together;
step a30, classifying the third sample features through the new classification model, performing feature discrimination on the third sample features and the fourth sample features through the feature discrimination model, and iteratively optimizing the new classification model and the feature extraction model to obtain the target feature extraction model and the target classification model.
In this embodiment, specifically, the third sample feature is classified according to the new classification model to calculate a global classification loss, and the third sample feature and the fourth sample feature are respectively subjected to feature discrimination according to a feature discrimination model to calculate a global feature discrimination loss, so that the new classification model is iteratively optimized according to a model gradient calculated by the global classification loss to obtain a target classification model, and the feature extraction model is iteratively optimized according to a model gradient calculated by both the global classification loss and the global feature discrimination loss to obtain a target feature extraction model.
Wherein, the classifying the third sample feature by the new classification model, performing feature discrimination on the third sample feature and the fourth sample feature by the feature discrimination model, and iteratively optimizing the new classification model and the feature extraction model to obtain the target feature extraction model and the target classification model include:
step A31, if the target global classification model and the target global feature generation model meet preset federal iteration end conditions, classifying the third sample features through the new classification model, performing feature discrimination on the third sample features and the fourth sample features through the feature discrimination model, and iteratively optimizing the new classification model and the feature extraction model to obtain the target feature extraction model and the target classification model;
step a32, if the target global classification model and the target global feature generation model do not satisfy a preset federal iteration end condition, classifying the third sample feature by the new classification model, performing feature discrimination on the third sample feature and the fourth sample feature by the feature discrimination model, iteratively optimizing the new classification model and the feature extraction model, and returning to the execution step: and extracting a first training sample, first noise data and a first real classification label corresponding to the first training sample.
In this embodiment, specifically, if receiving a federate learning modeling end notification sent by a second device, it is determined that the target global classification model and the target global feature generation model satisfy a preset federate iteration end condition, and then classify the third sample feature by the new classification model, and perform feature discrimination on the third sample feature and the fourth sample feature by the feature discrimination model, iteratively optimize the new classification model and the feature extraction model to obtain the target feature extraction model and the target classification model, if the federate learning modeling end notification sent by the second device is not received, it is determined that the target global classification model and the target global feature generation model do not satisfy the federate preset iteration end condition, and then classify the third sample feature by the new classification model, and performing feature discrimination on the third sample feature and the fourth sample feature through the feature discrimination model, iteratively optimizing the new classification model and the feature extraction model, and returning to the execution step: and extracting a first training sample, first noise data and a first real classification label corresponding to the first training sample so as to perform the next round of federal learning iteration.
Wherein, the classifying the third sample feature by the new classification model, performing feature discrimination on the third sample feature and the fourth sample feature by the feature discrimination model, and iteratively optimizing the new classification model and the feature extraction model to obtain the target feature extraction model and the target classification model include:
step C10, classifying the third sample characteristics through the new classification model, and calculating the global classification loss;
in this embodiment, specifically, the third sample features are classified according to the new classification model to obtain a classification result, and a global classification loss is calculated through a preset loss function according to a difference between the classification result and the second real classification label, where the preset loss function may be an L2 loss function or a cross entropy loss function.
Step C20, performing feature discrimination on the third sample feature and the fourth sample feature through the feature discrimination model, and calculating global feature discrimination loss;
in this embodiment, it should be noted that the global feature discrimination loss may be a cross entropy loss or a generation countermeasure network loss, where the specific calculation process for generating the countermeasure network loss may refer to the specific content in the step S31, and is not described herein again.
Specifically, according to the feature discrimination model, feature discrimination is performed on the third sample feature and the fourth sample feature respectively to obtain a third feature discrimination prediction label corresponding to the third sample feature and a fourth feature discrimination prediction label corresponding to the fourth sample feature, and then a global feature discrimination loss is calculated according to a difference between the third feature discrimination prediction label and the feature discrimination real label corresponding to the third sample feature and a difference between the third feature discrimination prediction label and the feature discrimination real label corresponding to the fourth sample feature.
Step C30, iteratively updating the feature extraction model, the new classification model, the new feature generation model and the feature discriminant model according to the global classification loss and the global feature discriminant loss to optimize the feature extraction model and the new classification model, thereby obtaining the target feature extraction model and the target classification model.
In this embodiment, specifically, whether the global classification loss and the global feature discrimination loss are both converged is determined, if both are converged and a federal learning end notification is received, the feature extraction model is used as a target feature extraction model and the new classification model is used as a target classification model, and if both are converged and a federal learning end notification is not received, the new feature generation model and the new classification model are sent to a second device for the next round of federal learning modeling iteration; if not, updating the new classification model according to the model gradient calculated by the global classification loss relative to the new classification model; updating the feature extraction model according to a model gradient calculated by the global classification loss and the global feature discrimination loss together relative to the feature extraction model; updating the feature discrimination model according to the model gradient calculated by the global feature discrimination loss relative to the feature discrimination model; updating the new feature generation model according to the model gradient calculated by the feature discrimination model relative to the new feature generation model, and returning to the execution step: and extracting a second training sample, second noise data and a second real classification label corresponding to the second training sample so as to carry out the next round of model training iteration.
The embodiment of the application provides a feature extraction model and a method for optimizing a classification model, that is, firstly, the target global classification model is used as a new classification model and the target global feature generation model is used as a new feature generation model, a second training sample, second noise data and a second real classification label corresponding to the second training sample are extracted, further, feature extraction is performed on the second training sample according to the feature extraction model to obtain a third sample feature, the second noise data and the second real classification label are jointly converted into a fourth sample feature according to the new feature generation model, further, the third sample feature is classified through the new classification model, and feature discrimination is performed on the third sample feature and the fourth sample feature through the feature discrimination model, iterative optimization is carried out on the new classification model and the feature extraction model, so that the new classification model can be matched with new feature generation and feature extraction models, model knowledge of a target global feature generation model is learned by the feature extraction model, the purpose of sharing the classification model knowledge and the feature generation model knowledge of all federal participants is achieved, the feature extraction model and the classification model are built based on federal learning, and at the same time, the federal learning modeling is not carried out through a direct aggregation feature extraction model, so that the data privacy of the federal participants can be protected.
Further, referring to fig. 5, in another embodiment of the present application, the federal learning modeling optimization method is applied to a second device, and the federal learning modeling optimization method includes:
step D10, receiving the feature generation models and the classification models sent by each first device, aggregating each feature generation model into a global feature generation model and aggregating each classification model into a global classification model;
step D20, extracting noise data and real classification labels corresponding to the noise data;
in this embodiment, it should be noted that the aggregation manner includes averaging, weighted summation, and the like. Each first device needs to maintain a feature generation model and a classification model, wherein the feature generation model is a model for simulating output features of a corresponding feature extraction model according to noise data and a real classification label, the output features of the feature extraction model are model output results obtained by performing feature extraction on samples corresponding to the real classification label, and the output of the feature generation model and the output of the feature extraction model can be distinguished by a feature distinguishing model. And for the same sample, the corresponding noise and the label, the output of the feature generation model and the output of the corresponding feature extraction model can generate the same classification label through a classification model. The specific process of constructing the feature generation model by the first device may refer to the specific contents in the above step S10 to step S30, and is not described herein again.
Step D30, according to the noise data and the real classification labels, iteratively optimizing the global classification model under the condition of fixing each feature generation model to obtain a target global classification model;
in this embodiment, specifically, according to each feature generation model, each real classification label of the noise data is converted into a sample feature together, so as to obtain a local sample feature output by each feature generation model, and then a local prediction classification label obtained by classifying each local sample feature through the global classification model and the real classification label are used to calculate a first target loss, and then the global classification model is iteratively optimized under the condition of fixing each feature generation model according to the first target loss, so as to obtain a target global classification model, wherein the global classification model is iteratively optimized under the condition of fixing each feature generation model, so as to enable the global classification model to be adapted to each feature generation model, and further indirectly enable the global classification model to learn the classification model knowledge of all participating parties, and further, the aim of constructing a target global classification model with global classification model knowledge is fulfilled.
Wherein, the step of iteratively optimizing the global classification model under the condition of fixing each feature generation model according to the noise data and the real classification label to obtain a target global classification model comprises:
step D31, generating a model according to each feature, and converting the noise data and the real classification label into corresponding local sample features together;
step D32, classifying the local sample features respectively according to the global classification model to obtain local prediction classification labels;
step D33, calculating a first target loss according to the difference degree between each local prediction classification label and the real classification label;
and D34, iteratively optimizing the global classification model under the condition of fixing each feature generation model according to the first target loss to obtain the target global classification model.
In this embodiment, specifically, the noise data and the real classification label are converted into corresponding local sample features together according to each feature generation model; classifying the local sample characteristics respectively according to the global classification model to obtain local prediction classification labels; calculating local classification losses corresponding to the local prediction classification labels according to the difference between each local prediction classification label and the real classification label, and further aggregating the local classification losses to obtain the first target loss, wherein the aggregation mode comprises averaging, weighted summation and the like, and further updating the global classification model according to a model gradient calculated by the first target loss under the condition that each feature generation model is fixed, and judging whether the global classification model reaches a preset model iteration updating frequency or not, if so, taking the global classification model as a target global classification model, and if not, returning to the execution step: and extracting noise data and a real classification label corresponding to the noise data.
In addition, as shown in fig. 6, a schematic flow chart of constructing a target global feature classification model in the embodiment of the present application is shown, where the client is the first device, the server is the second device, noise is the noise data, a label is the real classification label, and the global feature classification model is a global classification model.
Step D40, according to the noise data and the real classification labels, iteratively optimizing the global feature generation model under the condition of fixing each classification model to obtain a target global feature generation model;
in this embodiment, specifically, the noise data and the real classification labels are converted into sample features according to the global feature generation model to obtain global sample features, and a second target loss is calculated according to each global prediction classification label and the real classification label obtained by classifying the global sample features respectively according to each classification model, so that the global feature generation model is iteratively optimized under the condition of fixing each classification model according to the second target loss to obtain a target global feature generation model.
Wherein, the step of iteratively optimizing the global feature generation model under the condition of fixing each classification model according to the noise data and the real classification label to obtain a target global feature generation model comprises:
step D41, converting the noise data and the real classification label into corresponding global generation characteristics according to the global characteristic generation model;
step D42, classifying the global generation features respectively according to the classification models to obtain global prediction classification labels corresponding to the classification models;
step D43, calculating a second target loss according to the difference degree between each global prediction classification label and the real classification label;
and D44, iteratively optimizing the global feature generation model under the condition of fixing each classification model according to the second target loss to obtain the target global feature generation model.
In this embodiment, specifically, the noise data and the real classification label are jointly converted into corresponding global generation features according to the global feature generation model; classifying the global generation features according to the classification models to obtain global prediction classification labels corresponding to the classification models; calculating global classification losses corresponding to the global prediction classification labels according to the difference between each global prediction classification label and the real classification label, further aggregating the global classification losses to obtain a second target loss, further updating the global feature generation model according to a model gradient calculated according to the second target loss under the condition of fixing each classification model, judging whether the global feature generation model reaches a preset model iteration updating frequency, if so, taking the global feature generation model as a target global feature generation model, and if not, returning to the execution step: and extracting noise data and a real classification label corresponding to the noise data.
In addition, as shown in fig. 7, a schematic flow chart of constructing a target global feature classification model in the embodiment of the present application is shown, where the client is the first device, the server is the second device, noise is the noise data, and a label is the real classification label.
In addition, it should be noted that, sample data of each first device is usually non-independently and identically distributed, and further local models constructed by the first devices according to the sample data usually have a certain difference, if the local models are directly aggregated as a global model, performance of the global model is usually reduced, but in the embodiment of the present application, after the local models are aggregated to obtain the global model, the global model is further iteratively optimized, so that the global model is more adapted to the local models, that is, the global classification model is more adapted to the feature generation models, and the global feature generation model is more adapted to the classification models, that is, the global classification model and the global feature generation model can better learn knowledge of participants, so that performance of the global classification model and the global feature generation model can be improved, wherein the local model comprises a feature generation model and a classification model.
And D50, feeding the target global classification model and the target global feature generation model back to the first device, so that the first device iteratively optimizes the feature extraction model and the classification model corresponding to the feature generation model according to the target global feature generation model and the target global classification model to obtain a target feature extraction model and a target classification model.
In this embodiment, it should be noted that, the specific process of the first device obtaining the target feature extraction model and the target classification model by iteratively optimizing the feature extraction model and the classification model corresponding to the feature generation model according to the target global feature generation model and the target global classification model may refer to the specific contents in step S50, and details are not repeated here.
Wherein, before the step of feeding back the target global classification model and the target global feature generation model to the first device, the federal learning modeling optimization method further includes:
step E10, judging whether the target global classification model and the target global feature generation model meet preset federal iteration end conditions;
step E20, if yes, notifying each first device that the federal iteration is finished, and executing the steps of: feeding back the target global classification model and the target global feature generation model to the first device;
step E30, if not, directly executing the steps of: feeding back the target global classification model and the target global feature generation model to the first device.
In this embodiment, it should be noted that the preset federal iteration end condition is a condition for judging whether to end federal learning modeling, and the preset federal iteration end condition may be that the maximum number of federal iterations is reached, and a loss function converges.
Specifically, whether the target global classification model and the target global feature generation model meet a preset federal iteration end condition is judged; if yes, notifying each first device that the federal iteration is finished, and executing the following steps: feeding the target global classification model and the target global feature generation model back to the first equipment so that the first equipment can optimize a local model to obtain a final target feature extraction model and a final target classification model; if not, directly executing the following steps: and feeding back the target global classification model and the target global feature generation model to the first equipment so as to enable the first equipment to optimize a local model, and thus carrying out the next round of federal iteration.
Additionally, it should be noted that, in this embodiment of the application, the first device may also classify the output of the feature generation model and the output of the feature extraction model simultaneously through the classification model, and perform iterative update to obtain the feature generation model, but in the training process, the classification model always causes the output of the feature generation model to be consistent with the output of the feature extraction model, and then the classification model may generate the same classification label for the output of the corresponding feature generation model and the output of the feature extraction model, but the feature discrimination model causes a certain difference between the outputs of the feature generation model and the feature extraction model, which may cause the feature generation model to be difficult to converge, and may easily cause the model to be over-fitted on the local sample set. However, in the embodiment of the present invention, when the feature generation model is first constructed in steps S10 to S30, the classification model is not used to classify the output of the feature generation model to optimize the feature generation model, but the global classification model is respectively adapted to each feature generation model in steps D30 and D40, and the global feature generation model is adapted to each classification model, so that it is possible to avoid that the feature generation model is difficult to converge and is easy to cause overfitting of the model on the local sample set, thereby improving the efficiency of federal learning modeling, and similarly, if the feature generation model is an image feature generation model, the efficiency of constructing a target image feature generation model and a target image classification model based on federal learning is improved.
The embodiment of the application provides a federated learning modeling optimization method, and compared with the prior art, each participant maintains a local model and a global model in a federated learning scene. According to the technical means that all the participants learn local peculiar knowledge through local models, share the knowledge of all the participants through global models, and then all the participants gather the local models and the global models together, the embodiment of the application firstly receives feature generation models and classification models sent by all the first devices, aggregates the feature generation models into global feature generation models and aggregates the classification models into global classification models, extracts noise data and real classification labels corresponding to the noise data, and then iteratively optimizes the global classification models under the condition of fixing all the feature generation models according to the noise data and the real classification labels, so that the global classification models are matched with all the feature generation models, and indirectly prompts the global classification models to further learn the model knowledge of all the federal learning participants, improving the precision of a global classification model to obtain a target global classification model, and then iteratively optimizing the global feature generation model under the condition of fixing each classification model according to the noise data and the real classification label, so that each classification model is matched with the global feature generation model, indirectly prompting the global feature generation model to further learn the model knowledge of all federal learning participants, improving the precision of the global feature generation model to obtain the target global feature generation model, and further feeding the target global classification model and the target global feature generation model back to the first equipment, so that the first equipment iteratively optimizes the feature extraction model and the classification model corresponding to the feature generation model according to the target global feature generation model and the target global classification model, the accuracy of the feature extraction model and the classification model serving as the local model can be improved, the first equipment does not directly send the feature extraction model to the second equipment for aggregation, but sends the feature generation model for aggregation, and even if the second equipment reversely pushes the privacy data of the first equipment according to the feature generation model, the obtained input of the feature generation model is the input of the feature generation model, namely the mixed construction sample of the noise data and the label, so that the data privacy of the federal participants can be protected from being revealed, the technical defect that the federal server can reversely push the original data of the participants through the global model of each participant is overcome, the technical defect that the risk of data disclosure exists is overcome, and the risk of revealing the privacy data of the participants in federal learning is reduced.
Referring to fig. 8, fig. 8 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present application.
As shown in fig. 8, the federal learning modeling optimization device may include: a processor 1001, such as a CPU, a memory 1005, and a communication bus 1002. The communication bus 1002 is used for realizing connection communication between the processor 1001 and the memory 1005. The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a memory device separate from the processor 1001 described above.
Optionally, the federal learning modeling optimization device may further include a rectangular user interface, a network interface, a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. The rectangular user interface may comprise a Display screen (Display), an input sub-module such as a Keyboard (Keyboard), and the optional rectangular user interface may also comprise a standard wired interface, a wireless interface. The network interface may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface).
Those skilled in the art will appreciate that the federated learning modeling optimization facility architecture illustrated in FIG. 8 does not constitute a limitation of the federated learning modeling optimization facility, and may include more or fewer components than those illustrated, or some components in combination, or a different arrangement of components.
As shown in fig. 8, the memory 1005, which is a type of computer storage medium, may include an operating system, a network communication module, and a federal learning modeling optimization program. The operating system is a program for managing and controlling hardware and software resources of the Federal learning modeling optimization equipment and supports the operation of the Federal learning modeling optimization program and other software and/or programs. The network communication module is used for realizing communication among components in the memory 1005 and communication with other hardware and software in the federal learning modeling optimization system.
In the federated learning modeling optimization apparatus shown in fig. 8, the processor 1001 is configured to execute a federated learning modeling optimization program stored in the memory 1005 to implement the steps of any of the federated learning modeling optimization methods described above.
The specific implementation of the federal learning modeling optimization device of the application is basically the same as that of each embodiment of the federal learning modeling optimization method, and details are not repeated herein.
The embodiment of the present application further provides a federal learning modeling optimization device, which is applied to the first device, and includes:
the extraction module is used for acquiring a trained feature extraction model and a classification model, and extracting a first training sample, first noise data and a first real classification label corresponding to the first training sample;
a generating module, configured to obtain a first sample feature generated by the feature extraction model for the first training sample, and a second sample feature generated by the feature generation model to be trained for the first noise data and the first real classification label;
the first iterative optimization module is used for carrying out feature discrimination on the first sample feature and the second sample feature through a feature discrimination model to be trained, and iteratively optimizing the feature generation model to be trained under the condition of fixing the feature extraction model to obtain a feature generation model;
the sending module is used for sending the feature generation model and the classification model to second equipment so that the second equipment can iteratively optimize and aggregate the global classification models obtained by the classification models according to the feature generation model sent by the first equipment, and iteratively optimize and aggregate the global feature generation models obtained by the feature generation models according to the classification models sent by the first equipment to obtain a target global feature generation model and a target global classification model;
and the second iterative optimization module is used for receiving the target global feature generation model and the target global classification model fed back by the second equipment, and iteratively optimizing the feature extraction model and the classification model according to the target global feature generation model and the target global classification model to obtain a target feature extraction model and a target classification model.
Optionally, the generating module is further configured to:
carrying out feature discrimination on the first sample feature and the second sample feature through the feature discrimination model to be trained, and calculating feature discrimination loss;
and according to the characteristic discrimination loss, carrying out iterative updating on the characteristic discrimination model to be trained and the characteristic generation model to be trained under the condition of fixing the characteristic extraction model so as to optimize the characteristic generation model to be trained and obtain the characteristic generation model.
Optionally, the generating module is further configured to:
according to the feature discrimination model to be trained, performing secondary classification on the first sample feature and the second sample feature respectively to obtain a secondary classification result;
and calculating the feature discrimination loss according to the two classification results and positive and negative sample labels which correspond to the first sample feature and the second sample feature together.
Optionally, the second iterative optimization module is further configured to:
taking the target global classification model as a new classification model and the target global feature generation model as a new feature generation model, and extracting a second training sample, second noise data and a second real classification label corresponding to the second training sample;
according to the feature extraction model, feature extraction is carried out on the second training sample to obtain third sample features, and according to the new feature generation model, the second noise data and the second real classification label are jointly converted into fourth sample features;
classifying the third sample feature through the new classification model, performing feature discrimination on the third sample feature and the fourth sample feature through the feature discrimination model, and iteratively optimizing the new classification model and the feature extraction model to obtain the target feature extraction model and the target classification model.
Optionally, the second iterative optimization module is further configured to:
if the target global classification model and the target global feature generation model meet a preset federal iteration end condition, classifying the third sample features through the new classification model, performing feature discrimination on the third sample features and the fourth sample features through the feature discrimination model, and iteratively optimizing the new classification model and the feature extraction model to obtain the target feature extraction model and the target classification model;
if the target global classification model and the target global feature generation model do not meet the preset federal iteration end condition, classifying the third sample features through the new classification model, performing feature discrimination on the third sample features and the fourth sample features through the feature discrimination model, iteratively optimizing the new classification model and the feature extraction model, and returning to the execution step: and extracting a first training sample, first noise data and a first real classification label corresponding to the first training sample.
Optionally, the second iterative optimization module is further configured to:
classifying the third sample characteristics through the new classification model, and calculating global classification loss;
carrying out feature discrimination on the third sample feature and the fourth sample feature through the feature discrimination model, and calculating global feature discrimination loss;
and iteratively updating the feature extraction model, the new classification model, the new feature generation model and the feature discrimination model according to the global classification loss and the global feature discrimination loss to optimize the feature extraction model and the new classification model so as to obtain the target feature extraction model and the target classification model.
Optionally, the second iterative optimization module is further configured to:
performing knowledge distillation between the classification model and the target global classification model to optimize the classification model to obtain the target classification model;
and performing knowledge distillation between the feature extraction model and the target global feature generation model to optimize the feature extraction model to obtain the target feature extraction model.
The specific implementation of the federal learning modeling optimization device of the application is basically the same as that of each embodiment of the federal learning modeling optimization method, and details are not repeated herein.
The embodiment of the present application further provides a federal learning modeling optimization device, the federal learning modeling optimization device is applied to the second device, the federal learning modeling optimization device includes:
the aggregation module is used for receiving the feature generation models and the classification models sent by the first devices, aggregating the feature generation models into a global feature generation model and aggregating the classification models into a global classification model;
the extraction module is used for extracting noise data and real classification labels corresponding to the noise data;
the first iterative optimization module is used for iteratively optimizing the global classification model under the condition of fixing each feature generation model according to the noise data and the real classification labels to obtain a target global classification model;
the second iterative optimization module is used for iteratively optimizing the global feature generation model under the condition of fixing each classification model according to the noise data and the real classification labels to obtain a target global feature generation model;
and the feedback module is used for feeding the target global classification model and the target global feature generation model back to the first equipment so that the first equipment can iteratively optimize the feature extraction model and the classification model corresponding to the feature generation model according to the target global feature generation model and the target global classification model to obtain a target feature extraction model and a target classification model.
Optionally, the first iterative optimization module is further configured to:
respectively converting the noise data and the real classification labels into corresponding local sample characteristics together according to each characteristic generation model;
classifying the local sample characteristics respectively according to the global classification model to obtain local prediction classification labels;
calculating a first target loss according to the difference degree between each local prediction classification label and the real classification label;
and according to the first target loss, iteratively optimizing the global classification model under the condition of fixing each feature generation model to obtain the target global classification model.
Optionally, the second iterative optimization module is further configured to:
converting the noise data and the real classification labels into corresponding global generation characteristics together according to the global characteristic generation model;
classifying the global generation features according to the classification models to obtain global prediction classification labels corresponding to the classification models;
calculating a second target loss according to the difference degree between each global prediction classification label and the real classification label;
and according to the second target loss, iteratively optimizing the global feature generation model under the condition of fixing each classification model to obtain the target global feature generation model.
Optionally, the federal learning modeling optimization device is further configured to:
judging whether the target global classification model and the target global feature generation model meet a preset federal iteration end condition or not;
if yes, notifying each first device that the federal iteration is finished, and executing the following steps: feeding back the target global classification model and the target global feature generation model to the first device;
if not, directly executing the following steps: feeding back the target global classification model and the target global feature generation model to the first device.
The specific implementation of the federal learning modeling optimization device of the application is basically the same as that of each embodiment of the federal learning modeling optimization method, and details are not repeated herein.
The embodiment of the application provides a readable storage medium, and the readable storage medium stores one or more programs, which can be executed by one or more processors for implementing the steps of the federal learning modeling optimization method in any one of the above.
The specific implementation of the readable storage medium of the application is substantially the same as that of each embodiment of the federated learning modeling optimization method, and is not described herein again.
The present application provides a computer program product, and the computer program product includes one or more computer programs, which can also be executed by one or more processors for implementing the steps of any of the above methods for federated learning modeling optimization.
The specific implementation of the computer program product of the present application is substantially the same as the embodiments of the federated learning modeling optimization method described above, and is not described herein again.
The above description is only a preferred embodiment of the present application, and not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings, or which are directly or indirectly applied to other related technical fields, are included in the scope of the present application.