Federated learning method and electronic device

By dynamically adjusting the weight of the participant model according to its degree of influence on the global model, the problem of poor performance models in federated learning is solved, the performance and accuracy of the global model are improved, and the computational complexity and cost of the central party are reduced.

CN117131951BActive Publication Date: 2024-09-20HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310165522.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-16
Publication Date
2024-09-20
Estimated Expiration
2043-02-16

AI Technical Summary

Technical Problem

In federated learning, it is difficult for the central party to effectively distinguish between models with good performance and poor performance when aggregating local models, resulting in a decline in global model performance, and the use of knowledge distillation will increase the computational complexity and cost of the central party.

Method used

By dynamically adjusting the model weight of each participant and matching it according to its impact on the global model, it avoids the excessive impact of poor-performing models on the global model. It does not rely on knowledge distillation and reduces the computational complexity of the central party.

Benefits of technology

It improves the performance and accuracy of the global model, shortens the number of iterations, reduces the calculation cost of the central party, and prevents the negative impact of poor performance models on the global model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117131951B
    Figure CN117131951B
Patent Text Reader

Abstract

The present application provides a method and electronic device for federated learning, which relates to artificial intelligence technology. In the method for federated learning in the present application, the central party determines the first model used for aggregation operation through the local models uploaded by the participants; obtains the influence of each first model on the aggregation operation of the current round, determines the first aggregation weight of each first model, and aggregates each first model based on the first aggregation weight of each first model to obtain the global model of this round. Using the method in the present application, the weight of the model used for aggregation can be dynamically adjusted according to the influence of the local model of each participant on the aggregation operation of this round, so as to reduce the influence of the model with poor effect on the global model aggregated in this round, improve the performance of the global model determined in each round, and at the same time will not increase the cost of the central party.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method and electronic device for federated learning. Background Art

[0002] Federated Learning is a distributed machine learning technology that builds a global model based on virtual fusion data by training distributed models between multiple data sources with local data, without exchanging local individual or sample data, and only by exchanging model parameters or intermediate results, so as to achieve a balance between data privacy protection and data sharing calculation. Horizontal Federated Learning (Sample-Partitioned Federated Learning or Example-Partitioned Federated Learning) is a type of federated learning, including the client (i.e., the participant) and the server (i.e., the central party), and can be applied to scenarios where the data sets of each participant in federated learning have the same feature space and different sample spaces. The client uses local training data to train the global model sent by the server, and returns the trained local model to the central party. The central party aggregates each local model to obtain a new global model until the preset training termination condition is met, and a trained federated learning model is obtained.

[0003] However, when the central party aggregates the local models sent by each participant, if the same weight is used for aggregation, the models with good performance and the models with poor performance will have the same weight during aggregation, which will lead to poor performance of the trained global model; if the central party uses knowledge distillation to aggregate the local models, it will increase the computational complexity of the central party, resulting in a sharp increase in the cost of the central party. Summary of the invention

[0004] In order to solve the above technical problems, the present application provides a method and electronic device for federated learning, which can dynamically adjust the weight of the model used for aggregation according to the degree of influence of the local model of each participant on the aggregation operation of this round, so as to reduce the influence of the model with poor effect on the global model of this round of aggregation, improve the performance of the global model determined in each round, and at the same time will not increase the cost of the central party.

[0005] In a first aspect, the present application provides a method for federated learning, which is applied to a first electronic device, where the first electronic device is communicatively connected to at least two second electronic devices, the method comprising: sending global model information of the i-th round of federated learning to each second electronic device, so that each second electronic device performs local model training based on the i-th round of global model information, and uploading the i-th round of local model information to the first electronic device, wherein if i is an integer greater than 1, the global model information includes the global model or the gradient information of the global model, and if i=1, the global model information is a preset initial model, and the local model information includes the local model or the gradient information of the local model; according to each uploaded Local model information, determine the first model for the i+1th round of aggregation operation; obtain the first impact valuation of each first model, the first impact valuation of the first model is used to evaluate the impact of the first model on the i+1th round of aggregation operation; determine the first aggregation weight of each first model according to the first impact valuation of each first model; aggregate each first model according to the first aggregation weight of each first model to obtain the i+1th round of global model; according to the i+1th round of global model, transmit the i+1th round of global model information to each second electronic device for the next round of federated learning, until the preset training termination condition is met, and a trained federated learning model is obtained.

[0006] In this way, the first electronic device (i.e., the central party) determines the first model of the i+1th round according to the local model information uploaded by each second electronic device (i.e., the participating party) during the federated learning process, and dynamically determines the first aggregation weight of each first model at the i+1th round of aggregation. Since the first aggregation weights of each first model are not all the same, it can be avoided that the contribution of the first model with good performance and the first model with poor performance are consistent during aggregation, and the influence of the model with poor performance on the aggregation is avoided. At the same time, in this example, the first electronic device adjusts the first aggregation weight of each first model based on the influence of each first model on the aggregation operation of the i+1th round, so that the first aggregation weight of each first model matches the influence of the first model on the aggregation operation of the i+1th round, thereby improving the performance of the global model of the i+1th round (such as more accurate model prediction), and can shorten the number of iterations of the global model. In addition, this method does not need to adopt the knowledge distillation method, does not increase the calculation amount of the central party, and avoids the increase of the cost of the central party.

[0007] According to the first aspect, obtaining a first impact valuation of each first model includes: aggregating each first model to generate a first benchmark model of the (i+1)th round; respectively obtaining second models corresponding to each first model, wherein the second model corresponding to the jth first model is a model obtained by aggregating first models except the jth first model, j is an integer greater than or equal to 1, and the maximum value of j is equal to the number of first models; obtaining a first impact valuation of each first model according to the first benchmark model and the second model corresponding to each first model.

[0008] In this way, the first electronic device aggregates each first model to obtain the first benchmark model of the i+1th round, so that the first benchmark model contains the characteristic information of each first model; the second model corresponding to each first model is generated by aggregation after excluding the first model, so that the second model corresponding to the first model does not contain the characteristic information of the first model; the difference between the first benchmark model and the second model corresponding to the first model can reflect the influence of the first model on the global model of the i+1th round when aggregated; therefore, the first impact valuation determined in this way can more accurately reflect the influence of the first model on the global model of the i+1th round, and the method of determining the first impact valuation is simple and will not increase the calculation complexity of the central party.

[0009] According to the first aspect, according to the first benchmark model and the second model corresponding to each first model, the first impact valuation of each first model is obtained, including: obtaining the evaluation index of the first benchmark model; obtaining the evaluation index of the second model corresponding to each first model; according to the evaluation index of the first benchmark model and the evaluation index of the second model corresponding to each first model, respectively obtaining the difference between the evaluation index of the first benchmark model and the evaluation index of the second model corresponding to each first model as the first impact valuation of each first model. In this way, the evaluation index of the model can generally be accuracy, recall rate, F1 score, etc., and the evaluation index of the model can quickly quantify the influence of the first model on the aggregation operation of the i+1th round.

[0010] According to the first aspect, aggregating each first model to generate the first reference model of the i+1th round includes: obtaining the average value of the number of first models in the i-th round as the second aggregation weight of each first model; aggregating each first model according to the second aggregation weight of each first model to generate the first reference model. In this way, the first electronic device can determine the second aggregation weight of each first model without obtaining additional data uploaded by the second electronic device, which can avoid the problem of inaccurate second aggregation weight of the first model determined due to false data uploaded by the second electronic device.

[0011] According to the first aspect, aggregating each first model to generate a first benchmark model of the i+1th round includes: obtaining model information of each first model in the i-th round, the model information including the number of training samples indicating the first model or the training log indicating the first model; and determining the second aggregation weight of each first model according to the model information of each first model. In this way, since the model information can reflect the performance of the first model, the second aggregation weight of the first model with poor performance can be reduced, thereby improving the accuracy of the first benchmark model.

[0012] According to the first aspect, if the model information of the first model includes the number of training samples indicating the first model; according to the model information of each first model, the second aggregation weight of each first model is determined, including: obtaining the total number of training samples for generating all first models in the i-th round; obtaining the quotient between the number of training samples of each first model and the total number as the second aggregation weight of each first model. In this way, the more training samples there are, the more accurate the model is. The second aggregation weight of each first model is determined based on the number of training samples, so that the second aggregation weight of the first model with high performance is better, and the second aggregation weight of the first model with poor performance is reduced, thereby improving the accuracy of the first benchmark model.

[0013] According to the first aspect, the first aggregation weight of each first model is determined according to the first impact valuation of each first model, including: obtaining the average of the first impact valuations of all first models in the i-th round as the average impact valuation; processing the first impact valuation of each first model: obtaining the difference between the first impact valuation of the first model and the average impact valuation as the second difference; obtaining the sum of the second aggregation weight of the first model and the second difference as the first aggregation weight of the first model. In this way, the second aggregation weight is fine-tuned by the first impact valuation, and the fine-tuned second aggregation weight is used as the first aggregation weight, which improves the rationality of the first aggregation weight of each first model, thereby improving the accuracy of the global model in the i+1th round.

[0014] According to the first aspect, according to each uploaded local model information, determining the first model for the i+1th round of aggregation operation includes: determining the local model generated by each second electronic device in the i-th round according to each uploaded local model information; dividing each local model in the i-th round into N categories, where N is an integer greater than 1; and aggregating the local models in each category to obtain N first models. In this way, the first electronic device can first perform a classification operation on the local model of each second electronic device, aggregate the local models of each category, and obtain N first models, thereby reducing the number of first models in subsequent aggregation operations and reducing the amount of calculation of the central party.

[0015] According to the first aspect, the local models in each class are aggregated to obtain N first models, including: performing the following processing on the local models in each class: obtaining the average value of the number of local models in the class as the third aggregation weight of each local model in the class; and aggregating each local model in the class according to the third aggregation weight of each local model in the class to generate a first model. In this way, the first electronic device aggregates based on the number of local models in the class without relying on other information uploaded by the second electronic device, which can effectively avoid the influence of malicious data on model aggregation and improve the accuracy of each first model.

[0016] According to the first aspect, dividing each local model in the i-th round into N categories includes: using K-means clustering to divide the local models in the i-th round into N categories. In this way, when there are many local models, the first electronic device uses K-means clustering to classify the local models, and the classification speed is fast and accurate.

[0017] According to the first aspect, each local model in the i-th round is divided into N categories, including: aggregating the local models generated by each second electronic device in the i-th round to obtain a second reference model; respectively obtaining the distance between each local model and the second reference model; and determining the category to which each local model belongs according to each obtained distance and the preset N distance threshold ranges. In this way, the first electronic device respectively obtains the distance between the local model and the second reference model, and can more accurately determine the similarity between the local model and the second reference model according to the distance, and classifies based on the similarity between the local model and the second reference model.

[0018] According to the first aspect, each local model in the i-th round is divided into N categories, including: obtaining the change amount between the i-th round local model uploaded by each second electronic device and the i-th round global model; determining the category to which each local model belongs according to each obtained change amount and the preset N change amount threshold ranges. In this way, the first electronic device compares each local model with the i-th round global model, obtains the similarity between each local model and the i-th round global model, and based on the similarity, similar models can be divided into one category, so that the first model of each category can more accurately reflect the characteristics of the model of that category.

[0019] According to the first aspect, the evaluation indicators include: accuracy, recall or F1 score of the model.

[0020] According to the first aspect, before dividing each local model in the i-th round into N categories, the method further includes: detecting that the number of local models in the i-th round is greater than a preset threshold. In this way, each local model in the i-th round is divided only when the number of local models is greater than the preset threshold, so as to reduce the number of subsequent first models and reduce the amount of calculation of the central party.

[0021] According to the first aspect, determining the first model for the i+1th round of aggregation operation according to each uploaded local model information includes: determining the local model generated by each second electronic device in the i-th round according to each uploaded local model information; when it is detected that the number of local models in the i-th round is less than or equal to a preset threshold, the local model in the i-th round is used as the first model in the i-th round. In this way, when the number of local models is less than the preset threshold, there is no need to classify the local models, avoiding unnecessary computing overhead.

[0022] According to the first aspect, before sending the global model information of the i-th round of federated learning to each second electronic device, the method further includes: in response to the model training request sent by at least two second electronic devices, obtaining the initial model that matches the model training request; after obtaining the trained federated learning model, the method further includes: sending the federated learning model to each second electronic device respectively. In this way, the second electronic device can trigger the first electronic device to start the federated learning training target model to meet the model requirements of different second electronic devices.

[0023] In a second aspect, the present application provides an electronic device comprising: a memory and a processor, the memory being coupled to the processor; the memory storing program instructions, which, when executed by the processor, enables the electronic device to execute the method of federated learning corresponding to the first aspect and any one of the implementation methods of the first aspect.

[0024] The second aspect and any implementation of the second aspect correspond to the first aspect and any implementation of the first aspect respectively. The technical effects corresponding to the second aspect and any implementation of the second aspect can refer to the technical effects corresponding to the above-mentioned first aspect and any implementation of the first aspect, which will not be repeated here.

[0025] In a third aspect, the present application provides a computer-readable medium for storing a computer program. When the computer program is run on an electronic device, the electronic device executes the method of federated learning corresponding to the above-mentioned first aspect and any one of the implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0027] Figure 1 is a schematic diagram of an exemplary horizontal federated learning system;

[0028] Figure 2 is a schematic diagram of the structure of a central party shown as an example;

[0029] Figure 3 is a flowchart showing an exemplary central party training a global model;

[0030] Figure 4 is a schematic diagram of an exemplary federated learning system;

[0031] Figure 5 is a schematic diagram of an exemplary federated learning system;

[0032] Figure 6 is a schematic diagram of an exemplary federated learning system determining a global model in the i-th round;

[0033] Figure 7 is a flowchart showing an exemplary central party training a global model;

[0034] Figure 8 is a schematic diagram of an exemplary federated learning system determining a global model in the i-th round;

[0035] Fig. 9 is a schematic structural diagram of a second electronic device exemplarily shown;

[0036] Fig.10 FIG. 1 is a schematic diagram showing an exemplary software structure of a second electronic device. DETAILED DESCRIPTION

[0037] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0038] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0039] The terms "first" and "second" in the description and claims of the embodiments of the present application are used to distinguish different objects rather than to describe a specific order of objects. For example, a first target object and a second target object are used to distinguish different target objects rather than to describe a specific order of target objects.

[0040] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0041] In the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more than two. For example, multiple processing units refer to two or more processing units; multiple systems refer to two or more systems.

[0042] Before describing the technical solutions of the embodiments of the present application, Figure 1 The horizontal federated learning system in the embodiment of the present application is described. The horizontal federated learning system includes a parameter server (i.e., a central party) and at least one client (i.e., a participant). In this example, the horizontal federated learning system includes G clients, where G is an integer greater than 2. Figure 1 Specifically explain the process of horizontal federated learning:

[0043] S1. The central party initializes the global model parameters.

[0044] Specifically, the central party pre-stores the structure of the global model of this federated learning, and can initialize the parameters of the global model to obtain an initial global model (or initial model).

[0045] S2. The central party sends the initial global model to each participant.

[0046] S3. Each participant uses local data to train the model and sends the trained model (or gradient) to the central party.

[0047] S4. The central party receives the local models (or gradients) sent by each participant, obtains the local model of each participant, and aggregates the local models to obtain the global model of this round.

[0048] Specifically, each participant can send the local model obtained in this round of training to the central party. The participant can also send the gradient of the local model obtained in the training to the central party. The central party determines the local model obtained by each participant in this round of training based on the received gradient and the issued global model.

[0049] S5. Repeat steps S2 to S4 until the global model converges or reaches the preset number of training rounds.

[0050] When the central party aggregates each local model, it usually uses the federated average algorithm to determine the weight of each local model when it is aggregated. For example, if there are 5 participants, the local models trained by each participant are recorded as m1, m2, m3, m4 and m5 respectively. After the central party obtains the 5 local models, it uses the federated average algorithm to determine that the weight of each local model is 1 / 5; that is, the global model obtained by the central party in this round is recorded as M=1 / 5(m1+m2+m3+m4+m5). The global model obtained by this algorithm does not take into account the amount of training data and the distribution of training data when each participant trains the local model, nor does it refer to the differences in the performance of each local model; resulting in low accuracy of the global model.

[0051] In some embodiments, when the client reports the local model to the central party, it can also report the performance score of the model at the same time, such as model loss, accuracy and other information. The central party can determine the aggregation weight of the local model based on the model performance of each model. The central party aggregates each local model according to the aggregation weight of each local model to obtain the global model of this round. This method requires additional calculations on the trained local model based on the client, which increases the cost of the client, and it is also difficult to prevent the problem of malicious reporting of false performance scores.

[0052] In some embodiments, the central party can generate a global model by deep learning. For example, the central party performs knowledge distillation on the models of each participant to aggregate the model, or uses the attention mechanism to optimize the aggregated model. However, this method increases the computational complexity of the central party, resulting in a sharp increase in the cost of the central party, making it difficult to widely apply this method.

[0053] An embodiment of the present application provides a method of federated learning, which is applied to a central party. During the process of federated learning, the central party can determine the first model used for the i+1th round of aggregation operations based on the local model information returned by the participating parties; and dynamically determine the first aggregation weight of each first model in the i+1th round based on each first model. In this example, the first aggregation weight of each first model depends on the degree of influence of each first model on the aggregation operation, so that the weight of the local model with good effect is high, and the aggregation weight of the local model with poor effect is reduced, thereby improving the accuracy of the global model after aggregation and reducing the number of iterations of federated learning. In addition, the central party does not need to use knowledge distillation to perform aggregation operations, which also reduces the computational complexity of the central party and reduces the cost of model aggregation of the central party.

[0054] Figure 2 The schematic diagram of the structure of the central party is shown as an example. In this example, the central party can be a server, and the central party includes: a first model determination module, a first impact valuation determination module, a first aggregation weight determination module and an aggregation module. The first model determination module is used to determine the first model for aggregation operation in the i+1th round according to the local model information reported by each participant in the i-th round. The first impact valuation determination model is used to determine the first impact valuation of each first model. The first aggregation weight determination module is used to determine the first aggregation weight of each first model according to the first impact valuation of each first model. The aggregation module performs an aggregation operation on each first model according to the first aggregation weight of each first model to obtain a global model of the i+1th round. The aggregation model can also send the global model of the i+1th round to each participant when it is detected that the global model does not meet the training termination condition.

[0055] Combine the following Figure 3 , specifically describing the process of the center party training the global model. In this example, the first electronic device acts as the center party, and the first electronic device may be a server. The second electronic device acts as a participant, and the second electronic device may be a device with a training function, for example, the second electronic device may be a server, a mobile phone, a personal computer, etc.

[0056] Step 301: The first electronic device sends global model information of the i-th round of federated learning to each second electronic device.

[0057] In some embodiments, the first electronic device generates an initial model that matches the model training instruction according to the model training instruction input by the user. For example, the model training instruction A input by the user indicates to train a model for face recognition. After the first electronic device receives the model training instruction A, it can obtain an initial model for face recognition that matches the model training instruction A. Optionally, the initial model includes a model structure and each parameter in the initial model.

[0058] Optionally, the first electronic device may also receive model training instructions sent by multiple second electronic devices, and the first electronic device may determine an initial model that matches the model training instruction based on the received model training instruction. Figure 4 As shown, mobile phone A and mobile phone B send model training request 1 to the server, assuming that the initial model corresponding to model training request 1 is model A. When the server receives model training request 1, it finds that the initial model matching the model training request 1 is model A. The server can send model A as global model information to mobile phone A and mobile phone B respectively. That is, at this time, the server acts as the central party, and mobile phone A and mobile phone B act as participants.

[0059] It should be noted that the first electronic device can receive multiple different model training requests, and can obtain an initial model matching each model training request respectively. The first electronic device sends each initial model to the model training request sender matching the initial model.

[0060] For example, if Figure 5 As shown, in the smart service scenario, mobile phone A and mobile phone B send model training request 1 to the server (to realize the face recognition function), and mobile phone C and mobile phone D send model training request 2 to the server (to realize the road safety sign recognition function). Assume that the initial model corresponding to model training request 1 is model A, and the initial model corresponding to model training request 2 is model B. When the server receives model training request 1, it obtains model A corresponding to model training request 1, and obtains model B corresponding to model training request 2. The server sends model A to mobile phone A and mobile phone B respectively, and the server sends model B to mobile phone C and mobile phone D respectively. It can be understood that the server, mobile phone A and mobile phone B constitute the first federated learning system, and the server, mobile phone C and mobile phone D constitute the second federated learning system. The first federated learning system is used to train the model for face recognition, and the second federated learning system is used to train the model for road safety sign recognition.

[0061] The first electronic device uses the acquired initial model as the global model of the first round of this federated learning. The first electronic device can send the global model of the first round as global model information to each second electronic device.

[0062] The second electronic device receives the global model information sent by the first electronic device for the first time, and obtains the initial model from the global model information of the first round. Each second electronic device can train the initial model according to the local training data, update the parameters in the initial model, and obtain the local model of the first round. The training data in the second electronic device can be data pre-stored in the second electronic device, or it can be data obtained by the second electronic device from other electronic devices. For example, if federated learning is used to train a model for face recognition, the training data in mobile phone A (the second electronic device) can be images containing faces downloaded from the Internet, or it can be images containing faces stored in the gallery in mobile phone A.

[0063] The second electronic device may upload the local model as local model information to the server, or may upload the parameters or gradients in the first round of local model as the first round of local model information to the server.

[0064] After receiving the local model of the first round reported by each second electronic device, the first electronic device can execute steps 302 to 306. After determining the global model of the second round, the first electronic device can use the global model of the second round as the global model information of the second round, or use the gradient of the global model of the second round as the global model information of the second round. Similarly, when i is an integer greater than 2, the global model information of the i-th round can be the global model of the i-th round or the gradient of the global model of the i-th round.

[0065] Step 302: The first electronic device determines a first model for the (i+1)th round of aggregation operation based on each uploaded local model information.

[0066] In some embodiments, the following processing is performed for each local model information of the i-th round: when it is detected that the current local model information includes a gradient, the first electronic device can determine the local model uploaded by the second electronic device in the i-th round based on the global model of the i-th round and the gradient, and the first electronic device uses the local model as the first model. When it is detected that the current local model information includes the local model, the local model is directly used as the first model.

[0067] For example, the participants include mobile phone A and mobile phone B. After receiving the initial model, mobile phone A uses the local training data in mobile phone A to train and obtain the local model M a1 , mobile phone A obtains local model M a1 The gradient of is used as the local model information A of the first round, and the local model information A of the first round is uploaded to the server. After receiving the initial model, mobile phone B uses the local training data in mobile phone B to train and obtain the local model M b1 , mobile phone B will local model M b1As the local model information B of the first round, the local model information B of the first round is uploaded to the server. The server receives the local model information A uploaded by mobile phone A in the first round, and the local model information B uploaded by mobile phone B in the first round. The server detects that the local model information A includes a gradient, and then the server can determine the local model M obtained by mobile phone A after the first round of local training based on the initial model and the gradient. a1 The server can use the local model M a1 The server detects that the local model information B includes the local model M b1 , the local model M can be directly b1 Make the second first model in round 1.

[0068] Step 303: The first electronic device obtains a first impact estimation value of each first model.

[0069] After the first electronic device acquires each first model, it can determine a first impact estimate of each first model based on the first model. The first impact estimate of the first model is used to evaluate the impact of the first model on the i+1th round of aggregation operations, that is, to evaluate the impact of the first model on the i+1th round of global model to be determined.

[0070] In some embodiments, the first electronic device can aggregate each first model to generate a first benchmark model of the i+1th round; obtain the second models corresponding to each first model respectively, wherein the second model corresponding to the jth first model is a model obtained by aggregating the first models except the jth first model, j is an integer greater than or equal to 1, and the maximum value of j is equal to the number of first models; obtain the first impact valuation of each first model according to the first benchmark model and the second model corresponding to each first model.

[0071] Specifically, the first electronic device can construct the first reference model of the i+1th round based on all the first models in the current i-th round. The first electronic device can use the federated average algorithm to aggregate each first model, and the obtained model is used as the first reference model. For example, the first electronic device obtains the average value of the number of first models in the i-th round as the second aggregation weight of each first model; according to the second aggregation weight of each first model, aggregate each first model to generate a first reference model. For example, each first model is recorded as m j , the number of the first models in the i-th round is n, then the first benchmark model is expressed as:

[0072] The process of the first electronic device generating the second model corresponding to each first model is as follows: the first electronic device obtains the first model in the i-th round, aggregates the first models except the j-th first model, and obtains the second model corresponding to the j-th first model. Each first model is denoted as m j , the number of first models in the i-th round is n, then the second model corresponding to the j-th first model is expressed as:

[0073] For example, there are five first models in the first round, namely m1, m2, m3, m4 and m5. The first electronic device aggregates m2, m3, m4 and m5 using the federated average algorithm to obtain the model The model M -1 This is the second model corresponding to m1. The first electronic device aggregates m1, m3, m4 and m5 using the federated average algorithm to obtain the model The model M -2 This is the second model corresponding to m2. The first electronic device aggregates m1, m2, m4 and m5 using the federated average algorithm to obtain the model The model M -3 This is the second model corresponding to m3. The first electronic device aggregates m1, m2, m3 and m5 using the federated average algorithm to obtain the model The model M -4 This is the second model corresponding to m4. The first electronic device aggregates m1, m2, m3 and m4 using the federated average algorithm to obtain the model The model M -5 This is the second model corresponding to m5.

[0074] After determining the first benchmark model and the second model corresponding to each first model, the first electronic device can obtain the evaluation index of the first benchmark model. The evaluation index of the model can be the accuracy, precision, recall rate, F1 score, etc. of the model. The first electronic device obtains the evaluation index of the second model corresponding to each first model respectively. The first electronic device can determine the first influence estimate of each first model based on the evaluation index of the first benchmark model and the evaluation index of the second model corresponding to each first model. Exemplarily, the first electronic device can obtain the difference between the evaluation index of the first benchmark model and the evaluation index of the second model corresponding to the jth first model as the first influence estimate Influence of the jth first model. j , denoted as Influence j =score-score -j , where score represents the evaluation index of the first benchmark model. -j Represents the evaluation index of the second model corresponding to the j-th first model.

[0075] Figure 6 This is a schematic diagram of the federated learning system in this example determining the global model in one round. Figure 6 As shown in Figure 1, there are n participants. Assume that each participant sends local model information to the central party for the second time. The central party determines the local model of each participant based on the local model information of each participant and obtains n local models. The central party uses the federated average algorithm to aggregate the n local models and obtain the benchmark model. (i.e., the first benchmark model). The central party uses the federated balancing algorithm to aggregate other local models except local model 1 and obtains the model M corresponding to the local model -1 (i.e., the second model corresponding to local model 1). Similarly, the central party uses the federated balancing algorithm to aggregate other local models except local model n to obtain the model M corresponding to the local model. -n (ie, the second model corresponding to local model n), the determination process of the second models corresponding to other local models will not be listed one by one.

[0076] like Figure 6 As shown, the central party can use the central party's test data to obtain the benchmark model M avg The accuracy of the benchmark model M avg The accuracy of the model M is used as the evaluation score (i.e., the evaluation index of the first benchmark model). -1 The accuracy is used as the evaluation score of the model M1 -1 (i.e., the evaluation index of the second model corresponding to the first model). Similarly, the central party can obtain the evaluation scores of n second models. The first influence valuation of local model 1 Influence1 = score - score -1 、The first impact estimate of local model 2 Influence2 = score-score -2 , ..., the first impact estimate of local model n Influence n =score-score -n .

[0077] In some embodiments, the local model information uploaded by the second electronic device may also include the number of training samples used to train the local model. After the first electronic device receives the local model information, it can determine the first model based on the local model information. The first electronic device determines the number of training samples of the first model based on the training sample data of the local model. The first electronic device determines the second aggregation weight of the first model based on the number of training samples of the first model. The first electronic device aggregates each first model based on the second aggregation weight of each first model to obtain a first benchmark model.

[0078] Combine the following Figure 6 Another aggregation method is used to determine the process of the first benchmark model and each second model:

[0079] like Figure 6 As shown, in the i-th round, the local model information uploaded by participant 1 includes: the gradient of local model 1 and the number of training samples num_1 used to train the local model 1, and the local model information uploaded by participant 2 includes: the gradient of local model 2 and the number of training samples num_2 used to train the local model 2. The local model information uploaded by participant 3 includes: the gradient of local model 3 and the number of training samples num_3 used to train the local model 3, ..., the local model information uploaded by participant n includes: the gradient of local model n and the number of training samples num_n used to train the local model n.

[0080] The central party can determine the local model of each participant trained in the i-th round based on the local model information uploaded by each participant in the i-th round. For example, the central party can determine the local model 1 based on the gradient of the local model 1 and the global model determined in the previous round.

[0081] The central party obtains the total number of training samples for generating all first models in the i-th round, obtains the quotient between the number of training samples of each first model and the total number, and uses it as the second aggregation weight of each first model. The central party aggregates each first model according to the second aggregation weight of each first model to generate a first benchmark model.

[0082] For example, the center obtains the total number of training samples of all first models in round i The second weight w of the local model 1 (i.e., the first model) 21 =num_1 / num_sum; the second weight of local model 2 is w 22 =num_2 / num_sum, ..., the second weight w of the local model n (i.e., the first model) 2n = num_n / num_sum. The central party aggregates each first model according to the second aggregation weight of each first model to obtain a first benchmark model.

[0083] The process of the center party generating the second model corresponding to each first model is as follows: the first electronic device obtains the first model in the i-th round, aggregates the first models except the j-th first model, and obtains the second model corresponding to the j-th first model. Each first model is denoted as m j , the number of first models in the i-th round is n, and the second model corresponding to the j-th first model is expressed as:

[0084] For example, there are five first models in the first round, namely m1, m2, m3, m4 and m5. The number of training samples of m1 is num1, the number of training samples of m2 is num2, the number of training samples of m3 is num3, the number of training samples of m4 is num4 and the number of training samples of m5 is num5. The total number of training samples of all first models in the first round is recorded as sum (i.e. sum=num1+num2+num3+num4+num5).

[0085] The first electronic device aggregates m2, m3, m4 and m5 according to the number of training samples of each first model to obtain a model The model M -1 This is the second model corresponding to m1. The center aggregates m1, m3, m4 and m5 to obtain the model The model M -2 This is the second model corresponding to m2. The center aggregates m1, m2, m4 and m5 to obtain the model The model M -3 This is the second model corresponding to m3. The center aggregates m1, m2, m3 and m5 to obtain the model The model M -4 This is the second model corresponding to m4. The center aggregates m1, m2, m3 and m4 to obtain the model The model M -5 This is the second model corresponding to m5.

[0086] In this example, the second aggregation weight of each first model is determined based on the number of first models. Since there is no need to rely on additional information uploaded by the second electronic device to calculate the second aggregation weight, it can effectively defend against false information reported by malicious parties, avoid poor performance models occupying high weights in the i+1th round of aggregation, and avoid the risk of global model performance degradation.

[0087] In some embodiments, the local model information uploaded by the second electronic device may also include a training log for indicating the acquisition of the first model, and the training log may include evaluation indicators (such as accuracy, recall, and F1 score) of the local model trained by the second electronic device. The first electronic device can determine each first model based on the local model information, and the process of determining the first model will not be repeated. In this example, the training log includes accuracy as an example to illustrate the process of determining the first benchmark model and the second model corresponding to each first model.

[0088] Specifically, the first electronic device obtains the accuracy of each first model, and can use the accuracy of each first model as the second aggregation weight of the first model. The first electronic device aggregates each first model according to the second aggregation weight of each first model to generate a first reference model. Similarly, the first electronic device can also aggregate first models other than the jth first model according to the second aggregation weight of each first model to obtain a second model corresponding to the jth first model.

[0089] Step 304: The first electronic device determines a first aggregation weight for each first model according to the first impact estimation of each first model.

[0090] In this example, the first electronic device adjusts the second aggregation weight of the first model according to the first impact estimation of the first model, and uses the adjusted second aggregation weight as the first aggregation weight of the first model.

[0091] Optionally, the first electronic device may obtain an average of the first impact estimates of all first models in the i-th round as the average impact estimate. How to process the first impact estimate of each first model: the first electronic device obtains the difference between the first impact estimate of the first model and the average impact estimate as the second difference; the first electronic device obtains the sum of the second aggregate weight of the first model and the second difference as the first aggregate weight of the first model.

[0092] For example, the first model is denoted by m j , the starting value of j is 1 and the maximum value is n. The number of the first models in the i-th round is n, and the first impact estimate of the first model is recorded as: Influence j =score-score -j The first electronic device obtains an average value of the first impact estimates of all the first models in the i-th round, and the average impact estimate is expressed as: The second difference of the jth first model is The second aggregation weight of the jth first model is denoted as w 2j The first electronic device determines the first aggregation weight w of the jth first model according to the second aggregation weight of the jth first model, the first influence estimate of the jth first model and the average influence estimate. j ,

[0093] If the second aggregation weight of the jth first model is expressed as Then the first aggregation weight of the jth first model is

[0094] If the second aggregation weight of the jth first model is expressed as Then the first aggregation weight of the jth first model is

[0095] Step 305: The first electronic device aggregates each first model according to the first aggregation weight of each first model to obtain a global model of the (i+1)th round.

[0096] Exemplarily, after the first electronic device determines the first aggregation weight of each first model, it can aggregate each first model according to the first aggregation weight of each first model to obtain the global model of the (i+1)th round. Figure 6 As shown, the first electronic device determines that the aggregation weight of local model 1 is w1 (ie, the first aggregation weight), the aggregation weight of local model 2 is w2, ..., the aggregation weight of local model n is w n The first electronic device aggregates each local model according to the aggregation weight of each local model to obtain a global model M weighted =∑w j *m j , m j represents the jth local model, w j represents the first aggregation weight of the j-th local model.

[0097] Step 306: The first electronic device transmits the global model information of the i+1th round to each second electronic device based on the global model of the i+1th round to perform the next round of federated learning until the preset training termination condition is met to obtain a trained federated learning model.

[0098] Exemplarily, after determining the global model of the i+1th round, the first electronic device may detect whether a preset training termination condition is currently satisfied. Optionally, the training termination condition may be detecting that the global model has converged, and the training termination condition may also be detecting that the number of rounds has reached a preset number, which may be 20 times, 10 times, etc.

[0099] When the first electronic device detects that the global model of the i+1th round has converged or the number of rounds of the current i+1th round has reached a preset number, the global model of the i+1th round is used as a trained federated learning model.

[0100] When the first electronic device detects that the preset training termination condition is not met at present, the global model information of the i+1th round is generated, and the global model information of the i+1th round includes the global model of the i+1th round or the gradient of the global model of the i+1th round. The first electronic device sends the global model information of the i+1th round to each second electronic device and continues the next round of training, that is, executing steps 301 to 306.

[0101] In this example, during the federated learning process, the first electronic device (central party) can aggregate the local models of the i-th round of each participant to obtain the first benchmark model and obtain the evaluation index of the first benchmark model. The first electronic device aggregates other local models except the j-th local model to obtain the second model of the j-th local model, and the first electronic device obtains the evaluation index of the second model. Since the j-th local model is not aggregated when the second model of the j-th local model is aggregated, and the first benchmark model contains the information of each local model in the i-th round, the difference between the evaluation index of the first benchmark model and the evaluation index of the second model of the j-th local model is obtained, and the difference can be used to indicate the influence of the j-th local model in the aggregated local model in the i+1 round. The first electronic device can adjust the second aggregation weight of the j-th local model according to the influence degree, so that when the i+1 round of aggregation is performed, the local model is aggregated by the adjusted second aggregation weight, which can increase the aggregation weight of the local model with good effect and reduce the aggregation weight of the local model with poor effect, thereby having a good defense effect on malicious local models (i.e., models with random parameters). At the same time, if the average aggregation algorithm is used when aggregating the first benchmark model, since there is no need to rely on the model information fed back by the participants, it can avoid the impact of false data fed back by the participants on the global model of the i+1th round of aggregation, thereby reducing the risk of model performance degradation.

[0102] In some embodiments, if there are many participants, such as the number of participants is greater than a preset value, the central party can classify the local models obtained after obtaining the local models trained by each participant in the i-th round to obtain the aggregate model of each class. The central party can use the aggregate model of each class as the first model. Through the classification operation, the number of first models used for the i+1th round of aggregation can be reduced, and the amount of calculation for determining the global model of the i+1th round can be reduced.

[0103] Combine the following Figure 7 and Figure 8 The specific process of federated learning.

[0104] Step 701: The first electronic device sends global model information of the i-th round of federated learning to the second electronic device.

[0105] This step is similar to the step in step 301 , and the relevant description in step 301 may be referred to, and will not be repeated here.

[0106] Step 702: The first electronic device determines the local model generated by each second electronic device in the i-th round according to each uploaded local model information.

[0107] Exemplarily, the first electronic device may determine the local model generated by each second electronic device in the i-th round of training based on each local model information. Optionally, when the local model information includes a local model (the local model includes the structure of the model and each parameter in the model), the first electronic device may directly obtain the local model.

[0108] Optionally, when the local model information includes the gradient of the local model, the first electronic device may determine the local model generated by the training of the second electronic device in the i-th round based on the global model of the i-th round and the gradient of the local model.

[0109] Optionally, the types of information included in the local model information uploaded by different second electronic devices may be different. For example, the local model information uploaded by participant 1 includes the local model 1 trained in the i-th round; the local model information uploaded by participant 2 includes the gradient of the local model 2 trained in the i-th round.

[0110] In some embodiments, the first electronic device obtains the number of local models in the i-th round, and detects whether the number of local models is greater than a preset threshold; if the first electronic device detects that the number of local models is greater than the preset threshold, it determines to execute step 703; if the first electronic device detects that the number of local models is less than or equal to the preset threshold, it determines that the local model in the i-th round is the first model in the i-th round, and does not execute steps 703 and 704. The preset threshold can be set according to actual applications, for example, the preset threshold can be 10, 30, 50, 100, etc.

[0111] Step 703: The first electronic device divides the local model in the i-th round into N categories.

[0112] In some embodiments, the first electronic device obtains the local model generated by each second electronic device in the i-th round of training, and the first electronic device can classify all local models in the i-th round into N categories. Optionally, the first electronic device can use K-means clustering to divide the local models of the i-th round into N categories, and the process of the K-means clustering method is not described in detail here.

[0113] In some embodiments, the first electronic device may further divide the local models of the i-th round into N classes according to the similarity of each local model. The first electronic device may use the distance between the local model and the second reference model as the basis for judging the similarity between each local model, or may use the change between the local model of this round and the global model of this round as the basis for judging the similarity between each local model.

[0114] Optionally, the first electronic device may also aggregate the local models generated by each second electronic device in the i-th round to obtain a second benchmark model; obtain the distance between each local model and the second benchmark model respectively; and determine the class to which each local model belongs based on each obtained distance and a preset range of N distance thresholds.

[0115] Specifically, the first electronic device may use a federated average algorithm to aggregate each local model in the i-th round to obtain a second reference model. The first electronic device may pre-store distance threshold ranges corresponding to N classes. For example, the first electronic device stores distance threshold ranges corresponding to three classes, and the three distance threshold ranges do not intersect each other. The first electronic device obtains the distance between each local model and the second reference model, and obtains the distance threshold range in which each distance is located, and divides the local models corresponding to the distances in the same distance threshold range into one class.

[0116] For example, the first electronic device is divided into three categories, the distance threshold range corresponding to the first category is Th1, the distance threshold range corresponding to the second category is Th2, and the distance threshold range corresponding to the third category is Th3. The second reference model is denoted as M avg2 , there are 10 local models in the i-th round, which are recorded as m1, m2, m3, m4, m5, m6, m7, m8, m9 and m10. The first electronic device calculates the distance between each local model and the second reference model, and obtains the distance L1 between m1 and the second reference model, L1 = m1-M avg2 , the distance between m2 and the second reference model L2 = m2-M avg2 Similarly, the first electronic device can obtain the distances between other local models and the second reference model, which are recorded as L3, L4, ..., L10. The first electronic device detects that the distances L1, L4 and L7 are within the range of Th1, and then classifies m1, m4 and m7 into the first category. The first electronic device detects that the distances L2, L5, L6 and L10 are within the range of Th2, and then classifies m2, m5, m6 and m10 into the second category; the first electronic device detects that the distances L3, L8 and L9 are within the range of Th3, and then classifies m3, m8 and m9 into the third category.

[0117] The first electronic device may also classify the local models of the i-th round into N categories by other classification methods. Optionally, the first electronic device may obtain the amount of change between the local model of the i-th round uploaded by each second electronic device and the global model issued in the i-th round; and determine the category to which each local model belongs based on each obtained amount of change and the preset N amount of change threshold ranges.

[0118] Specifically, the first electronic device can pre-store the change threshold range corresponding to each class, obtain the change threshold range of the change between the jth local model in the i-th round and the global model issued in the i-th round, and the first electronic device classifies the jth local model into the class corresponding to the change threshold range.

[0119] For example, the first electronic device is divided into three categories. The change threshold range corresponding to the first category is Var1, the distance threshold range corresponding to the second category is Var2, and the distance threshold range corresponding to the third category is Var3. The global model issued in the i-th round is denoted as M i There are 10 local models in the i-th round, which are denoted as m1, m2, m3, m4, m5, m6, m7, m8, m9 and m10. The first electronic device calculates the difference between each local model and M i The first electronic device obtains the change between m1 and M i The change between D1, D1 = m1-M avg2 , m2 and M i The change between D2 = m2-M avg2 Similarly, the first electronic device can obtain other local models and M i The amount of change between them is recorded as D3, D4, ..., D10. If the first electronic device detects that the amount of change D1, D4 and D7 are within the range of Var1, m1, m4 and m7 are classified into the first category. If the first electronic device detects that the amount of change D2, D5, D6 and D10 are within the range of Var2, m2, m5, m6 and m10 are classified into the second category; if the first electronic device detects that the amount of change D3, D8 and D9 are within the range of Var3, m3, m8 and m9 are classified into the third category.

[0120] Step 704: The first electronic device aggregates the local models in each category to obtain N first models.

[0121] Specifically, the first electronic device may aggregate the local models in each class to obtain N first models. The first electronic device may aggregate the local models in each class by average aggregation. Optionally, the first electronic device may also determine the third aggregation weight of each local model according to the number of training samples of each local model. The first electronic device aggregates the local models in the class according to the third aggregation weight of each local model in the class to obtain the first model of the class.

[0122] For example, 7 participants upload their local models trained in round i to the central party. In this example, the preset threshold is set to 6. The first electronic device detects that the number of local models is greater than 6 and determines to divide the 7 local models into 4 categories. The first electronic device stores 4 categories and the change threshold range corresponding to each category. Figure 8 As shown, participant 1 uploaded local model 1, participant 2 uploaded local model 2, ..., participant 7 uploaded local model 7. In this example, the central party can obtain the change between each local model and the global model of the i-th round, and divide the 7 local models into 4 categories according to each change and the change threshold range corresponding to each of the 4 categories. The classification process can refer to step 703, which will not be repeated here. The first category includes: local model 1, local model 2 and local model 3; the second category includes: local model 4 and local model 5; the third category includes: local model 6; the fourth category includes: local model 7. The central party can aggregate the three local models of the first category according to the federated average algorithm to obtain the merged model 1 (that is, the first model corresponding to the first category), and aggregate the two local models of the second category in the same way to obtain the merged model 2. Aggregate the local models of the third category to obtain the merged model 3, and aggregate the local models of the fourth category to obtain the merged model 4. It can be understood that the local model contained in the third category is 1, and the aggregated merged model is the local model in this category.

[0123] In this example, the central party uses the merged model 1, the merged model 2, the merged model 3 and the merged model 4 as four first models.

[0124] Optionally, if the second electronic device uploads the number of training samples for each local model, then the number of training samples for the first model can be determined based on the local models of each category. Optionally, the first electronic device can use the sum of the number of training samples of all local models in the category as the number of training samples of the first model corresponding to the category.

[0125] For example, Figure 8 As shown, the number of training samples of local model 1 is num1, the number of training samples of local model 2 is num2, and the number of training samples of local model 3 is num3. The number of training samples of the merged model 1 is num_1=num1+num2+num3.

[0126] Step 705: The first electronic device obtains a first impact estimation of each first model.

[0127] This step is similar to step 303, and the relevant description in step 303 may be referred to, which will not be repeated here.

[0128] Step 706: The first electronic device determines a first aggregation weight for each first model according to the first impact estimation of each first model.

[0129] This step is similar to step 304, and the relevant description in step 304 may be referred to, and will not be repeated here.

[0130] Step 707: The first electronic device aggregates each first model according to the first aggregation weight of the first model to obtain a global model of the (i+1)th round.

[0131] This step is similar to step 305, and the relevant description in step 305 may be referred to, and will not be repeated here.

[0132] Step 708: The first electronic device transmits the global model information of the i+1th round to each second electronic device based on the global model of the i+1th round to perform the next round of federated learning until the preset training termination condition is met to obtain a trained federated learning model.

[0133] This step is similar to step 306, and you can refer to the relevant description in step 306, which will not be repeated here.

[0134] In this example, when the number of participants is large (i.e., the number of participants exceeds a preset threshold, such as 20, 10, etc.), the central party can classify the local models of the current round, aggregate the local models in each class, and obtain a first model for determining the global model of the next round. Through classification and aggregation operations, the number of first models is reduced, thereby reducing the amount of calculation for determining the global model of the next round.

[0135] The second electronic device in the embodiment of the present application serves as a participant, and the second electronic device may be a smart phone, a tablet computer, a laptop computer, etc.

[0136] Fig. 9 This is a schematic diagram of the structure of a second electronic device 100 shown in an embodiment of the present application. It should be understood that: Fig. 9 The second electronic device 100 shown in the figure is only one example of the second electronic device, and the electronic device 100 may have more or less components than those shown in the figure, may combine two or more components, or may have a different configuration of components. Fig. 9 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0137] The second electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.

[0138] Fig.10 It is a software structure block diagram of the second electronic device 100 according to an embodiment of the present application.

[0139] The layered architecture of the second electronic device 100 divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into three layers, namely, the application layer, the application framework layer, and the kernel layer from top to bottom. It is understandable that Fig.10 The layers in the software structure and the components contained in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer layers than shown in the figure, and each layer may include more or fewer components, which is not limited in the present application.

[0140] like Fig.10 As shown, the application layer can include a series of application packages. The application packages can include model training applications, maps, WLAN, calendar, short messages, gallery, calls, navigation, Bluetooth, camera and other applications. The application framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The application framework layer includes some predefined functions.

[0141] The model training application can be used to send a model training instruction to the first electronic device according to the model training instruction input by the user. The model training application can obtain training data according to the model training instruction, and the training data can be data in the gallery or training data downloaded from the network. After receiving the global model sent by the first electronic device, the model training application can perform model training according to the global model and the training data, and upload the trained local model to the first electronic device.

[0142] like Fig.10 As shown, the application framework layer may include a window manager, a resource manager, a content provider, a view system, a phone manager, a notification manager, and the like.

[0143] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0144] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0145] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0146] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0147] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.).

[0148] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0149] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0150] Understandably, Fig.10 The layers in the software structure shown and the components included in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer layers than shown, and each layer may include more or fewer components, which is not limited in the present application.

[0151] It is understandable that, in order to realize the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.

[0152] This embodiment also provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the method of federated learning in the above-mentioned embodiment. The storage medium includes: a U disk, a mobile hard disk, a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0153] This embodiment also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the above-mentioned related steps to implement the method of federated learning in the above-mentioned embodiment.

[0154] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above and will not be repeated here.

[0155] Any content of each embodiment of the present application, as well as any content of the same embodiment, can be freely combined. Any combination of the above content is within the scope of the present application.

[0156] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A method of federated learning, It is characterized in that Applied to a first electronic device, the first electronic device is communicatively connected with at least two second electronic devices, the method includes: Sending the global model information of the i-th round of federated learning to each of the second electronic devices, so that each of the second electronic devices performs local model training based on the i-th round of global model information, and uploading the i-th round of local model information to the first electronic device, wherein, if i is an integer greater than 1, the global model information includes the global model or the gradient information of the global model, and if i=1, the global model information is a preset initial model, and the local model information includes the local model or the gradient information of the local model; Determine the first model for the (i+1)th round of aggregation operation according to each uploaded local model information; Obtaining a first impact estimate of each first model, where the first impact estimate of the first model is used to evaluate the impact of the first model on the aggregation operation of the (i+1)th round; Determining a first aggregation weight for each first model according to the first impact estimate of each first model; Aggregate each first model according to the first aggregation weight of each first model to obtain a global model of the (i+1)th round; According to the global model of the (i+1)th round, transmitting the global model information of the (i+1)th round to each of the second electronic devices for the next round of federated learning, until a preset training termination condition is met, thereby obtaining a trained federated learning model; The obtaining of the first impact estimate of each first model includes: Obtaining model information of each first model in the i-th round or the number of first models of the first model in the i-th round, wherein the model information includes the number of training samples and a training log, wherein the number of training samples is the number of training samples of the local model trained by the second electronic device, and the training log includes an evaluation index of the local model trained by the second electronic device, wherein the evaluation index includes: accuracy, recall rate or F1 score of the model; Determine the second aggregation weight of each first model according to the model information of each first model, or obtain an average value of the number of the first models as the second aggregation weight of each first model; Aggregate each first model according to the second aggregation weight of each first model to generate a first benchmark model; Obtain the second model corresponding to each first model respectively, wherein the second model corresponding to the j-th first model is a model obtained by aggregating the first models except the j-th first model, j is an integer greater than or equal to 1, and the maximum value of j is equal to the number of the first models; Obtaining a first impact estimate of each first model according to the first benchmark model and the second model corresponding to each first model; The determining, according to the first impact estimation of each first model, the first aggregation weight of each first model comprises: Obtaining an average of the first impact estimates of all first models in the i-th round as an average impact estimate; The difference between the first impact estimate of the first model and the average impact estimate is obtained as the second difference; and the sum of the second aggregation weight of the first model and the second difference is obtained as the first aggregation weight of the first model.

2. The method according to claim 1, It is characterized in that The step of obtaining a first impact estimate of each first model according to the first benchmark model and the second model corresponding to each first model includes: Obtaining an evaluation index of the first benchmark model; Obtaining an evaluation index of the second model corresponding to each first model; According to the evaluation index of the first benchmark model and the evaluation index of the second model corresponding to each first model, The difference between the evaluation index of the first benchmark model and the evaluation index of the second model corresponding to each first model is respectively obtained as the first impact estimate of each first model.

3. The method according to claim 1, It is characterized in that If the model information of the first model includes a number of training samples for indicating the acquisition of the first model; The determining, according to the model information of each first model, the second aggregation weight of each first model includes: Get the total number of training samples for all first models generated in round i; A quotient between the number of training samples of each first model and the total number is obtained as a second aggregation weight of each first model.

4. The method according to claim 1, It is characterized in that The step of determining the first model for the (i+1)th round of aggregation operation according to each uploaded local model information includes: Determine, according to each uploaded local model information, a local model generated by each second electronic device in the i-th round; Divide each local model in the i-th round into N categories, where N is an integer greater than 1; The local models in each category are aggregated to obtain N first models.

5. The method according to claim 4, It is characterized in that Aggregate the local models in each category to obtain N first models, including: The following processing is performed for the local model in each class: Get the model number of the local model in the class; Obtaining an average value of the number of models as a third aggregation weight of each local model in the class; Each local model in the class is aggregated according to the third aggregation weight of each local model in the class to generate a first model.

6. The method according to claim 4, It is characterized in that Divide each local model in the i-th round into N categories, including: K-means clustering is used to divide the local models of the i-th round into N categories.

7. The method according to claim 4, It is characterized in that Divide each local model in the i-th round into N categories, including: Aggregate the local models generated by each second electronic device in the i-th round to obtain a second benchmark model; respectively obtaining the distance between each local model and the second reference model; According to each acquired distance and the preset N distance threshold ranges, the class to which each local model belongs is determined.

8. The method according to claim 4, It is characterized in that Divide each local model in the i-th round into N categories, including: Obtaining a change between the local model of the i-th round uploaded by each second electronic device and the global model issued in the i-th round; The class to which each local model belongs is determined according to each acquired variation and the preset N variation threshold ranges.

9. The method according to claim 4, It is characterized in that Before classifying each local model in the i-th round into N categories, the method further includes: It is detected that the number of local models in the i-th round is greater than a preset threshold.

10. The method according to claim 1, It is characterized in that The step of determining the first model for the (i+1)th round of aggregation operation according to each uploaded local model information includes: Determine, according to each uploaded local model information, a local model generated by each second electronic device in the i-th round; When it is detected that the number of local models in the i-th round is less than or equal to a preset threshold, the local model in the i-th round is used as the first model in the i-th round.

11. The method according to claim 1, It is characterized in that Before sending the global model information of the i-th round of federated learning to each of the second electronic devices, the method further includes: In response to the model training requests sent by at least two of the second electronic devices, acquiring the initial model matching the model training requests; After obtaining the trained federated learning model, the method further includes: The federated learning model is sent to each of the second electronic devices respectively.

12. An electronic device, It is characterized in that include: a memory and a processor, the memory being coupled to the processor; The memory stores program instructions, and when the program instructions are executed by the processor, the electronic device executes the federated learning method described in any one of claims 1-11.

13. A computer-readable storage medium comprising a computer program, It is characterized in that When the computer program runs on an electronic device, the electronic device executes the method of federated learning described in any one of claims 1 to 11.