Network model training method and device, electronic equipment and storage medium
By calculating the global gradient value and shrinkage factor in federated learning to shrink the weight of the network model, the data privacy issues and acquisition difficulties caused by additional training sets in federated learning are solved, and the efficiency and security of model training are improved.
Patent Information
- Application Number
- CN202410500530.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-24
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-04-24
AI Technical Summary
In federated learning, additional training sets used to learn weight shrinkage factors and aggregation weights may cause data privacy issues, and in real applications it is difficult to obtain a training set that is consistent with the test data distribution, making it difficult to obtain additional training sets.
By sending the first global model parameters of the network model to at least two clients, triggering the clients to train based on local data, returning the trained model parameters to the server, calculating the global gradient value and shrinkage factor, and performing network operations based on these parameters. The weights of the model are shrunk, thereby avoiding the use of additional training sets to learn weight shrinkage factors and aggregate weights.
This avoids data privacy issues, avoids the acquisition of additional training sets, and improves the efficiency and security of model training.
Smart Images

Figure CN118799698A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to network model training methods, devices, electronic devices and storage media. Background Art
[0002] With the rapid development of computer computing and storage capabilities, using large-scale data to solve problems through machine learning has brought significant benefits to scientific research and real-world applications. Therefore, machine learning is increasingly being used in various fields such as finance, healthcare, and business. In order to avoid user privacy issues during model training, Federated Learning (FL) came into being.
[0003] In related technologies, the global weight shrinkage phenomenon is found in the weighted aggregation process of federated learning, and the weight shrinkage factor and aggregation weight are learned separately through additional training sets. However, such additional training sets may cause data privacy issues in the federated learning framework, and it is difficult to obtain training sets that are consistent with the distribution of test data for training in real applications, and it is difficult to obtain additional training sets. Summary of the invention
[0004] The main purpose of this application is to provide a network model training method, device, electronic device and storage medium, aiming to avoid learning weight shrinkage factors and aggregation weights through additional training sets, thereby avoiding data privacy issues and avoiding the acquisition of additional training sets. The technical solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides a network model training method, comprising:
[0006] Sending first global model parameters of the network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameters and local data, and returning the trained client model parameters to the server, wherein the local data is an image carrying a species category identifier;
[0007] Aggregating the received plurality of client model parameters, and determining a global gradient value based on the aggregated second global model parameter and the first global model parameter;
[0008] Get preset hyperparameters and global learning rate;
[0009] Determine a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter;
[0010] Based on the first shrinkage factor and the second global model parameter, a first weight shrinkage is performed on the network model to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image.
[0011] In a second aspect, an embodiment of the present application provides a network model training device, including:
[0012] A sending unit, sending a first global model parameter of the network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameter and local data, and returning the trained client model parameter to the server, wherein the local data is an image carrying a species category identifier;
[0013] a first determining unit, configured to aggregate the received plurality of client model parameters, and determine a global gradient value based on the aggregated second global model parameter and the first global model parameter;
[0014] The acquisition unit is used to obtain preset hyperparameters and global learning rate;
[0015] A second determining unit, configured to determine a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter;
[0016] A weight shrinkage unit is used to perform a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image.
[0017] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the above method when executed by the processor.
[0018] In a fourth aspect, an embodiment of the present application provides a storage medium having a computer program stored thereon, and the computer program implements the steps of the above method when executed by a processor.
[0019] In an embodiment of the present application, by sending the first global model parameter of the network model to at least two clients, each client is triggered to train the network model based on the received first global model parameter and local data, and the trained client model parameter is returned to the server, wherein the local data is an image carrying a species category identifier; the received multiple client model parameters are aggregated, and a global gradient value is determined based on the aggregated second global model parameter and the first global model parameter; a preset hyperparameter and a global learning rate are obtained; a first shrinkage factor is determined based on the first global model parameter, the global gradient value, the preset hyperparameter and the global learning rate, and the first shrinkage factor is the shrinkage factor corresponding to the client model parameter; a first weight shrinkage is performed on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image. The first weight shrinkage of the network model is achieved by calculating the first shrinkage factor, thereby avoiding learning the weight shrinkage factor and the aggregation weight through an additional training set, thereby avoiding causing data privacy issues and avoiding the acquisition of additional training sets. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 A system diagram of the network model training method provided in an embodiment of the present application.
[0022] Figure 2 It is a flowchart of a network model training method provided in an embodiment of the present application.
[0023] Figure 3 It is a structural diagram of a network model training device provided in an embodiment of the present application.
[0024] Figure 4 It is a structural diagram of a network model training device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0025] 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 only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0026] The present application provides a network model training method, apparatus, storage medium and computer equipment. Figure 1 , Figure 1 System diagram of the network model training method provided for the embodiment of the present application. The system may include at least two clients 1000, at least one electronic device 2000, at least one database 3000, and a network 4000. The client 1000 may be connected to the electronic device 2000 via the network 4000. The electronic device 2000 is any device with computing hardware that can support and execute services related to network model training. The network 4000 may be a wireless network or a wired network, such as a wireless network such as a wireless local area network (WLAN), a local area network (LAN), a cellular network, a 2G network, a 3G network, a 4G network, a 5G network, etc. In addition, different clients 1000 may also use their own Bluetooth network or hotspot network to connect to other terminals or to electronic devices 2000, etc. For example, a client 1000 is connected to an electronic device 2000 via a Bluetooth network, and another client 1000 is connected to an electronic device 2000 via a hotspot network. In addition, the system may include multiple databases 3000 , which are coupled to different electronic devices 2000 , and network model parameters of the network model before and after training may be stored in the databases 3000 .
[0027] It should be noted that Figure 1 The system diagram of the network model training system shown is only an example. The network model training system and scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Ordinary technicians in this field can know that with the evolution of the network model training system and the emergence of new transaction scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0028] In this embodiment, the description will be made from the perspective of a network model training device, which can be specifically integrated into a computer device having a storage unit and a microprocessor installed therein and having computing capabilities.
[0029] See also Figure 2 , Figure 2A flowchart of a network model training method is provided for an embodiment of the present application. Figure 2 As shown, the method of the embodiment of the present application may include the following steps S101-S105.
[0030] S101, sending first global model parameters of a network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameters and local data, and returning the trained client model parameters to the server, wherein the local data is an image carrying a species category identifier;
[0031] S102, aggregating the received plurality of client model parameters, and determining a global gradient value based on the aggregated second global model parameter and the first global model parameter;
[0032] S103, obtaining preset hyperparameters and global learning rate;
[0033] S104, determining a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter;
[0034] S105, performing a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage.
[0035] In the weighted aggregation process of federated learning, a global weight shrinkage phenomenon was discovered, and the weight shrinkage factor and aggregation weight were learned through additional training sets. However, such additional training sets may cause data privacy issues in the federated learning framework, and it is difficult to obtain training sets that are consistent with the distribution of test data for training in real applications, and it is difficult to obtain additional training sets. Therefore, an embodiment of the present application provides a method for determining the shrinkage factor in the weight shrinkage process by calculation, thereby avoiding learning the weight shrinkage factor and aggregation weight through additional training sets, thereby avoiding causing data privacy issues and avoiding the acquisition of additional training sets.
[0036] The following is a detailed description of each step:
[0037] S101, sending the first global model parameters of the network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameters and local data, and returning the trained client model parameters to the server, wherein the local data is an image carrying a species category identifier.
[0038] Among them, Federated Learning (FL) is a distributed training method that aims to promote the training of high-quality models by coordinating multiple clients or devices while retaining the privacy of their respective local data sets. It provides a privacy protection mechanism that can effectively use the computing resources of client devices to train models, and then unify and merge the trained models on the server side to obtain the overall training model, which can avoid the transmission and sharing of private data during training, thereby preventing the leakage of private information during data transmission. Federated learning can make full use of the large amount of valuable data set resources in client devices.
[0039] Specifically, in the network model application scenario provided in the embodiment of the present application, the network model is used for image classification, for example, to distinguish the species of images input into the trained network model. For example: input an image of a kitten, and use the trained network model to determine whether the species in the image is a cat or a dog. The network model can also be used for speech noise removal, for example, to remove noise from speech input into the trained network model. The network model can also be applied to various scenarios, which are not limited here.
[0040] Among them, based on the framework of federated learning, the electronic device sends the first global model parameters of the network model obtained in the previous training round to each of at least two clients, triggering each client to train the network model based on the received first global model parameters and local data, and return the trained client model parameters to the server.
[0041] S102, aggregating the received plurality of client model parameters, and determining a global gradient value based on the aggregated second global model parameters and the first global model parameters.
[0042] Among them, the aggregation process can be aggregated through FedAvg, FedAvgM, CCVR, FedDF, FeddBE, FedDisco, FedLAW and L-DAWA.
[0043] FedAvg is a standard algorithm for federated learning. Most federated learning algorithms follow its basic framework. Assume that there is a server and K clients, and each client has a private dataset D k , FedAvg trains T communication rounds until the model converges. The main process of each communication round t can be summarized as follows: the server aggregates the models uploaded by the client to obtain a new global model where λ k is the aggregation weight, is the client model parameter obtained after each client is trained. FedAvg often uses a simple average weight Or weighted according to the size of the local dataset, that is
[0044] FedAvgM stabilizes the training process through momentum updates on the server side. CCVR uses virtual representations to adjust the classifier of the global model. FedDF and FeddBE fine-tune the global model on the server using an additional dataset. FedDisco recalculates the aggregation weights using the dataset size and the degree of difference between the local and global category distributions. FedLAW re-examines the weighted aggregation process and discovers the global weight shrinkage phenomenon. The weight shrinkage factor and aggregation weight are learned separately using an additional proxy dataset. L-DAWA uses the cosine similarity between the local model and the global model as the aggregation weight for model aggregation, while taking into account the differences between different layers in the model.
[0045] Specifically, the multiple client model parameters are aggregated by any of the above-mentioned multiple aggregation methods to obtain the aggregated second global model parameter Global gradient value Based on the second global model parameter and the first global model parameter Sure.
[0046] In some implementations, determining the global gradient value based on the aggregated second global model parameter and the first global model parameter includes:
[0047] The difference between the aggregated second global model parameter and the first global model parameter is calculated to obtain a global gradient value.
[0048] Among them, the global gradient value is the second global model parameter With the first global model parameter The difference.
[0049] S103, obtaining preset hyperparameters and global learning rate.
[0050] Among them, the preset hyperparameter τ and the global learning rate η g Pre-set.
[0051] Specifically, in some embodiments, the global learning rate η g =1.
[0052] S104: Determine a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter.
[0053] Among them, after determining the global gradient value Afterwards, the first global model parameter Preset hyperparameter τ and the global learning rate η g , to determine the first shrinkage factor γ.
[0054] In some implementations, determining a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate includes:
[0055] (1) calculating a norm of a product of the global gradient value and the global learning rate to obtain a first calculation result;
[0056] (2) calculating the product of the norm of the first global model parameter and the preset hyperparameter to obtain a second calculation result;
[0057] (3) calculating the sum of the first calculation result and the second calculation result to obtain a third calculation result;
[0058] (4) Calculate the ratio of the second calculation result to the third calculation result to obtain a first shrinkage factor.
[0059] Among them, the federated learning algorithm aggregates Perform model aggregation using represents the pseudo gradient of client k in the tth communication round, then the updated local model It can be expressed as
[0060] The global learning rate η is set g = 1. Therefore, FedLAW introduces the shrinkage factor and the polymerization process It can be expressed as follows:
[0061]
[0062] in is the global gradient, It can be regarded as a global gradient update (optimization term). It can be regarded as a pseudo-gradient (regularization term) of global weight contraction. Therefore, the value of the contraction factor γ affects the regularization strength during the model aggregation process. A smaller contraction factor means a smaller gradient update and stronger regularization. When FedLAW uses additional data to learn the optimal contraction factor, it is found that the ratio of the norm of the optimization term and the regularization term in the above formula is stable at a constant τ, which can be expressed as follows:
[0063]
[0064] However, FedLAW used this to prove that the learned shrinkage factor can maintain the stability between the regularization term and the optimization term and improve the model effect, but did not further exploit this phenomenon. Therefore, this phenomenon can be used to calculate the shrinkage factor.
[0065] Based on the above phenomenon, the method FedLWS (Federate Learning with Layer-wise Weight Shrinking) is proposed to improve the generalization ability of federated learning by shrinking the layered weights. It can be seen that in the aggregation process, if the value of the constant τ is known, other parameters can be easily obtained during the training process, then the only unknown quantity in the formula is the shrinkage factor γ. Therefore, the constant τ is used as a hyperparameter, and it is easy to infer the expression of the shrinkage factor γ through the above formula as follows:
[0066]
[0067] The value of the shrinkage factor γ is directly calculated by the above expression. The numerator is the second calculation result obtained by calculating the product of the norm of the first global model parameter and the preset hyperparameter; the denominator includes the sum of the first calculation result obtained by calculating the norm of the product of the global gradient value and the global learning rate and the second calculation result, that is, the third calculation result; the shrinkage factor γ is the ratio of the second calculation result to the third calculation result.
[0068] S105, performing a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage, wherein the network model is used to predict the species category of the content in the input image.
[0069] Among them, after calculating the first shrinkage factor γ, the second global model parameter obtained by aggregation can be combined The network model is subjected to a first weight contraction to obtain a network model after the first weight contraction. The network model after the first weight contraction is used to predict the species category of the content in the input image in the application scenario of species category prediction.
[0070] In some implementations, performing a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain the network model after the first weight shrinkage includes:
[0071] (1) calculating the product of the first shrinkage factor and the second global model parameter to obtain a third global model parameter;
[0072] (2) Updating the model parameters in the network model to the third global model parameters to obtain the network model after the first weight contraction.
[0073] The third network model parameter of the subsequent network model is the product of the first shrinkage factor and the second global model parameter.
[0074] Among them, when obtaining the network model after the first weight shrinkage, it is necessary to determine whether the training of the network model after the first weight shrinkage is completed. If it is determined that the training of the network model after the first weight shrinkage is completed, it is determined that the training of the network model is completed, and the trained network model is obtained; if it is determined that the training of the network model after the first weight shrinkage is not completed, the network model parameters corresponding to the network model after the first weight shrinkage are determined as the first global model parameters, and the first global model parameters of the network model are sent to at least two clients in step 101, triggering each of the clients to train the network model based on the received first global model parameters and local data, and returning the trained client model parameters to the server, wherein the local data is an image carrying a species category identification step, and then continue to optimize the network model parameters.
[0075] Specifically, the method for determining whether the training of the network model after the first weight contraction is completed is as follows: calculate the difference value (that is, the loss value) between the label of the data in the verification set and the output data output by the network model after the first weight contraction, and compare the current loss value with the loss value obtained in the previous round of training. If the loss value for multiple consecutive rounds remains unchanged, or is less than the loss value for multiple consecutive historical rounds, it means that the trained model tends to be stable, that is, converges; or set a preset loss value, compare the loss value of the network model after the first weight contraction with the preset loss value, if the loss value exceeds the preset loss value, then it is determined that the training of the network model after the first weight contraction is not completed; if the loss value does not exceed the preset loss value, then it is determined that the training of the network model after the first weight contraction is completed.
[0076] Taking the species category prediction scenario as an example, the loss value can be calculated as follows: set the category label corresponding to the cat to 1 and the category label corresponding to the dog to 0. When the model outputs the maximum probability of the cat's probability of 0.8, calculate the difference between the category label corresponding to the cat of 1 and the predicted probability of 0.8 to get the loss value.
[0077] The method for determining whether the training of the network model after the first weight contraction is completed can also be: setting a preset training round, when obtaining the network model after the first weight contraction, determining whether this training round reaches the preset training round, if it does not reach the preset training round, it is determined that the training of the network model after the first weight contraction is not completed; if it reaches the preset training round, it is determined that the training of the network model after the first weight contraction is completed.
[0078] The preset training rounds can be determined according to the model effect. For example, when the training rounds are 200, it is known from the experimental data that the trained model has the best effect, and 200 is used as the preset training rounds.
[0079] The embodiment of the present application sends the first global model parameter of the network model to at least two clients, triggering each client to train the network model based on the received first global model parameter and local data, and returns the trained client model parameter to the server, wherein the local data is an image carrying a species category identifier; aggregates the received multiple client model parameters, and determines the global gradient value based on the aggregated second global model parameter and the first global model parameter; obtains the preset hyperparameter and the global learning rate; determines the first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter and the global learning rate, wherein the first shrinkage factor is the shrinkage factor corresponding to the client model parameter; performs the first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter, and obtains the network model after the first weight shrinkage, wherein the network model is used to predict the species category of the content in the input image. The first weight shrinkage of the network model is achieved by calculating the first shrinkage factor, thereby avoiding learning the weight shrinkage factor and the aggregation weight through an additional training set, thereby avoiding causing data privacy issues, and avoiding the acquisition of an additional training set.
[0080] In some implementations, after performing a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain the network model after the first weight shrinkage, the method further includes:
[0081] (1) obtaining first network layer model parameters corresponding to each network layer in the network model from the first global network model parameters;
[0082] (2) obtaining second network layer model parameters corresponding to each network layer in the network model from the second global model parameters;
[0083] (3) determining a second shrinkage factor corresponding to each of the network layers based on the first network layer model parameters corresponding to each of the network layers, the corresponding second network layer model parameters, the preset hyperparameters, and the global learning rate;
[0084] (4) Based on the second network layer model parameters corresponding to each of the network layers and the corresponding second shrinkage factors, a second weight shrinkage is performed on the weight-shrinked network model to obtain a second weight-shrinked network model.
[0085] Among them, FedLAW directly shrinks the weights of the entire model, but due to the differences between different layers of deep neural networks. Therefore, simply applying a single shrinkage factor to the entire model may not be able to effectively improve the generalization of the global model. Therefore, assigning different shrinkage factors γ to each layer of the model in a hierarchical manner, rather than using a single γ for the entire model, can further improve the generalization performance of the model. To address this problem, the embodiment of the present application further calculates the corresponding second shrinkage factor for each network layer in the network model.
[0086] Specifically, use γ l Represents the shrinkage factor of the first layer in the network model. The shrinkage factor of the first layer is calculated based on the following formula:
[0087]
[0088] In some implementations, determining the second shrinkage factor corresponding to each of the network layers based on the first network layer model parameters corresponding to each of the network layers, the corresponding second network layer model parameters, the preset hyperparameters, and the global learning rate includes:
[0089] (1) calculating the product of the norm of the second network layer model parameter corresponding to each of the network layers and the preset hyperparameter to obtain a fourth calculation result;
[0090] (2) calculating a norm of a difference between the first network layer model parameter corresponding to each of the network layers and the corresponding second network layer model parameter to obtain a fifth calculation result;
[0091] (3) calculating the product of the fifth calculation result and the global learning rate to obtain a sixth calculation result;
[0092] (4) calculating the sum of the sixth calculation result and the fourth calculation result to obtain a seventh calculation result;
[0093] (5) Calculate the ratio of the fourth calculation result to the seventh calculation result to obtain a second shrinkage factor corresponding to each of the network layers.
[0094] Among them, the fourth calculation result is The fifth calculation result is The sixth calculation result is The seventh calculation result is The fourth calculation result is the numerator in the following formula, and the seventh calculation result is the denominator in the following formula, thereby obtaining the network layer model parameter γ corresponding to the network layer l l .
[0095]
[0096] In some implementations, performing a second weight shrinkage on the learned network model based on the network layer model parameters corresponding to each of the network layers and the corresponding second shrinkage factor to obtain the network model after the second weight shrinkage includes:
[0097] (1) calculating the product of the network layer model parameter corresponding to each of the network layers and the corresponding second shrinkage factor to obtain the network layer model parameter corresponding to each of the network layers after the second weight shrinkage;
[0098] (2) synthesizing the network layer model parameters corresponding to the second weight contraction of the plurality of network layers to obtain a fourth global model parameter;
[0099] (3) Updating the model parameters in the network model to the fourth global model parameters to obtain the network model after the second weight contraction.
[0100] Among them, the second weight contraction is performed on the learned network model through the following formula to obtain the network model after the second weight contraction.
[0101]
[0102] Among them, the product of the second shrinkage factor corresponding to the network layer model parameter corresponding to each network layer is calculated to obtain the network layer model parameter after the second weight shrinkage corresponding to each network layer. For example, the second shrinkage factor corresponding to network layer 1 is γ1, and the corresponding network layer model parameter is Then the network model after the second weight contraction corresponding to network layer 1 is By analogy, the network model after the second weight contraction corresponding to each network layer is calculated. The network models after the second weight contraction corresponding to multiple network layers are synthesized to obtain the fourth global model parameters; the model parameters in the network model are updated to the fourth global model parameters to obtain the network model after the second weight contraction.
[0103] In the embodiment of the present application, by calculating the second shrinkage factor corresponding to each network layer, the network layer model parameters corresponding to each network layer after the second weight shrinkage are obtained based on the product of the second network layer model parameters corresponding to each network layer and the corresponding second shrinkage factor in the second weight shrinkage process, and the network layer model parameters corresponding to the second weight shrinkage of multiple network layers are synthesized to obtain the fourth global model parameters, and the network model after the second weight shrinkage is obtained. Thus, the differences between different layers of the model are taken into account to improve the model effect.
[0104] The following will be combined with the attached Figure 3 , the network model training device provided in the embodiment of the present application is introduced in detail. It should be noted that the attached Figure 3 The network model training device in this manual is used to execute Figure 2 For the convenience of explanation, only the part related to the embodiment of the present application is shown. For the specific technical details not disclosed, please refer to this specification. Figure 2 The embodiment shown.
[0105] See also Figure 3 , which shows a schematic diagram of the structure of a network model training device provided by an exemplary embodiment of the present application. The network model training device can be implemented as all or part of the device through software, hardware or a combination of both. The device 1 includes a sending unit 10, a first determining unit 20, an acquiring unit 30, a second determining unit 40 and a weight shrinking unit 50.
[0106] A sending unit 10 sends a first global model parameter of a network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameter and local data, and returns the trained client model parameter to the server, wherein the local data is an image carrying a species category identifier;
[0107] A first determining unit 20, configured to aggregate the received plurality of client model parameters, and determine a global gradient value based on the aggregated second global model parameter and the first global model parameter;
[0108] An acquisition unit 30 is used to acquire preset hyperparameters and a global learning rate;
[0109] A second determining unit 40 is used to determine a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter;
[0110] The weight shrinkage unit 50 is used to perform a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image.
[0111] Optionally, the second determining unit 40 is specifically used to calculate a norm of a product of the global gradient value and the global learning rate to obtain a first calculation result;
[0112] Calculating the product of the norm of the first global model parameter and the preset hyperparameter to obtain a second calculation result;
[0113] Calculating the sum of the first calculation result and the second calculation result to obtain a third calculation result;
[0114] The ratio of the second calculation result to the third calculation result is calculated to obtain a first shrinkage factor.
[0115] Optionally, the weight shrinkage unit 50 is specifically used to calculate the product of the first shrinkage factor and the second global model parameter to obtain a third global model parameter;
[0116] The model parameters in the network model are updated to the third global model parameters to obtain the network model after the first weight contraction.
[0117] Optionally, the device is further used to obtain first network layer model parameters corresponding to each network layer in the network model from the first global network model parameters;
[0118] Acquire second network layer model parameters corresponding to each network layer in the network model from the second global model parameters;
[0119] Determine a second shrinkage factor corresponding to each of the network layers based on the first network layer model parameters corresponding to each of the network layers, the corresponding second network layer model parameters, the preset hyperparameters, and the global learning rate;
[0120] Based on the second network layer model parameters corresponding to each of the network layers and the corresponding second shrinkage factors, a second weight shrinkage is performed on the weight-shrinked network model to obtain a second weight-shrinked network model.
[0121] Optionally, the device is further used to calculate the product of the norm of the second network layer model parameter corresponding to each of the network layers and the preset hyperparameter to obtain a fourth calculation result;
[0122] Calculate a norm of a difference between the first network layer model parameter corresponding to each of the network layers and the corresponding second network layer model parameter to obtain a fifth calculation result;
[0123] Calculate the product of the fifth calculation result and the global learning rate to obtain a sixth calculation result;
[0124] Calculating the sum of the sixth calculation result and the fourth calculation result to obtain a seventh calculation result;
[0125] The ratio of the fourth calculation result to the seventh calculation result is calculated to obtain a second shrinkage factor corresponding to each of the network layers.
[0126] Optionally, the first determining unit 20 is specifically used to calculate the product of the second network layer model parameter corresponding to each of the network layers and the corresponding second shrinkage factor to obtain the network layer model parameter corresponding to each of the network layers after the second weight shrinkage;
[0127] synthesizing the network layer model parameters corresponding to the second weight contraction of the plurality of network layers to obtain a fourth global model parameter;
[0128] The model parameters in the network model are updated to the fourth global model parameters to obtain the network model after the second weight contraction.
[0129] In an embodiment of the present application, by sending the first global model parameter of the network model to at least two clients, each client is triggered to train the network model based on the received first global model parameter and local data, and the trained client model parameter is returned to the server, wherein the local data is an image carrying a species category identifier; the received multiple client model parameters are aggregated, and a global gradient value is determined based on the aggregated second global model parameter and the first global model parameter; a preset hyperparameter and a global learning rate are obtained; a first shrinkage factor is determined based on the first global model parameter, the global gradient value, the preset hyperparameter and the global learning rate, and the first shrinkage factor is the shrinkage factor corresponding to the client model parameter; a first weight shrinkage is performed on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image. The first weight shrinkage of the network model is achieved by calculating the first shrinkage factor, thereby avoiding learning the weight shrinkage factor and the aggregation weight through an additional training set, thereby avoiding causing data privacy issues and avoiding the acquisition of additional training sets.
[0130] It should be noted that the network model training device provided in the above embodiment only uses the division of the above functional modules as an example when executing the network model training method. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the network model training device provided in the above embodiment and the network model training method embodiment belong to the same concept, and the implementation process thereof is detailed in the method embodiment, which will not be repeated here.
[0131] The serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0132] The present application also provides a storage medium having a computer program stored thereon. When the computer program is executed by a processor, the above-mentioned Figure 2 The method of the embodiment shown in the figure can be specifically executed by referring to Figure 2 The specific description of the illustrated embodiment will not be repeated here.
[0133] Please refer to Figure 4 , which shows a schematic diagram of the structure of a network model training device provided by an exemplary embodiment of this specification. The network model training device in this specification may include one or more of the following components: a processor 110, a memory 120, an input device 130, an output device 140, and a bus 150. The processor 110, the memory 120, the input device 130, and the output device 140 may be connected via a bus 150.
[0134] The processor 110 may include one or more processing cores. The processor 110 uses various interfaces and lines to connect the various parts of the entire network model training device, and executes various functions and processes data of the terminal 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 110 can integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, user pages, and applications; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 110, but may be implemented separately through a communication chip.
[0135] The memory 120 may include a random access memory (RAM) or a read-only memory (ROM). Optionally, the memory 120 includes a non-transitory computer-readable medium (Non-Transitory Computer-Readable Storage Medium). The memory 120 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc. The operating system may be an Android system, including a system deeply developed based on the Android system, an IOS system developed by Apple, including a system deeply developed based on the IOS system or other systems.
[0136] The memory 120 can be divided into an operating system space and a user space. The operating system runs in the operating system space, and native and third-party applications run in the user space. In order to ensure that different third-party applications can achieve good operating results, the operating system allocates corresponding system resources to different third-party applications. However, the requirements for system resources in different application scenarios in the same third-party application are also different. For example, in the local resource loading scenario, the third-party application has higher requirements for disk reading speed; in the animation rendering scenario, the third-party application has higher requirements for GPU performance. The operating system and third-party applications are independent of each other, and the operating system often cannot perceive the current application scenario of the third-party application in a timely manner, resulting in the operating system being unable to perform targeted system resource adaptation according to the specific application scenario of the third-party application.
[0137] In order for the operating system to distinguish the specific application scenarios of third-party applications, it is necessary to open up data communication between third-party applications and the operating system so that the operating system can obtain the current scenario information of third-party applications at any time, and then perform targeted system resource adaptation based on the current scenario.
[0138] The input device 130 is used to receive input commands or data, and includes but is not limited to a keyboard, a mouse, a camera, a microphone, or a touch device. The output device 140 is used to output commands or data, and includes but is not limited to a display device and a speaker. In one example, the input device 130 and the output device 140 can be combined, and the input device 130 and the output device 140 are touch screen displays.
[0139] The touch display screen can be designed as a full screen, a curved screen or a special-shaped screen. The touch display screen can also be designed as a combination of a full screen and a curved screen, or a combination of a special-shaped screen and a curved screen, which is not limited in the embodiments of the present application.
[0140] In addition, those skilled in the art can understand that the structure of the network model training device shown in the above drawings does not constitute a limitation on the network model training device, and the network model training device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, the network model training device also includes components such as radio frequency circuits, input units, sensors, audio circuits, WiFi modules, power supplies, and Bluetooth modules, which will not be described in detail here.
[0141] exist Figure 4 In the network model training device shown, the processor 110 can be used to call the network model training application stored in the memory 120, and specifically perform the following operations:
[0142] Sending first global model parameters of the network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameters and local data, and returning the trained client model parameters to the server, wherein the local data is an image carrying a species category identifier;
[0143] Aggregating the received plurality of client model parameters, and determining a global gradient value based on the aggregated second global model parameter and the first global model parameter;
[0144] Get preset hyperparameters and global learning rate;
[0145] Determine a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter;
[0146] Based on the first shrinkage factor and the second global model parameter, a first weight shrinkage is performed on the network model to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image.
[0147] In one embodiment, when the processor 110 determines the first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, the processor 110 specifically performs the following operations:
[0148] Calculating a norm of a product of the global gradient value and the global learning rate to obtain a first calculation result;
[0149] Calculating the product of the norm of the first global model parameter and the preset hyperparameter to obtain a second calculation result;
[0150] Calculating the sum of the first calculation result and the second calculation result to obtain a third calculation result;
[0151] The ratio of the second calculation result to the third calculation result is calculated to obtain a first shrinkage factor.
[0152] In one embodiment, when the processor 110 performs the first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain the network model after the first weight shrinkage, the processor 110 specifically performs the following operations:
[0153] Calculating the product of the first shrinkage factor and the second global model parameter to obtain a third global model parameter;
[0154] The model parameters in the network model are updated to the third global model parameters to obtain the network model after the first weight contraction.
[0155] In one embodiment, after performing a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain the network model after the first weight shrinkage, the processor 110 further specifically performs the following operations:
[0156] Acquire a first network layer model parameter corresponding to each network layer in the network model from the first global network model parameter;
[0157] Acquire second network layer model parameters corresponding to each network layer in the network model from the second global model parameters;
[0158] Determine a second shrinkage factor corresponding to each of the network layers based on the first network layer model parameters corresponding to each of the network layers, the corresponding second network layer model parameters, the preset hyperparameters, and the global learning rate;
[0159] Based on the second network layer model parameters corresponding to each of the network layers and the corresponding second shrinkage factors, a second weight shrinkage is performed on the weight-shrinked network model to obtain a second weight-shrinked network model.
[0160] In one embodiment, when the processor 110 determines the second shrinkage factor corresponding to each network layer based on the first network layer model parameters corresponding to each network layer, the corresponding second network layer model parameters, the preset hyperparameters, and the global learning rate, it is specifically used to perform the following operations:
[0161] Calculate the product of the norm of the second network layer model parameter corresponding to each of the network layers and the preset hyperparameter to obtain a fourth calculation result;
[0162] Calculate a norm of a difference between the first network layer model parameter corresponding to each of the network layers and the corresponding second network layer model parameter to obtain a fifth calculation result;
[0163] Calculate the product of the fifth calculation result and the global learning rate to obtain a sixth calculation result;
[0164] Calculating the sum of the sixth calculation result and the fourth calculation result to obtain a seventh calculation result;
[0165] The ratio of the fourth calculation result to the seventh calculation result is calculated to obtain a second shrinkage factor corresponding to each of the network layers.
[0166] In one embodiment, when the processor 110 performs the second weight shrinkage on the weight-shrunken network model based on the second network layer model parameters corresponding to each of the network layers and the corresponding second shrinkage factor to obtain the second weight-shrunken network model, the following operations are specifically performed:
[0167] Calculate the product of the second network layer model parameter corresponding to each of the network layers and the corresponding second shrinkage factor to obtain the network layer model parameter after the second weight shrinkage corresponding to each of the network layers;
[0168] synthesizing the network layer model parameters corresponding to the second weight contraction of the plurality of network layers to obtain a fourth global model parameter;
[0169] The model parameters in the network model are updated to the fourth global model parameters to obtain the network model after the second weight contraction.
[0170] In one embodiment, when the processor 110 determines the global gradient value based on the aggregated second global model parameter and the first global model parameter, it is specifically configured to perform the following operations:
[0171] The difference between the aggregated second global model parameter and the first global model parameter is calculated to obtain a global gradient value.
[0172] In an embodiment of the present application, by sending the first global model parameter of the network model to at least two clients, each of the clients is triggered to train the network model based on the received first global model parameter and local data, and the trained client model parameters are returned to the server, wherein the local data is an image carrying a species category identification; the received multiple client model parameters are aggregated, and a global gradient value is determined based on the aggregated second global model parameter and the first global model parameter; a preset hyperparameter and a global learning rate are obtained; a first shrinkage factor is determined based on the first global model parameter, the global gradient value, the preset hyperparameter and the global learning rate, and the first shrinkage factor is the shrinkage factor corresponding to the client model parameter; a first weight shrinkage is performed on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage. The first weight shrinkage of the network model is achieved by calculating the first shrinkage factor, thereby avoiding learning the weight shrinkage factor and the aggregation weight through an additional training set, thereby avoiding causing data privacy issues and avoiding the acquisition of additional training sets.
[0173] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0174] The above disclosure is only the preferred embodiment of this specification, which certainly cannot be used to limit the scope of rights of this specification. Therefore, equivalent changes made according to the claims of this specification are still within the scope covered by this specification.
Claims
1. A network model training method, characterized in that: include: Sending first global model parameters of the network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameters and local data, and returning the trained client model parameters to the server, wherein the local data is an image carrying a species category identifier; Aggregating the received plurality of client model parameters, and determining a global gradient value based on the aggregated second global model parameter and the first global model parameter; Get preset hyperparameters and global learning rate; Determine a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter; Based on the first shrinkage factor and the second global model parameter, a first weight shrinkage is performed on the network model to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image.
2. The method according to claim 1, characterized in that The determining a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate includes: Calculating a norm of a product of the global gradient value and the global learning rate to obtain a first calculation result; Calculating the product of the norm of the first global model parameter and the preset hyperparameter to obtain a second calculation result; Calculating the sum of the first calculation result and the second calculation result to obtain a third calculation result; The ratio of the second calculation result to the third calculation result is calculated to obtain a first shrinkage factor.
3. The method according to any one of claims 1 or 2, characterized in that The performing a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain the network model after the first weight shrinkage includes: Calculating the product of the first shrinkage factor and the second global model parameter to obtain a third global model parameter; The model parameters in the network model are updated to the third global model parameters to obtain the network model after the first weight contraction.
4. The method according to claim 3, characterized in that After performing a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain the network model after the first weight shrinkage, the method further includes: Acquire a first network layer model parameter corresponding to each network layer in the network model from the first global network model parameter; Acquire second network layer model parameters corresponding to each network layer in the network model from the second global model parameters; Determine a second shrinkage factor corresponding to each of the network layers based on the first network layer model parameters corresponding to each of the network layers, the corresponding second network layer model parameters, the preset hyperparameters, and the global learning rate; Based on the second network layer model parameters corresponding to each of the network layers and the corresponding second shrinkage factors, a second weight shrinkage is performed on the weight-shrinked network model to obtain a second weight-shrinked network model.
5. The method according to claim 4, characterized in that The determining, based on the first network layer model parameters corresponding to each network layer, the corresponding second network layer model parameters, the preset hyperparameters, and the global learning rate, the second shrinkage factor corresponding to each network layer comprises: Calculate the product of the norm of the second network layer model parameter corresponding to each of the network layers and the preset hyperparameter to obtain a fourth calculation result; Calculate a norm of a difference between the first network layer model parameter corresponding to each of the network layers and the corresponding second network layer model parameter to obtain a fifth calculation result; Calculate the product of the fifth calculation result and the global learning rate to obtain a sixth calculation result; Calculating the sum of the sixth calculation result and the fourth calculation result to obtain a seventh calculation result; The ratio of the fourth calculation result to the seventh calculation result is calculated to obtain a second shrinkage factor corresponding to each of the network layers.
6. The method according to any one of claims 4 or 5, characterized in that The method of performing a second weight shrinkage on the weight-shrunken network model based on the second network layer model parameters corresponding to each of the network layers and the corresponding second shrinkage factors to obtain the second weight-shrunken network model includes: Calculate the product of the second network layer model parameter corresponding to each of the network layers and the corresponding second shrinkage factor to obtain the network layer model parameter after the second weight shrinkage corresponding to each of the network layers; synthesizing the network layer model parameters corresponding to the second weight contraction of the plurality of network layers to obtain a fourth global model parameter; The model parameters in the network model are updated to the fourth global model parameters to obtain the network model after the second weight contraction.
7. The method according to claim 1, characterized in that The determining of the global gradient value based on the aggregated second global model parameter and the first global model parameter comprises: The difference between the aggregated second global model parameter and the first global model parameter is calculated to obtain a global gradient value.
8. A network model training device, characterized in that: The device comprises: A sending unit, sending a first global model parameter of the network model to at least two clients, triggering each of the clients to train the network model based on the received first global model parameter and local data, and returning the trained client model parameter to the server, wherein the local data is an image carrying a species category identifier; a first determining unit, configured to aggregate the received plurality of client model parameters, and determine a global gradient value based on the aggregated second global model parameter and the first global model parameter; The acquisition unit is used to obtain preset hyperparameters and global learning rate; A second determining unit, configured to determine a first shrinkage factor based on the first global model parameter, the global gradient value, the preset hyperparameter, and the global learning rate, where the first shrinkage factor is a shrinkage factor corresponding to the client model parameter; A weight shrinkage unit is used to perform a first weight shrinkage on the network model based on the first shrinkage factor and the second global model parameter to obtain a network model after the first weight shrinkage, and the network model is used to predict the species category of the content in the input image.
9. An electronic device, characterized in that: include: Processor and memory; The memory stores a computer program, wherein the computer program is suitable for being loaded by the processor and executing the steps of the method according to any one of claims 1 to 7.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Federal learning method based on client selection and gradient compression
CN115796271A
Comparative federated learning traffic sign identification method and system based on soft threshold noise reduction
CN116543370A
Multi-view deep neural network for lidar perception
US20220415059A1
