A fast and accurate federated learning method and application for non-independent and identically distributed scenarios
By encrypting and grouping data feature maps for terminal devices, and using the federated learning aggregation algorithm of device grouping, the gradient divergence problem of federated learning in non-independent and identically distributed scenarios is solved, the convergence speed and accuracy of the model are improved, and the communication load is reduced. Improved the efficiency of federated learning.
Patent Information
- Application Number
- CN202011284944.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-17
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2040-11-17
AI Technical Summary
In non-IID scenarios, the accuracy of traditional federated learning will drop dramatically, and more information communication rounds will be required, which will increase network bandwidth pressure, causing device gradients to diverge, affecting performance.
By extracting feature maps from the sample data of each terminal device, encrypting and grouping them, and using a federated learning aggregation algorithm based on device grouping, devices are randomly selected for gradient aggregation in each round of training to reduce gradient divergence and improve the convergence speed of the global model. and precision.
Stabilize the direction of global model optimization, accelerate convergence, reduce the number of training rounds, improve model inference accuracy, reduce communication load, and improve federated learning efficiency.
Smart Images

Figure CN114581750B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of machine learning and relates to a federated learning method and application for each terminal device in a scenario where data is not independent and identically distributed. Background Art
[0002] With the prosperity of artificial intelligence and cloud computing applications, federated learning has gradually become a popular distributed machine learning paradigm in cloud-based applications. Nowadays, federated learning has been widely used in many fields such as surveillance cameras and autonomous driving. Compared with sending all local data to the central model, federated learning assigns the model to each data source (that is, each device) to assist each device in model training. In federated learning, the cloud is responsible for integrating the models in all device terminals into a global model and sending the global model to all terminal devices. During the model training process, each terminal device only uploads the model update information obtained from local training to the cloud for aggregation of model weights, thereby achieving privacy protection of local data of each terminal device and reducing the overall communication overhead of the system.
[0003] Although federated learning has great application value in collaborative machine learning of various device terminals, it is greatly troubled by the disadvantage of inconsistent data distribution of various device terminals. When the data distribution received by each terminal device is independent and identically distributed, the stochastic gradient obtained by training the local model in each device terminal is an unbiased estimate of the overall gradient, so traditional federated learning can show excellent performance. However, when the data distribution received by each device in the system is skewed and non-independent and identically distributed, the models in each device terminal will converge and optimize in different directions during training. Due to the phenomenon of gradient divergence of each device terminal, the accuracy of traditional federated learning will drop sharply in the case of such data distribution. In addition, compared with the independent and identically distributed data scenario, when the data in each terminal device is non-independent and identically distributed, traditional federated learning requires more information communication rounds to achieve convergence of the global model, which will add huge pressure to the device's scarce network bandwidth. Summary of the invention
[0004] In order to address the shortcomings of the prior art, the purpose of the present invention is to provide a fast and accurate federated learning method for non-independent and identically distributed scenarios. The method starts from reducing the adverse effect of gradient divergence generated by non-independent and identically distributed data collected in each terminal device on the federated learning performance, groups the terminal devices participating in federated learning, and in each round of federated learning training, uses the federated learning aggregation algorithm based on device grouping proposed in the present invention to perform gradient aggregation of the global model, which can effectively improve the reasoning accuracy of the global model trained by federated learning.
[0005] The specific technical solution for achieving the purpose of the present invention is:
[0006] A fast and accurate federated learning method for non-IID scenarios, the method comprising the following specific steps:
[0007] Step 1: Preprocessing:
[0008] 1) Extract feature graphs from sample data collected by each terminal device of federated learning and calculate their average value as the feature graph of the device;
[0009] 2) Encrypting the characteristic graph of each terminal device;
[0010] 3) Group the terminal devices according to the encrypted results.
[0011] Step 2: Federation training:
[0012] The grouping of each terminal device in the previous preprocessing stage is used as a constraint for device selection in this stage. In each round of model training, the device grouping-based federated learning aggregation algorithm proposed in the present invention is used to perform gradient aggregation of the global model.
[0013] in,
[0014] The extracted feature graph is a feature graph extracted from all data samples collected by each device using the pre-trained model provided by Keras;
[0015] The method further includes calculating an average value, calculating an average value of the feature graphs of all samples in each device as the feature graph of the device.
[0016] The feature map encryption operation is to use the p-stable local sensitive hash function family to perform an encryption operation on the feature map of each of the above-mentioned devices; the operation needs to set the number of the function family to be used, and multiple hash values obtained by encrypting the feature map of a single terminal device with multiple local sensitive hash functions constitute a hash vector of a single device;
[0017] The device grouping operation is to use the K-means algorithm to compare the similarity of the hash vectors of each terminal device obtained above and group all the terminal devices accordingly;
[0018] The device grouping-based federated learning aggregation algorithm proposed in the present invention is that in each round of training, a terminal device is randomly selected from each group of all terminal devices obtained above to participate in the gradient aggregation of the global model of this round of federated learning until the training is completed.
[0019] The present invention also provides an application of the above method in federated learning in a non-independent and identically distributed scenario.
[0020] The beneficial effects of the present invention include: 1. Stabilizing the optimization direction of the global model, thereby accelerating the convergence of the global model and reducing the number of training rounds of federated learning. 2. Improving the model reasoning accuracy after training. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 It is a preprocessing workflow diagram of the present invention.
[0022] Figure 2 This is the federated learning workflow diagram of the present invention.
[0023] Figure 3 It is a result diagram of an embodiment of the present invention. DETAILED DESCRIPTION
[0024] The present invention is further described in detail with reference to the following specific examples and drawings. The process, conditions, experimental methods, etc. for implementing the present invention, except for the contents specifically mentioned below, are all common knowledge and common common sense in the art and are not particularly limited by the present invention.
[0025] The present invention proposes a fast and accurate federated learning method for non-independent and identically distributed scenarios, which can effectively improve the reasoning accuracy of the global model trained by federated learning. The present invention groups the terminal devices participating in federated learning, and in the federated learning training phase, in each round of training, uses the federated learning aggregation algorithm proposed by the present invention to perform gradient aggregation of the global model, and finally effectively improves the reasoning accuracy of the global model trained by federated learning.
[0026] The present invention comprises the following steps:
[0027] Step 1: Preprocessing:
[0028] 1) Extract feature graphs from sample data collected by each terminal device of federated learning and calculate their average value as the feature graph of the device;
[0029] 2) Encrypting the characteristic graph of each terminal device;
[0030] 3) Group the terminal devices according to the encrypted results.
[0031] Step 2: Federation training:
[0032] The grouping of each terminal device in the previous preprocessing stage is used as a constraint for device selection in this stage. In each round of model training, the device grouping-based federated learning aggregation algorithm proposed in this invention is used to perform gradient aggregation of the global model. The aggregation step of federated learning is divided into two parts: 1. Device selection; 2. Gradient aggregation operation of the gradient of the selected device and the cloud model.
[0033] The steps specifically include:
[0034] (1) Device feature map extraction strategy: The device feature map extraction strategy proposed in the present invention is based on the samples in each device. First, the features of each sample in each device are extracted using the pre-trained model provided by Keras. Considering the limitations of device storage and computing power, a smaller pre-trained model in Keras is selected as much as possible to extract the feature map of the sample. After extracting the feature maps of all samples in each device, the average value of the feature maps of all samples contained in the device is calculated.
[0035] (2) Feature graph encryption strategy: Directly using the feature graph of each device to perform similarity comparison and grouping of the data distribution of each device has the risk of exposing the original samples collected in each device. Therefore, the present invention proposes to use the p-stable local sensitive hash function family to encrypt the feature graph of each device. Each hash function of the local sensitive hash function family can be expressed by the formula:
[0036]
[0037] Among them, v is the average value of the feature map of each device obtained by the above method; a is an integer with the same dimension as the feature map, which obeys the independent and identical distribution of p-stable; b is a real number that obeys a uniform distribution in the interval [0, r]; r is a positive real number representing the hash interval window. According to the properties of the p-stable local sensitive hash function family, using it to encrypt the feature map of each device can maintain the distribution characteristics of the samples of each device, and the original data samples of each device cannot be obtained from the hash values obtained. At the same time, the number of hash functions used can be manually set to control the length of the vector composed of the encrypted hash values. Setting a reasonable number of hash functions without affecting the experimental results can achieve data dimensionality reduction, thereby saving network communication resources.
[0038] (3) Device grouping method: After obtaining the hash vectors of each device feature map, directly use the K-means algorithm to cluster and group them. You only need to set the number of required groups. The K-means algorithm performs grouping operations based on the Euclidean distance between each hash vector. The Euclidean distance is defined as:
[0039]
[0040] Among them, x is the hash vector of each device, and c is the group center point closest to x. The sum of the Euclidean distances between the hash vector of each device and its nearest center point is continuously reduced iteratively until it is less than the threshold, and the grouping is completed.
[0041] (4) Federated learning device selection strategy: After the three stages of feature map extraction, feature map encryption, and device grouping in the early preprocessing stage, all devices participating in federated learning training are grouped according to the similarity of the sample distribution collected by the devices. The grouping results will serve as the constraints for device selection in each round of the training stage.
[0042] In each round of federated learning, a device is first randomly selected from each group, and then the global model is sent to these devices. After the selected devices obtain the latest global model, they perform local training. After the training is completed in the device terminal, the gradient of the model update is uploaded to the cloud server for gradient aggregation of the global model.
[0043] The overall algorithm is as follows:
[0044]
[0045]
[0046]
[0047] The present invention can accelerate the convergence speed of federated learning when the devices are not in independent and identically distributed, improve the reasoning accuracy of the model trained by federated learning, greatly reduce the training communication load, and improve the efficiency of federated learning.
[0048] Example
[0049] The method of the present invention focuses on the scenario where the environment in which each terminal device is located is a scenario where the samples are not independent and identically distributed. As a specific embodiment, the process is as follows:
[0050] 1. CIFAR-10 is selected as the experimental data set of the present invention. The entire set contains 50,000 training sets and 10,000 test sets, both of which contain 10 categories, such as cats, dogs, birds, etc.
[0051] 2. To simulate the non-IID scenario of each device, the present invention re-divides the data set, divides the training set into 100 equal parts and distributes them to 100 terminal devices, where each device contains only 500 pictures belonging to the same category. For example, device 1 contains only 500 pictures of cats, and device 2 contains only 500 pictures of dogs, etc.
[0052] 3. Use the pre-trained MobileNetV2 model provided by Keras to extract feature maps (feature map dimension is 1*1280) from all images in 100 devices, and calculate the average value of each device as the feature map of the device (dimension is 1*1280). (Preprocessing step 1 above)
[0053] 4. Use the p-stable local sensitive hash function family to generate formulas Generate 5 local sensitive hash functions, and use these 5 hash functions to hash the feature graphs of each device obtained in step 3 to obtain a hash vector (dimension is 1*5). (Preprocessing step 2 above)
[0054] 5. Use the K-means algorithm to group the hash vectors obtained from each device in 4, set the number of groups to 10, and divide 100 devices into 10 groups. (Preprocessing step 3 above)
[0055] 6. Set the federated learning to train for 5000 rounds. In each round of federated learning, first randomly select a device from each group obtained in 5, and then send the global model to these devices. After the selected devices obtain the latest global model, they perform local training. After the training is completed in the device terminal, the gradient of the model update is uploaded to the cloud server for gradient aggregation of the global model until the training is completed. (The federated learning algorithm proposed in the present invention)
[0056] 7. After each round of gradient aggregation, the global model is tested for inference accuracy. The 10,000 images in the test set are used, and the ratio of the number of correctly inferred images to the number of images in the entire set is recorded as the inference accuracy. The test results are recorded and visualized as follows: Figure 3 .
[0057] 8. As a comparison of the experimental results, the traditional federated learning algorithm is used without preprocessing steps, and 10 devices are randomly selected from 100 devices for gradient aggregation in each round of training.
[0058] according to Figure 3 The experimental results show that the method proposed in the present invention performs much better than the traditional federated learning algorithm. Specifically, 1. At the same number of training rounds, the method proposed in the present invention has higher reasoning accuracy than the model obtained by the traditional federated learning algorithm; 2. To achieve the same model reasoning accuracy, the method proposed in the present invention requires a better number of training rounds than traditional federated learning; 3. Within a reasonable number of training rounds, the method proposed in the present invention can achieve a higher number of training rounds (Note: From the experimental result graph, it can be seen that at about 5000 rounds, the model reasoning accuracy curves obtained by the two methods began to flatten, and there will be no further improvement in the future); 4. The training stability of the method proposed in the present invention is better than that of the traditional method (Note: The model reasoning accuracy curve obtained by the method proposed in the present invention has a smaller oscillation amplitude).
[0059] The protection content of the present invention is not limited to the above embodiments. Without departing from the spirit and scope of the present invention, changes and advantages that can be thought of by those skilled in the art are included in the present invention and are protected by the attached claims.
Claims
1. A fast and accurate federated learning method for non-IID scenarios, It is characterized in that The method comprises the following specific steps: Step 1: Preprocessing: 1) Extract feature graphs from sample data collected by each terminal device of federated learning and calculate their average value as the feature graph of the device; 2) Encrypting the feature graph of each terminal device; the feature graph encryption operation is to use the p-stable local sensitive hash function family to perform an encryption operation on the feature graph of each of the aforementioned devices; the operation sets the number of the function family to be used, and multiple hash values obtained by encrypting the feature graph of a single terminal device using multiple local sensitive hash functions constitute a hash vector of a single device; The formula of each hash function of the locality sensitive hash function family is expressed as: Where v is the average value of the feature graphs of each device obtained by the above method; a is an integer with the same dimension as the feature graph and obeys the independent and identical distribution of p-stable; b is a real number that obeys a uniform distribution in the interval [0, r]; r is a positive real number representing the hash interval window; From the properties of the p-stable local sensitive hash function family, it can be seen that the feature map of each device is encrypted using it to maintain the sample distribution characteristics of each device, and the original data sample of each device cannot be obtained from the hash value obtained by it; 3) Grouping each terminal device according to the encrypted result; Step 2: Federation training: The grouping of each terminal device in the above preprocessing stage is used as a constraint for device selection in this stage. In each round of model training, a federated learning aggregation algorithm based on device grouping is used to perform gradient aggregation of the global model; the federated learning aggregation algorithm based on device grouping is to randomly select a terminal device in each group of all terminal devices obtained above to participate in the gradient aggregation of the global model of this round of federated learning in each round of training until the training is completed.
2. The method according to claim 1, It is characterized in that The extracted feature graph is a feature graph extracted from all data samples collected by each device using the pre-trained model provided by Keras.
3. The method according to claim 2, It is characterized in that The method further includes calculating an average value, calculating an average value of the feature graphs of all samples in each device as the feature graph of the device.
4. The method according to claim 1, It is characterized in that The device grouping operation is to use the K-means algorithm to compare the similarity of the hash vectors of each terminal device obtained above and group all the terminal devices accordingly.
5. The method according to claim 4, It is characterized in that The K-means algorithm performs grouping operations on the Euclidean distance between hash vectors, where the Euclidean distance is defined as: Among them, x is the hash vector of each device, and c is the group center point closest to x; the sum of the Euclidean distances between the hash vector of each device and its nearest center point is continuously iterated to reduce until it is less than the threshold, and the grouping is completed.
6. An application of the method according to any one of claims 1 to 5 in federated learning in a non-independent and identically distributed scenario.
