Image classification method and device based on fixed sparse rate compression and computer equipment
By using fixed sparsity rate compression technology in the training process of the image classification model, the problem of data islands and high communication overhead is solved, more efficient image classification model training and communication is achieved, and the accuracy and training speed of the model are improved.
Patent Information
- Application Number
- CN202410763446.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-06-13
AI Technical Summary
In the existing technology, data acquisition is difficult due to the data island problem during the training process of the image classification model. The traditional centralized training method cannot quickly and effectively obtain a high-performance model, and federated learning has a high cost in communication overhead.
An image classification method based on fixed sparsity rate compression is adopted. By randomly selecting client devices to update parameters after local training, and performing sparse rate compression and transmission between central servers, the amount of communication data is reduced and communication efficiency is optimized.
The communication efficiency between the central server and the client is improved, communication overhead is reduced, and a usable image classification model can be obtained faster, and the accuracy and convergence speed of the model are improved through the error feedback mechanism.
Smart Images

Figure CN118628818A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image classification, and in particular to an image classification method, device and computer equipment based on fixed sparse rate compression. Background Art
[0002] At present, machine learning, especially deep learning methods, has profoundly affected our daily lives. Data collection has become more convenient, and "big data-driven" artificial intelligence has developed rapidly in various industries. People hope that more fields can use artificial intelligence to facilitate social life. But the reality is that the amount of data in most fields is large, distributed on different data sets, and lacks effective communication and collaboration. In addition, the amount of data in a single data set is limited, the quality is poor, and there is a lack of "trust" between data sets, resulting in the formation of "data islands" between data sets.
[0003] For image classification technology, it is far from enough to rely solely on the data of a single user for machine learning. In order to train a high-performance image classification model, a high-quality large-scale dataset is required. However, due to the existence of "data islands", data acquisition has become extremely difficult, and the centralized training conditions of traditional image classification models are increasingly unable to meet the needs.
[0004] In 2016, a team led by McMahan at Google designed a decentralized approach called federated learning (FL) to solve the problem of data silos. With Federated Learning, data can be saved on client devices and used for local training. The key concept behind this approach is to establish a data federation so that each client can access knowledge embedded in the entire dataset. Although research on federated learning is very extensive, this privacy-preserving form of collaborative learning consumes a lot of communication overhead during training. The communication capacity between client devices and central servers is limited. As the number of nodes increases, the communication cost becomes very high, resulting in uncertainty in network connectivity and an inability to quickly and efficiently obtain high-performance image classification models. Summary of the invention
[0005] Based on this, it is necessary to provide an image classification method, device and computer equipment based on fixed sparse rate compression to address the above technical problems, so as to improve the communication efficiency between the central server and the client device, so as to obtain a usable image classification model more quickly.
[0006] An image classification method based on fixed sparse rate compression, the method comprising:
[0007] After the current round of local training is completed, a preset number of client devices are randomly selected as target client devices; wherein each client device corresponds to a local image data set and a local image classification model;
[0008] If the parameters of the local image classification model of the target client device change, the corresponding updated parameters are compressed according to a preset first fixed sparsity rate and uploaded to the central server, thereby obtaining an updated global image classification model;
[0009] The parameters of the updated global image classification model are compressed according to a preset second fixed sparsity rate and transmitted to all client devices through the central server for the next round of local training until the preset conditions are met to obtain a trained global image classification model;
[0010] Perform image classification based on the trained global image classification model.
[0011] An image classification device based on fixed sparse rate compression, the device comprising:
[0012] A target client determination module is used to randomly select a preset number of client devices as target client devices after the current round of local training is completed; wherein each client device corresponds to a local image data set and a local image classification model;
[0013] An update parameter compression module is used to compress the corresponding update parameters according to a preset first fixed sparsity rate and upload them to the central server if the parameters of the local image classification model of the target client device change, thereby obtaining an updated global image classification model;
[0014] A global parameter transmission module is used to compress the parameters of the updated global image classification model according to a preset second fixed sparsity rate and transmit them to all client devices through the central server to perform the next round of local training until the preset conditions are met to obtain a trained global image classification model;
[0015] The image classification module is used to classify images based on the trained global image classification model.
[0016] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0017] After the current round of local training is completed, a preset number of client devices are randomly selected as target client devices; wherein each client device corresponds to a local image data set and a local image classification model;
[0018] If the parameters of the local image classification model of the target client device change, the corresponding updated parameters are compressed according to a preset first fixed sparsity rate and uploaded to the central server, thereby obtaining an updated global image classification model;
[0019] The parameters of the updated global image classification model are compressed according to a preset second fixed sparsity rate and transmitted to all client devices through the central server for the next round of local training until the preset conditions are met to obtain a trained global image classification model;
[0020] Perform image classification based on the trained global image classification model.
[0021] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0022] After the current round of local training is completed, a preset number of client devices are randomly selected as target client devices; wherein each client device corresponds to a local image data set and a local image classification model;
[0023] If the parameters of the local image classification model of the target client device change, the corresponding updated parameters are compressed according to a preset first fixed sparsity rate and uploaded to the central server, thereby obtaining an updated global image classification model;
[0024] The parameters of the updated global image classification model are compressed according to a preset second fixed sparsity rate and transmitted to all client devices through the central server for the next round of local training until the preset conditions are met to obtain a trained global image classification model;
[0025] Perform image classification based on the trained global image classification model.
[0026] In the above-mentioned image classification method, device and computer equipment based on fixed sparsity compression, only the parameters of the local image classification model that have changed after the current round of training are transmitted to the central server, rather than all the model parameters, that is, the changes are limited to a small part of the parameters for transmission; and in the training process of the global image classification model, the present invention randomly selects the changed parameters of the local image classification model of some client devices in each round and uploads them to the central server, which can greatly reduce the amount of communication data. Furthermore, the present invention compresses the changed parameters of the local image classification model and the parameters of the global image classification model using a fixed sparsity rate. After removing the "unimportant" model parameters, the optimization direction can be more clearly defined, the communication efficiency can be improved, the communication overhead can be reduced, and the target image classification model can be obtained more quickly for image classification tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a flowchart of an image classification method based on fixed sparsity rate compression;
[0028] Figure 2 Schematic diagram of matrix compression process;
[0029] Figure 3 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0031] In one embodiment, Figure 1 As shown, a method for image classification based on fixed sparse rate compression is provided, comprising the following steps:
[0032] Step 102: After the current round of local training is completed, a preset number of client devices are randomly selected as target client devices.
[0033] Each client device corresponds to a local image dataset and a local image classification model.
[0034] In order to enhance the robustness of image representation, image enhancement on client devices requires multiple operations such as random cropping, random translation, random affine transformation, etc. A method combining a convolutional neural network (CNN) model and a logistic regression model can be used to extract and classify image features.
[0035] In the convolutional neural network model, convolutional layers, pooling layers, fully connected layers, classification layers and other layers are often used for image feature extraction, data compression and classification. Convolutional layer: Through convolution operations, different details and complex features that are difficult to construct manually are extracted from the input image; Pooling layer: By applying pooling operations, downsampling is performed to reduce the amount of data in the convolutional network and achieve faster calculations; Hierarchical features: In order to understand deeper feature information from the input image, convolution and pooling operations are often repeated to deepen the network hierarchy; Fully connected layer: The extracted feature information is passed to the fully connected layer. The parameters of these layers are trained using a loss function. When the loss function value converges, the training of the network model is completed and can be used for tasks such as target detection and classification.
[0036] Logistic regression is a commonly used binary classification model that maps the input feature vector to class 0 or class 1. Its core principle is to use the following function to perform a nonlinear transformation on the output of the linear regression model to obtain a probability estimate.
[0037]
[0038] Where z is the input value.
[0039] The training process of logistic regression is to solve the model parameters w and b through maximum likelihood estimation. Specifically, we use the known N samples (x i ,y i ), where x i is the input feature quantity, y i is the label to maximize the likelihood function L(w,b), which is expressed as:
[0040]
[0041] Our goal is to find the best set of model parameters w and b so that the likelihood function reaches the maximum value. This process is usually carried out by solving the gradient, that is, by taking the partial derivative of the likelihood function, calculating the gradient of w and b, and using the gradient descent method to iteratively update the model parameters w and b, thereby realizing the training of the image classification model.
[0042] Step 104, if the parameters of the local image classification model of the target client device are changed, the corresponding updated parameters are compressed according to a preset first fixed sparsity rate and uploaded to the central server, thereby obtaining an updated global image classification model.
[0043] In order to save network resources, during the image classification model training process, this method randomly selects the changed parameters of the local image classification model of some clients in each round and uploads them to the central server for gradient aggregation. Assuming that the total number of client devices is N, at the beginning of the tth round, K client devices are randomly selected to participate in the aggregation of the global image classification model in this round. The selection of K value is fixed, and only the same number of client devices are selected each time.
[0044] Theoretically, after the sparse processing, each pixel in the image only needs to transmit a small retained value. If we regard the parameters of each layer as a matrix, the original matrix is dense, where the color depth represents the size of the value. However, the method proposed in the present invention generates a sparse matrix by retaining larger values and setting smaller values to 0. The compression method used in the present invention follows Figure 2 The process shown.
[0045] Step 106, the central server compresses the parameters of the updated global image classification model according to the preset second fixed sparsity rate and transmits them to all client devices for the next round of local training until the preset conditions are met to obtain a trained global image classification model.
[0046] Fixed sparsity compression methods are mainly aimed at speeding up parallel training in data centers. In their existing form, they mainly compress upstream communications, because the sparse patterns of updates from different client devices are usually different. The elements sent by the client to the server are always sparse, so this paper proposes to extend the idea of fixed sparsity compression to downstream compression, applying the same compression mechanism at the central server to compress downstream communications.
[0047] First, the central server initializes a global image classification model, which is generally a random, pre-trained model. After that, the central server obtains the compressed model change parameters from the client device. The central server performs weighted averaging on the received model change parameters. The compressed model change parameters of each client are assigned a weight, which can be determined based on factors such as the image data set size and computing resources of the client device. Then, a global image classification model can be obtained by weighted averaging all compressed model change parameters. Specifically, for each compressed model change parameter, the change parameter of each client device is multiplied by its corresponding weight, and then all weighted change parameters are summed and finally divided by the sum of all weights. Finally, the corresponding parameters of the global image classification model can be obtained. Finally, the central server sends the generated global image classification model parameters to all client devices participating in the joint learning.
[0048] The above preset conditions can be designed as needed. For example, the training rounds can be set during the training process and the training can be stopped after the training rounds are reached.
[0049] Step 108: performing image classification according to the trained global image classification model.
[0050] In summary, in the context of multi-client collaborative training of image classification models, this paper proposes a fixed sparse compression algorithm to solve the communication efficiency problem in federated learning. The federated learning framework based on this algorithm adopts a bidirectional compression method between the client device and the central server, and only transmits the changed parameters during the client update process, which improves the communication efficiency and reduces the communication overhead.
[0051] In one embodiment, the above method also includes: when the corresponding update parameters are compressed according to a preset first fixed sparsity rate and uploaded to the central server, the errors before and after the update parameters are compressed are calculated and retained, and accumulated in the next round of local training process.
[0052] By accumulating the error feedback, we can achieve an accuracy similar to that of the algorithm without compression, improve the convergence speed, and greatly reduce the amount of communication in each round. This error feedback mechanism can further improve the accuracy of the image classification model.
[0053] In one embodiment, when the corresponding update parameters are compressed according to the preset first fixed sparsity rate and uploaded to the central server, the errors before and after the update parameters are compressed are calculated and retained, and accumulated in the next round of local training process, specifically:
[0054]
[0055] in, represents the model parameters after the error accumulation before the start of the tth round of local training, It represents the parameters of the local image classification model updated by the i-th target client device after the t-th round of local training. represents the parameters of the local image classification model updated by the i-th target client device after the t-1th round of local training. is the updated parameter of the local image classification model obtained after the tth round of local training, error t Represents the error before and after compression of the updated parameters corresponding to the t-th round of local training.
[0056] Before the start of the tth round of local training, the initial value of the image classification model parameters of the tth round of local training is obtained based on the sum of the errors before and after compression of the local image classification model and its corresponding updated parameters obtained after the t-1th round of local training. Then according to Perform the tth round of local training and get That is to say, each round of local training only needs to add the compression error of the previous round. If the client device corresponding to the previous round is not selected, it can be understood that the compression error of the previous round is 0.
[0057] In one embodiment, if the parameters of the local image classification model of the target client device change, the corresponding updated parameters are compressed according to the preset second fixed sparsity rate and uploaded to the central server to obtain an updated global image classification model, including:
[0058]
[0059] Among them, w t represents the global image classification model parameters before update in the tth round, w t+1 represents the updated global image classification model parameters in the tth round, represents the model parameters of the local image classification model that have changed after the local training of the tth round of the i-th target client device is completed. K represents the number of target client devices. D i represents the total number of samples in the local image dataset corresponding to the i-th target client device, top p%It represents the selection of the largest element in the top p%, and ← is the assignment symbol.
[0060] In one embodiment, the update parameters are calculated as follows:
[0061]
[0062] in, It represents the model parameters corresponding to the i-th target client device after the t-th round of local training. represents the model parameters corresponding to the i-th target client device before the start of the t-th round of local training, η represents the learning rate, Represents the gradient generated in the tth round of local training.
[0063] In one embodiment, the above method also includes: when the parameters of the updated global image classification model are compressed according to a preset second fixed sparsity rate and transmitted to all client devices through the central server, the errors before and after compression of the parameters of the updated global image classification model are calculated and retained, and accumulated in the next round of global training process.
[0064] In one embodiment, the first fixed thinning rate and the second fixed thinning rate are equal.
[0065] In summary, the contribution of the present invention is to propose a federated learning algorithm with a fixed sparsity rate, based on which the number of overall parameters is effectively reduced by selectively discarding parameters. This reduction leads to improved communication efficiency and reduced communication overhead. In addition, the use of fixed sparsity compression helps to reduce the risk of overfitting. In addition, the present invention includes an error feedback mechanism that greatly improves the accuracy of image classification. In general, these innovations have brought significant optimization and progress to the field of federated learning.
[0066] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0067] In one embodiment, an image classification device based on fixed sparse rate compression is provided, comprising: a target client determination module, an update parameter compression module, a global parameter transmission module and an image classification module, wherein:
[0068] A target client determination module is used to randomly select a preset number of client devices as target client devices after the current round of local training is completed; wherein each client device corresponds to a local image data set and a local image classification model;
[0069] An update parameter compression module is used to compress the corresponding update parameters according to a preset first fixed sparsity rate and upload them to the central server if the parameters of the local image classification model of the target client device change, thereby obtaining an updated global image classification model;
[0070] A global parameter transmission module is used to compress the parameters of the updated global image classification model according to a preset second fixed sparsity rate and transmit them to all client devices through the central server to perform the next round of local training until the preset conditions are met to obtain a trained global image classification model;
[0071] The image classification module is used to classify images based on the trained global image classification model.
[0072] For the specific definition of the image classification device based on fixed sparse rate compression, please refer to the definition of the image classification method based on fixed sparse rate compression above, which will not be repeated here. Each module in the above-mentioned image classification device based on fixed sparse rate compression can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0073] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 3As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an image classification method based on fixed sparse rate compression is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0074] Those skilled in the art will understand that Figure 1 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0075] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0076] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0077] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. An image classification method based on fixed sparse rate compression, It is characterized in that The method comprises: After the current round of local training is completed, a preset number of client devices are randomly selected as target client devices; wherein each client device corresponds to a local image data set and a local image classification model; If the parameters of the local image classification model of the target client device change, the corresponding updated parameters are compressed according to a preset first fixed sparsity rate and uploaded to the central server, thereby obtaining an updated global image classification model; The parameters of the updated global image classification model are compressed according to a preset second fixed sparsity rate and transmitted to all client devices through the central server for the next round of local training until the preset conditions are met to obtain a trained global image classification model; Perform image classification based on the trained global image classification model.
2. The method according to claim 1, It is characterized in that The method also includes: when the corresponding update parameters are compressed according to a preset first fixed sparsity rate and uploaded to the central server, the errors before and after the update parameters are compressed are calculated and retained, and accumulated in the next round of local training process.
3. The method according to claim 2, It is characterized in that When the corresponding update parameters are compressed according to the preset first fixed sparsity rate and uploaded to the central server, the error before and after the update parameter compression is calculated and retained, and accumulated in the next round of local training process, specifically: in, represents the model parameters after the error accumulation before the start of the tth round of local training, It represents the parameters of the local image classification model updated by the i-th target client device after the t-th round of local training. represents the parameters of the local image classification model updated by the i-th target client device after the t-1th round of local training. is the updated parameter of the local image classification model obtained after the tth round of local training, error t Represents the error before and after compression of the updated parameters corresponding to the t-th round of local training.
4. The method according to claim 1, It is characterized in that If the parameters of the local image classification model of the target client device change, the corresponding updated parameters are compressed according to the preset second fixed sparsity rate and uploaded to the central server to obtain an updated global image classification model, including: Among them, w t represents the global image classification model parameters before update in the tth round, w t+1 represents the updated global image classification model parameters in the tth round, represents the model parameters of the local image classification model that have changed after the local training of the tth round of the i-th target client device is completed. K represents the number of target client devices. D i represents the total number of samples in the local image dataset corresponding to the i-th target client device, top p% It represents the selection of the largest element in the top p%, and ← is the assignment symbol.
5. The method according to claim 4, It is characterized in that The update parameters are calculated as follows: in, It represents the model parameters corresponding to the i-th target client device after the t-th round of local training. represents the model parameters corresponding to the i-th target client device before the start of the t-th round of local training, η represents the learning rate, Represents the gradient generated in the tth round of local training.
6. The method according to claim 1, It is characterized in that The method also includes: when the parameters of the updated global image classification model are compressed according to a preset second fixed sparsity rate and then transmitted to all client devices through the central server, the errors before and after the compression of the parameters of the updated global image classification model are calculated and retained, and accumulated in the next round of global training process.
7. The method according to claim 1, It is characterized in that The first fixed thinning rate and the second fixed thinning rate are equal.
8. An image classification device based on fixed sparse rate compression, It is characterized in that The device comprises: A target client determination module is used to randomly select a preset number of client devices as target client devices after the current round of local training is completed; wherein each client device corresponds to a local image data set and a local image classification model; An update parameter compression module is used to compress the corresponding update parameters according to a preset first fixed sparsity rate and upload them to the central server if the parameters of the local image classification model of the target client device change, thereby obtaining an updated global image classification model; A global parameter transmission module is used to compress the parameters of the updated global image classification model according to a preset second fixed sparsity rate and transmit them to all client devices through the central server to perform the next round of local training until the preset conditions are met to obtain a trained global image classification model; The image classification module is used to classify images based on the trained global image classification model.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, It is 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 model compression method based on model rarefaction and weight quantization
CN113222179A
Federal learning backdoor attack defense method and device
CN113779563A
Sparse communication method and system based on federal deep learning
CN117061617A
Federated modelling method based on non-uniformly distributed data, and related device
WO2021190638A1
