Data processing method, device, equipment and computer readable storage medium
Through a phased and layer-by-layer quantitative training scheme, the pre-trained model is quantified, which solves the problem of deploying large-scale neural networks in devices with limited storage space and achieves a balance between model size reduction and recognition accuracy.
Patent Information
- Application Number
- CN202110583709.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-27
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-05-27
AI Technical Summary
Existing technology makes it difficult to effectively deploy large-scale neural network models in devices with limited storage space or limited power consumption, and quantitative processing methods cannot effectively reduce the loss of recognition accuracy.
By obtaining the pre-trained model and inserting pseudo-quantization nodes layer by layer in the iterative training process, the quantization process is simulated, the model parameters are adjusted, and the errors caused by quantization are gradually adapted to realize the quantization processing of the model.
It successfully reduces the size of the neural network model, improves the inference speed, while maintaining high recognition accuracy, and is suitable for devices with limited storage space and power consumption.
Smart Images

Figure CN113762503B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and specifically to a data processing method, device, equipment and computer-readable storage medium. Background Art
[0002] With the continuous development of computer technology, more and more neural network models are being applied to various businesses; for example, face recognition models are applied to face detection, and noise optimization models are applied to reduce noise. Studies have found that the representation ability of a neural network model has a strong positive correlation with its scale (number of parameters, amount of calculation); in short, the accuracy of the prediction results of a larger neural network model is better than that of a smaller neural network model. However, the larger the scale of the neural network, the higher the configuration parameters required for the device when it is deployed, such as requiring more storage space, requiring higher operating speed, etc. Therefore, in order to configure a large-scale neural network in a device with limited storage space or limited power consumption, it is necessary to quantize the large-scale neural network. At present, in the field of artificial intelligence, how to quantize the neural network model has become one of the hot issues in research. Summary of the invention
[0003] The embodiments of the present application provide a data processing method, apparatus, device and computer-readable storage medium to achieve model quantization.
[0004] On the one hand, an embodiment of the present application provides a data processing method, including:
[0005] Obtain a pre-trained model, wherein the pre-trained model includes N network layers, and parameters of the N network layers are initialized based on parameters of the N network layers in the pre-trained model; the pre-trained model is obtained by iterative training based on a first training data set, and the first training data set includes full-precision first training data and training labels of the first training data;
[0006] Obtaining a second training data set, and using the second training data set to iteratively train the pre-trained model; the second training data set includes quantized second training data and training labels corresponding to the second training data;
[0007] In the iterative training process, if the current number of iterations meets the parameter quantization condition, a target network layer to be quantized is determined from the N network layers, the target network layer to be quantized is quantized, and the pre-trained model is updated according to the quantized target network layer to be quantized;
[0008] The updated pre-trained model is trained using the second training data set to obtain a quantized model.
[0009] On the one hand, an embodiment of the present application provides a data processing device, including:
[0010] An acquisition unit is used to acquire a pre-trained model and a second training data set; the pre-trained model includes N network layers, and the parameters of the N network layers are initialized based on the parameters of the N network layers in the pre-trained model; the pre-trained model is obtained by iterative training based on the first training data set, and the first training data set includes full-precision first training data and training labels of the first training data;
[0011] A processing unit, used to iteratively train the pre-trained model using the second training data set; the second training data set includes quantized second training data and training labels corresponding to the second training data; and used to determine a target network layer to be quantized from the N network layers if the current number of iterations meets the parameter quantization condition during the iterative training process, quantize the target network layer to be quantized, and update the pre-trained model according to the quantized target network layer to be quantized; and used to train the updated pre-trained model using the second training data set to obtain a quantized model.
[0012] Correspondingly, an embodiment of the present invention further provides a data processing device, comprising: a storage device and a processor; the storage device stores a computer program; the processor executes the computer program to implement the above-mentioned data processing method.
[0013] Correspondingly, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned data processing method is implemented.
[0014] Accordingly, the present application provides a computer program product or a computer program, which includes computer instructions, which are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the above-mentioned data processing method.
[0015] In an embodiment of the present application, a pre-trained model and a second training data set are obtained, and the second training data set is used to iteratively train the pre-trained model; during the iterative training process, if the current number of iterations meets the parameter quantization condition, a target network layer to be quantized is determined from the N network layers, the target network layer to be quantized is quantized, and the pre-trained model is updated according to the quantized target network layer to be quantized; and the updated pre-trained model is trained using the second training data set to obtain a quantized model. It can be seen that in the process of iterative training of the pre-trained model, by using the quantized target network layer to be quantized to update the pre-trained model, the scale of the neural network model can be reduced well, thereby achieving model quantization. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] 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 the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1a A schematic diagram of the structure of a model quantization system provided in an embodiment of the present application;
[0018] Figure 1b A schematic diagram of a structure diagram of another model quantization system provided in an embodiment of the present application;
[0019] Figure 2 A flowchart of a data processing method provided in an embodiment of the present application;
[0020] Figure 3 A flowchart of another data processing method provided in an embodiment of the present application;
[0021] Figure 4a A flowchart for updating a pre-trained model provided in an embodiment of the present application;
[0022] Figure 4b An application scenario diagram of a quantization model provided in an embodiment of the present application;
[0023] Figure 4c Another application scenario diagram of a quantization model provided in an embodiment of the present application;
[0024] Figure 5 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application;
[0025] Figure 6 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0027] The embodiments of the present application relate to artificial intelligence (AI) and machine learning (ML). Among them, AI is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science, which attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that the machines have the functions of perception, reasoning and decision-making. The embodiments of the present application mainly involve inserting pseudo-quantization operators in multiple network layers to be quantized in the model to be trained in stages during iterative training to obtain a model to be converted; converting the model to be converted, and training the converted model, and finally obtaining a quantization model corresponding to the model to be trained, so as to achieve the purpose of reducing the scale of the neural network model.
[0028] AI technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, processing technologies for large applications, operating / interactive systems, and mechatronics. Artificial intelligence software technologies mainly include computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning. Among them, computer vision technology is a science that studies how to make machines "see". To put it more concretely, it refers to machine vision such as using cameras and computers to replace human eyes to identify, detect, and measure targets, and further perform graphics processing to make computer processing into images that are more suitable for human eye observation or transmission to instrument detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multidimensional data; it usually includes image processing, video processing, video semantic understanding, video content / behavior recognition, and other technologies.
[0029] Machine learning is a multi-disciplinary cross-discipline involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specifically studies how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of AI and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning / deep learning usually includes artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning and other technologies. The representation ability of a neural network model has a strong positive correlation with its scale (such as the number of parameters and the amount of calculation). The deeper and wider the model, the better the performance of the smaller model. However, blindly expanding the model size can improve the accuracy of face recognition, but it has caused great obstacles to the actual application and deployment of the model, especially on mobile devices with limited computing power and power consumption. Therefore, after training a full-precision pre-trained model, each device that deploys the model will compress the pre-trained model according to its own situation before deploying it. The compression of the model can be understood as quantizing the model. The embodiments of the present invention propose the following model quantization methods in the process of model quantization research:
[0030] 1) Post-quantization scheme: The post-quantization scheme first uses the traditional deep neural network model training method to train a full-precision model for a specific model structure and loss function. The model parameters are then quantized to an agreed number of bits (such as int8 quantization, i.e., integerization) using a specific quantization method; then a small batch of training data (such as 2,000 images, or a data volume much smaller than the size of the training set) is used to obtain the range of outputs of each layer in the model, i.e., the value range of the activation function, and then the outputs of each network layer in the model are quantized. The final model is the quantized model. At this time, for a certain network layer, the model parameters involved in the calculation and the activation output of the previous layer (the input of this layer) are all quantized fixed-point numbers.
[0031] 2) Quantization-aware training scheme (QAT): In the quantization step of the post-quantization scheme, the model parameters are only quantized, and the accuracy loss caused by quantization cannot be taken into account in the training process, and the model parameters are adjusted based on the quantization itself (that is, the impact of quantization on the accuracy of the model is not considered). For this reason, in the quantization-aware training scheme, pseudo-quantization nodes are artificially inserted after the model parameters and the activation function to simulate the quantization process. This scheme can simulate the actual calculation after quantization during the training process, and the quantized model can be obtained after training, so it can greatly reduce the recognition accuracy loss caused by quantization.
[0032] 3) Model quantization training scheme with phased and layer-by-layer quantization: During the quantization-aware training process, pseudo-quantization nodes are not inserted all at once, but are inserted in stages and layer-by-layer from shallow to deep according to predetermined rules. In other words, each time a network layer in the model is quantized, the model will be trained (parameter adjustment). Finally, when all the network layers that need to be quantized in the model are quantized and the model converges, an updated model is obtained.
[0033] In practice, it is found that among the above three solutions, the post-quantization solution that directly performs post-quantization operations on the full-precision model cannot guarantee that the quantized model can obtain good recognition results. This is because the errors caused by quantization are not taken into account during the training process of the full-precision model. However, the model often has extremely high accuracy requirements, and the errors caused by model quantization may lead to incorrect recognition results, and the losses caused by it are immeasurable.
[0034] The quantization-aware training solution can adjust the model parameters after quantization to a certain extent and minimize the error caused by the quantization operation. However, in actual operation, the one-time insertion of the pseudo-quantization operator will destroy the stability of the training and make the model unable to converge to the optimal point. This is because the pseudo-quantization operator corresponding to the quantization operation will reduce the representation ability of the model. The drastic jump in the representation ability will cause the model to jump out of the original convergence optimal point and fall into other suboptimal points.
[0035] The model quantization training scheme that quantizes the model layer by layer in stages divides the "huge change" in the model's representation ability into several "small jumps" through a staged insertion method compared to a one-time insertion. After inserting the pseudo-quantization node, the subsequent layers can still retain the full-precision calculation process, and can gradually adapt to the errors caused by quantization and gradually adjust their own parameters. This "gentle" model quantization-aware training method can greatly reduce the interference of quantization errors on model training, so that the quantized model trained by this method can still maintain a high recognition accuracy after obtaining the benefits of reduced model size and improved inference speed, meeting the actual requirements of model application.
[0036] From the above analysis, it can be seen that the model quantization training scheme of staged layer-by-layer quantization is more effective in practical applications. Therefore, this application mainly introduces the model quantization training scheme of staged layer-by-layer quantization in detail. Figure 1a A schematic diagram of a model quantization system provided by an embodiment of the present invention, Figure 1aThe model quantization system shown includes a data processing device 101 and a model storage device 102. Both the data processing device 101 and the model storage device 102 can be terminals, such as smart phones (such as Android phones, iOS phones, etc.), tablet computers, portable personal computers, mobile Internet devices (Mobile Internet Devices, MID) and other devices; the data processing device 101 and the model storage device 102 can also be servers, such as independent physical servers, or server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0037] exist Figure 1a In the figure, the data processing device 101 is taken as a terminal and the model storage device 102 is taken as a server as an example. The model storage device 102 is mainly used to store the pre-trained model after training. The pre-trained model can be trained by the model storage device 102 based on the first training data set, or it can be uploaded to the model storage device 102 after other devices complete the training based on the first training data set. The first training data set includes the first training data with full precision and the training label of the first training data. The model storage device 102 can be a node in the blockchain network, so that the pre-trained model can be stored in the blockchain. The blockchain is a new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm, etc. It is essentially a decentralized database, a string of data blocks generated by cryptographic methods. The distributed ledger connected by the blockchain allows multiple parties to effectively record transactions and can permanently check the transaction (cannot be tampered with). The data in the blockchain is tamper-proof, and storing the pre-trained model in the blockchain can ensure the security of the pre-trained model.
[0038] When a pre-trained model needs to be deployed in the data processing device 101, the data processing device 101 first obtains the configuration parameters of the data processing device, such as storage space, running memory, power consumption, etc.; then determines whether the configuration parameters of the data processing device match the deployment conditions of the pre-trained model. If so, the pre-trained model is directly obtained from the model storage device 102 and deployed in the data processing device; if the configuration parameters of the data processing device do not match the deployment conditions of the pre-trained model, the data processing device 101 can use the above-mentioned staged and layer-by-layer quantization model quantization training scheme to quantize the pre-trained model obtained in the model storage device 102 to obtain a quantized model, the deployment conditions of the quantized model match the configuration parameters of the data processing device, and then the quantized model is deployed in the data processing device 101.
[0039] Subsequently, the data processing device 101 may collect data to be processed, and call the quantization model to perform recognition processing on the data to be processed, and output the recognition result. For example, if the quantization model is a face recognition model, the data processing device 101 may collect face data to be recognized (i.e., data to be processed), call the quantization model to perform recognition processing on the face data to be recognized, and output the recognition result.
[0040] Based on the above-mentioned model quantization system, the present application embodiment also provides a structural diagram of another model quantization system, such as Figure 1b As shown. Figure 1b In the present invention, the model quantization system may include a training data module, a full-precision model training module, a staged quantization perception training module, a quantization model conversion module, a quantization model execution module, and a model application module. Among them, the training data module is mainly responsible for preprocessing the data required by the full-precision model module and the staged quantization perception training module. Specifically, in the full-precision model training stage, the training data module provides it with the original training data (preprocessed, normalized full-precision form); and in the staged quantization perception training stage, the training data module provides it with quantized training data (preprocessed, normalized quantization form). It should be noted that the data preprocessing form required by the quantization training module needs to refer to some limitations of the subsequent quantization model execution module. For example, the commonly used TNN quantization model execution framework only supports symmetric quantization forms with input forms ranging from -1 to +1, so this module needs to process the training data into the corresponding symmetric quantization forms ranging from -1 to +1.
[0041] The full-precision model training module is a neural network training module, which is used to provide a high-precision pre-trained model for the subsequent staged quantization perception training module. Specifically, the full-precision model training steps are divided into: 0) Initialize model parameters; 1) Obtain training data of a specific size and its corresponding labels; 2) Use full-precision model reasoning to obtain prediction results, and use labels to calculate model losses according to a pre-designed loss function; 3) Calculate the gradients of each parameter based on the loss; 4) Update model parameters according to a pre-specified method; 5) Repeat 1) to 4) until the model converges; 6) Obtain a full-precision pre-trained model.
[0042] The staged quantization-aware training module is used to quantize the network layers to be quantized in the pre-trained model (i.e., from shallow to deep, according to predetermined rules, pseudo-quantization nodes are inserted in stages and layer by layer) to obtain an updated pre-trained model.
[0043] The quantization model conversion module is used to convert the updated pre-trained model to obtain a quantization model. Since the updated pre-trained model obtained in the staged quantization perception training module contains pseudo-quantization operators and the model parameters are still full precision, further processing is required. The quantization model execution module is used to process the input data to be predicted to obtain the prediction result. Compared with the full-precision floating-point number calculation, the quantized fixed-point number calculation requires the corresponding processor underlying instruction support. The quantization model execution module uses the quantization model obtained in the quantization model conversion module to infer the input data and obtain the prediction result. Taking int8 quantization as an example, open source projects such as TNN and NCNN can provide special underlying support and optimization for int8 numerical calculations to truly give play to the advantages of model quantization. The model application module is used to deploy the quantization model to the data processing equipment.
[0044] To summarize the above, Figure 1bWhen the model quantization system shown in the figure performs model quantization, the specific process can be summarized as follows: (1) The staged quantization perception training model obtains a pre-trained model from the full-precision model training module. The pre-trained model includes N network layers. The pre-trained model is obtained by iteratively training the initial model based on the first training data set. The first training data set can be provided by the training data module. The first training data set includes full-precision first training data and training labels of the first training data. Generally speaking, full-precision data refers to raw data that has not been processed (such as quantization processing, compression processing, blur processing, cropping processing, etc.). (2) The staged quantization perception module obtains a second training data set from the training data module, and uses the second training data set to iteratively train the pre-trained model. The second training data set includes quantized second training data and training labels corresponding to the second training data set. For signals, quantization can be understood as converting continuous signals into discrete signals; for images, quantization can be understood as reducing the clarity of images; for data, quantization can be understood as converting high-precision data into low-precision data. (3) During the iterative training process, if it is detected that the current number of iterations satisfies the parameter quantization condition (such as the current number of iterations can be divided by P, where P is a positive integer), a target network layer to be quantized is determined from the N network layers; in one embodiment, the target network layer to be quantized can be a network layer that has not been quantized in a set of network layers consisting of convolutional layers and fully connected layers in the pre-trained model; further, the target network layer to be quantized is quantized (such as performing operations on the parameters in the target network layer to be quantized by a pseudo-quantization operator), and the quantized target network model to be quantized is used to update the pre-trained model; (4) The updated pre-trained model is trained using a second training data set (i.e., the second training data is input into the updated pre-trained model, and the parameters of the N network layers of the updated pre-trained model are updated according to the output of the updated pre-trained model and the training labels of the second training data), to obtain a quantized model. It can be understood that by repeatedly executing steps (3) and (4) (i.e., in the iterative training process), the network layers that need to be quantized in the pre-trained model can be quantized step by step (in stages) until all the network layers that need to be quantized in the pre-trained model are quantized and the pre-trained model converges to obtain the module to be converted. Furthermore, the module to be converted is quantized by the quantization model conversion module (the N network parameters included in the model to be converted are quantized based on the quantization coefficient) to obtain the final quantization model. The quantization model execution module can call the quantization model converted by the quantization model conversion module to process the data to be processed and obtain the processing result; for example, assuming that the quantization model converted by the quantization model conversion module is a face recognition model, the quantization model execution module calls the face recognition model to identify the face data to be identified (i.e., the data to be processed) and obtains the face recognition result (i.e., the processing result).In addition, the quantization model converted by the quantization model conversion module can also be deployed to the data processing device through the model application module; for example, the face recognition model (quantization model) is deployed to the camera (data processing device) through the model application module.
[0045] See also Figure 2 , Figure 2 A flowchart of a data processing method provided in an embodiment of the present application. The method can be executed by a data processing device, and the method in the embodiment of the present application includes the following steps:
[0046] S201. Obtain a pre-trained model.
[0047] A pre-trained model may refer to a model that is trained on an initial model using full-precision training data. The initial model may be a face recognition model, a noise recognition model, a text recognition model, a disease prediction model, etc. In a specific implementation, the pre-trained model is obtained by iteratively training the initial model based on the first training data set, and the first training data set includes full-precision first training data (full-precision data refers to original data that has not been processed (such as quantization processing, compression processing, blur processing, cropping processing, etc.)) and training labels of the first training data (used to optimize the parameters in the pre-trained network model); specifically, the pre-trained model can be a full-precision model trained to convergence, and the training process of the pre-trained model includes: 1) obtaining training data of a specific size (the first training data in the first training data set) and its corresponding labels; 2) using full-precision model reasoning to obtain prediction results, and using the labels to calculate the model loss according to a pre-designed loss function; 3) calculating the gradients of each parameter according to the loss; 4) updating the model parameters according to a predetermined method (so that the prediction results of the optimized model are closer to the training labels of the first training data than before optimization); 5) repeating 1) to 4) until the model converges; 6) obtaining a full-precision pre-trained model.
[0048] S202: Obtain a second training data set, and use the second training data set to iteratively train the pre-trained model.
[0049] The second training data set includes quantized second training data (for signals, quantization can be understood as converting a continuous signal into a discrete signal; for images, quantization can be understood as reducing the clarity of an image; for data, quantization can be understood as converting high-precision data into low-precision data (such as converting floating-point data into integer data)) and training labels corresponding to the second training data set (used to optimize the parameters in the pre-trained model).
[0050] Iterative training of the pre-trained model using the second training data set means: inputting the second training data into the pre-trained model, and optimizing the parameters of the N network layers of the pre-trained model according to the results output by the pre-trained model and the training labels of the second training data (so that the prediction results of the optimized model are closer to the training labels of the second training data than before the optimization), and obtaining a quantized model. Specifically, each iterative training includes a forward operation and a reverse operation (backward operation); wherein the forward operation means that after the training data is input into the pre-trained model, the input data is weighted by the neurons in the N network layers of the pre-trained model, and the prediction results of the training data are output according to the results of the weighted processing; the reverse operation means that the model loss is calculated according to the prediction results and the training labels corresponding to the training data (through the loss function corresponding to the pre-trained model), and the gradients of each parameter are calculated according to the loss, and then the parameters of the pre-trained model are updated, so that the prediction results of the updated pre-trained model are closer to the training labels corresponding to the training data than before the update.
[0051] Optionally, the second training data set can be obtained by quantizing the first training data set. When performing the quantization process, the limitations of the quantization model during execution also need to be considered; for example, the commonly used TNN quantization model execution framework only supports input in the form of symmetric quantization in the range of -1 to +1, so this module needs to process the training data into the corresponding symmetric quantization in the range of -1 to +1.
[0052] S203. During the iterative training process, if the current number of iterations meets the parameter quantization condition, a target network layer to be quantized is determined from the N network layers, and the target network layer to be quantized is quantized; and the pre-trained model is updated according to the quantized target network layer to be quantized.
[0053] The parameter quantization condition can be specified by the user; for example, the user specifies that the target network layer to be quantized is quantized when the number of iterations is the 3rd, 5th, 11th, 19th, 23rd...; the parameter quantization condition can also be set by the developer (the number of iterations meets a certain rule); for example, the developer sets that the target network layer to be quantized is quantized every N iterations; for another example, if the current number of iterations meets a preset operation rule (such as a geometric sequence, an arithmetic sequence, etc.), the target network layer to be quantized is quantized; the parameter quantization condition can also be that if the data processing device detects that the pre-trained model has converged, the target network layer to be quantized is quantized.
[0054] In one embodiment, the target network layer to be quantized may be specified by the user; for example, the user specifies to quantize the 3rd network layer, the 10th network layer and the 15th network layer of the pre-trained model one by one. The target network layer to be quantized may also be determined by a smart device from the pre-trained model according to judgment conditions. For example, the data processing device judges one by one in order from shallow to deep. Assume that the data processing device currently judges the jth network layer (that is, the first j-1 layers do not meet the judgment conditions of the target network layer to be quantized), j is a positive integer, and j is less than or equal to N; if the jth network layer belongs to the target layer (such as a convolutional layer, a fully connected layer), and the jth network layer has not been quantized, then the jth network layer is determined as the target network layer to be quantized.
[0055] Furthermore, the process of quantizing the target network layer to be quantized by the data processing device includes: obtaining a quantization coefficient, and calculating a pseudo-quantization operator based on the quantization coefficient and a first parameter, wherein the first parameter refers to a parameter in the target network layer to be quantized, and in one embodiment, the first parameter refers to a parameter with the largest absolute value in the target network layer to be quantized; performing a preset operation on the first parameter and the pseudo-quantization operator, and using the operation result (i.e., the parameter obtained after the operation) to replace the original parameter in the target network layer to be quantized. Then, the pre-trained model is updated according to the quantized target network layer to be quantized. For example, after the target quantized network layer is updated, the parameters in one or more network layers in the pre-trained model other than the target quantized network layer also need to be updated accordingly, so that the prediction result of the updated pre-trained model is closer to the actual result (i.e., the label of the second training data).
[0056] S204: Use the second training data set to train the updated pre-trained model to obtain a quantized model.
[0057] In one embodiment, the data processing device inputs the second training data into an updated pre-trained model, and updates the parameters of the N network layers of the updated pre-trained model based on the results output by the updated pre-trained model and the training labels of the second training data, so that the prediction results of the updated pre-trained model are closer to the actual results (i.e., the labels of the second training data), thereby obtaining a quantized model.
[0058] It is understandable that, during the iterative training process, by repeatedly executing steps S203 and S204, the data processing device can gradually (in stages) quantize the network layers that need to be quantized in the network model to be quantized (i.e., each time a network layer that needs to be quantized in the network model to be quantized is selected for quantization), until all network layers that need to be quantized in the network model to be quantized are quantized, and the pre-trained model converges to obtain the final quantized model. Practice has found that by processing the model using the data processing method provided in this application, the scale of the neural network model can be reduced well, and the representation ability of the neural network model can be better retained (i.e., the loss of recognition accuracy caused by directly quantizing all network layers in the upgraded network model is reduced).
[0059] In an embodiment of the present application, a pre-trained model and a second training data set are obtained, and the second training data set is used to iteratively train the pre-trained model; during the iterative training process, if the current number of iterations meets the parameter quantization condition, a target network layer to be quantized is determined from the N network layers, the target network layer to be quantized is quantized, and the pre-trained model is updated according to the quantized target network layer to be quantized; and the updated pre-trained model is trained using the second training data set to obtain a quantized model. It can be seen that in the process of iteratively training the pre-trained model, by using the quantized target network layer to be quantized to update the pre-trained model, the scale of the neural network model can be reduced well.
[0060] See also Figure 3 , Figure 3 A flowchart of another data processing method provided in an embodiment of the present application. The method can be executed by a data processing device, and the method in the embodiment of the present application includes the following steps:
[0061] S301. Obtain a pre-trained model.
[0062] In one embodiment, in response to deploying a pre-trained model in a data processing device, the data processing device obtains the pre-trained model. After obtaining the pre-trained model, the data processing device determines whether it meets the deployment conditions for deploying the pre-trained model based on its own configuration parameters (such as storage space, computing power, power consumption, etc.); if the data processing device determines that it does not meet the deployment conditions for the pre-trained model, it continues to execute steps S302-S308, or executes steps S202-S204, and then obtains a quantization model corresponding to the pre-trained model, and in response to the deployment conditions of the quantization model matching the configuration parameters of the data processing device, deploys the quantization model; accordingly, if the data processing device determines that it meets the deployment conditions for the pre-trained model, the data processing device can directly deploy the pre-trained model.
[0063] S302: Obtain a second training data set, and use the second training data set to iteratively train the pre-trained model.
[0064] The specific implementation of step S301 and step S302 can be referred to Figure 2 The implementation of step S201 and step S202 will not be repeated here.
[0065] S303: During the iterative training process, if the current number of iterations meets the parameter quantization condition, a target network layer to be quantized is determined from the N network layers.
[0066] In one embodiment, the N network layers include M convolutional layers and W fully connected layers connected in order from shallow to deep in the network, M and W are positive integers, and both M and W are less than N. The data processing device selects a network layer that has not been quantized from the M convolutional layers and the W fully connected layers in order from shallow to deep, and uses the selected network layer as the target network layer to be quantized. For example, assuming that the 3rd to 7th layers in the pre-trained model are convolutional layers, the 21st to 23rd layers are fully connected layers, and the 3rd and 4th layers have been quantized, the data processing device determines the 5th layer as the target network layer to be quantized in order from shallow to deep.
[0067] S304: Obtain a quantization coefficient, and calculate a pseudo quantization operator based on the quantization coefficient and the first parameter.
[0068] In one embodiment, the number of first parameters (i.e., parameters in the target network layer to be quantized) is at least one. The process of the data processing device obtaining the quantization coefficient includes: determining the number of quantization bits, which can be set by the user according to the quantization requirements, or can be pre-set by the developer; and determining the target first parameter that meets the absolute value requirements from at least one first parameter. In one embodiment, the target first parameter is the first parameter with the largest absolute value among the at least one first parameter. Further, the data processing device substitutes the target first parameter and the number of quantization bits into the quantization coefficient operation rule for operation to obtain the quantization coefficient. After obtaining the quantization coefficient, the data processing device calculates the pseudo-quantization operator based on the quantization coefficient and the first parameter. In one embodiment, the data processing device divides the first parameter and the quantization coefficient, and uses a rounding function to round the division result, and then multiplies the rounding result with the quantization coefficient to obtain a pseudo-quantization operator. The specific calculation method is shown in Formula 1:
[0069]
[0070] Wherein, Q represents a pseudo quantization operator, R is the first parameter, D represents a quantization coefficient, and the round() function represents rounding, that is, the part greater than or equal to 0.5 is rounded up, otherwise it is discarded. In one embodiment, MAX=max(abs(R)); abs() is an absolute value function, abs(R) means finding the absolute value of R, max(abs(R)) is the target first parameter (the first parameter with the largest absolute value), N is the number of quantization bits, and for shaping, N=8 (that is, the number of quantization bits is 8).
[0071] S305: Perform a preset operation on the first parameter and the pseudo quantization operator, and use the operation result to replace the target network layer to be quantized.
[0072] In one embodiment, after calculating the pseudo-quantization operator, the data processing device performs a preset operation (such as multiplication or division, etc.) on the pseudo-quantization operator and the first parameter (i.e., the parameter in the target network layer to be quantized) to obtain the quantized parameters corresponding to each parameter in the target network layer to be quantized, and uses the quantized parameters to replace the parameters in the target network layer to be quantized to obtain the quantized target network layer to be quantized.
[0073] S306: Use the second training data set to train the updated pre-trained model, and obtain the model to be converted after the training is completed.
[0074] In one embodiment, the data processing device updates the pre-trained model according to the quantized target network layer to be quantized, that is, after updating the target network layer to be quantized, the updated pre-trained model is trained (parameter adjustment) using the second training data set to obtain the updated pre-trained model. In other words, when the data processing device updates the parameters of one network layer in the pre-trained model according to the pseudo-quantization operator, it may affect other network layers. Therefore, each time the parameters of one network layer are updated, the updated pre-trained model needs to be trained using the second training data set to adjust the parameters in the pre-trained model so that the prediction results of the updated pre-trained model are closer to the actual results (i.e., the labels of the second training data).
[0075] Furthermore, during the process of training the updated pre-trained model using the second training data set by the data processing device, if the current number of iterations meets the parameter quantization conditions, and there is a network layer to be quantized among the N network layers, the network layer to be quantized is determined as the target network layer to be quantized, and the step of quantizing the target network layer to be quantized is triggered.
[0076] That is to say, in the iterative training process, by repeatedly executing steps S303-S306, the data processing device can gradually (in stages) quantize the network layers that need to be quantized in the network model to be quantized (i.e., each time a network layer that needs to be quantized in the network model to be quantized is selected for quantization), until all network layers that need to be quantized in the network model to be quantized are quantized, and the pre-trained model converges to obtain the final quantized model. Practice has found that by processing the model using the data processing method provided in this application, the scale of the neural network model can be reduced well, and the representation ability of the neural network model can be better retained (i.e., the loss of recognition accuracy caused by directly quantizing all network layers in the upgraded network model is reduced).
[0077] Figure 4a This is a flowchart of updating a pre-trained model provided in an embodiment of the present application. Figure 4a As shown, the update process of the pre-trained model includes Step 1-Step 7:
[0078] Step 1: The data processing device obtains a pre-trained model, and the parameters of the pre-trained model can be obtained by pre-training the initial model using the full-precision training data set (i.e., the first training data set) in the training data module by the full-precision model training module.
[0079] Step 2: The data processing device determines the insertion timing (i.e., the conditions for triggering the quantization of the target network layer to be quantized) and the insertion position of the pseudo-quantization node according to the pre-set staged quantization rules. The example rules corresponding to the staged layer-by-layer quantization scheme proposed in this application are: from shallow to deep layers, every N steps (step: a model forward and reverse operation, that is, inputting the training data into the model, obtaining the prediction result, and updating the model according to the prediction result and the label of the training data) insert a pseudo-quantization operator (such as a pseudo-quantization operator between two network layers) at the associated position of the layer to be quantized to simulate the actual quantization operation.
[0080] Step 3: If the data processing device in Step 2 determines that a pseudo-quantization operator needs to be inserted into the current network layer, the pseudo-quantization operator corresponding to the current network layer is inserted according to the above formula 1 (that is, the parameters of the current network layer are updated through the pseudo-quantization operator. The specific implementation method can refer to steps S304 and S305, which will not be repeated here).
[0081] Step 4: The data processing device obtains training data, which may be training data provided by a training data module (eg, the training data is data obtained after the training data module quantizes the full-precision data).
[0082] Step 5: The data processing device forward calculates the loss function in the pre-trained model with the pseudo-quantization operator.
[0083] Step 6: The data processing device calculates the gradient of each parameter in the quantization model according to the loss function, and finally updates the parameters of the pre-trained model according to the pre-set method. It should be noted that the calculated data at this time is still calculated in full precision, and the pseudo-quantization operator only simulates the quantization operation.
[0084] Step 7: Determine whether there are still network layers that need to be quantized in the pre-trained model (that is, ensure that all network layers that need to be quantized in the pre-trained model have been quantized). If there are no network layers that need to be quantized in the pre-trained model and the pre-trained model has converged, stop iterating and updating the pre-trained model and output the updated pre-trained model; if there are network layers that need to be quantized in the pre-trained model, continue to repeat steps 2 to 6 until there are no network layers that need to be quantized in the pre-trained model and the pre-trained model has converged.
[0085] S307 , performing quantization conversion on N network parameters included in the model to be converted based on the quantization coefficients to obtain a quantized model.
[0086] In one embodiment, the data processing device extracts the quantization coefficient D of the corresponding network layer in each pseudo-quantization operator and the quantized parameter Z=round(R / D) of the corresponding network layer, where Z is an N-bit fixed-point number and the quantization coefficient D is a full-precision number. For the quantization operator of the activated output, in addition to extracting the quantization coefficient D, the corresponding pseudo-quantization operator is retained. After extracting the above parameters, the data processing device can convert the pre-trained model into a quantized model through a model conversion framework (such as tflite, onnx, etc.).
[0087] In another embodiment, after obtaining the quantization model, the data processing device determines whether the quantization model meets the deployment conditions based on its own configuration parameters. If the quantization model meets the deployment conditions, the quantization model is deployed; if the quantization model does not meet the deployment conditions, the scale of the quantization model can be further reduced by adjusting the number of quantization bits (the smaller the number of quantization bits, the smaller the scale of the model (required storage space, computing power, power consumption, etc.)) to obtain a quantization model that meets the deployment conditions.
[0088] In one embodiment, after the data processing device deploys the quantization model, the data processing device obtains the data to be predicted; quantizes the data to be predicted (such as quantizing the data to be predicted through a training data module), and calls the quantization model to process the quantized data to be predicted. In a specific implementation, the quantization model can be a face recognition model, the data processing device (through a device with an image acquisition function, such as a camera) collects the face data to be processed (i.e., the data to be predicted), and quantizes the face data to be processed to obtain quantized face data (i.e., the quantized data to be predicted), the data processing device determines the face area from the quantized face data (such as cropping the quantized face data to obtain the face area), calls the face recognition model to perform face recognition on the quantized face area, and outputs the recognition result. It can be understood that by determining the face area from the quantized face data, the amount of calculation of the face recognition model can be further reduced, and the recognition efficiency of the face recognition model can be improved. Similarly, the quantization model can also be a speech recognition model. The data processing device collects the speech data to be recognized (i.e., the data to be predicted) through the speech acquisition device (such as a microphone), and quantizes the speech data to be recognized to obtain quantized speech data (i.e., the quantized data to be predicted). The data processing device calls the speech recognition model to perform speech recognition on the quantized speech data and outputs the recognition result. Similarly, the quantization model can also be a prediction model (such as predicting the products and videos that the user may like), a classification model (such as classifying short videos), etc.
[0089] In an embodiment of the present application, a pre-trained model and a second training data set are obtained, and the second training data set is used to iteratively train the pre-trained model; during the iterative training process, if the current number of iterations meets the parameter quantization conditions, the target network layer to be quantized is determined from the N network layers, the target network layer to be quantized is quantized, and the pre-trained model is updated according to the quantized target network layer to be quantized; and the updated pre-trained model is trained using the second training data set to obtain a quantized model. It can be seen that in the process of iterative training of the pre-trained model, by using the quantized target network layer to be quantized to update the pre-trained model, the scale of the neural network model can be reduced; practice has found that by using the progressive optimization method, not only a compact and efficient recognition model can be obtained, but also the interference of the quantization error on the training process can be significantly reduced, thereby optimizing the performance of the quantization model (such as recognition speed, recognition accuracy, etc.).
[0090] Based on the above data processing method, the embodiment of the present invention provides an application scenario of a quantitative model. Figure 4b , is an application scenario diagram of a quantization model provided in an embodiment of the present application. Figure 4bIn the embodiment, the data processing device 401 is a camera that deploys a face recognition model. The deployment method of the face recognition model can refer to the above steps S201-S204, or refer to steps S301-S307, which will not be repeated here. In addition, the camera (data processing device 401) stores the target face to be found (such as a photo of a lost child). The camera collects the face data of people passing through area 402 (i.e., the camera acquisition area), and compares these faces with the target face. When it is detected that there is a face matching the target face in the collected face data (such as the similarity is higher than the threshold), a prompt message is output. Specifically, the data processing device 401 quantizes the face data (picture) collected in area 402 (such as adjusting the clarity) to obtain the quantized face data, and determines the face area from the quantized face data, calls the face recognition model to perform face recognition on the quantized face area (i.e., detect the similarity between the face area and the target face), and outputs the face recognition result.
[0091] See also Figure 4c , is another application scenario diagram of a quantization model provided in an embodiment of the present application. Figure 4c In the example, the data processing device 403 is an access control device that deploys a face recognition model, and the face of the target user with the right to open the door is stored in the access control device; when a request to open the door is detected, the access control device collects the face of the requesting user who currently requests to open the door, and if the face of the requesting user matches the face of the target user, the door is opened; if they do not match, a prompt message is output, and the prompt message is used to prompt that the requesting user does not have the right to open the door. Specifically, the data processing device 403 quantizes the face data (picture) collected in the area 404 (i.e., the camera acquisition area) (such as adjusting the clarity) to obtain the quantized face data, and determines the face area from the quantized face data, and calls the face recognition model to perform face recognition on the quantized face area (i.e., detect the similarity between the face area and the face of the target user), and if the face recognition passes (the similarity is higher than the threshold), the door is opened; if the face recognition fails (the similarity is lower than the threshold), it prompts that the requesting user does not have the right to open the door.
[0092] The method of the embodiment of the present application is described in detail above. In order to facilitate better implementation of the above scheme of the embodiment of the present application, the device of the embodiment of the present application is provided below accordingly.
[0093] See also Figure 5 , Figure 5 A schematic diagram of a data processing device provided in an embodiment of the present application, which can be mounted on Figure 1a The data processing device 101 or the model storage device 102 is shown. Figure 5 The data processing device shown can be used to perform the above Figure 2 and Figure 3 Part or all of the functions of the method embodiment described. The detailed description of each unit is as follows:
[0094] An acquisition unit 501 is used to acquire a pre-trained model and a second training data set; the pre-trained model includes N network layers, and the parameters of the N network layers are initialized based on the parameters of the N network layers in the pre-trained model; the pre-trained model is obtained by iterative training based on the first training data set, and the first training data set includes full-precision first training data and training labels of the first training data;
[0095] The processing unit 502 is used to iteratively train the pre-trained model using the second training data set; the second training data set includes quantized second training data and training labels corresponding to the second training data; and is used to determine a target network layer to be quantized from the N network layers if the current number of iterations meets the parameter quantization condition during the iterative training process, quantize the target network layer to be quantized, and update the pre-trained model according to the quantized target network layer to be quantized; and is used to train the updated pre-trained model using the second training data set to obtain a quantized model.
[0096] In one embodiment, the processing unit 502 is specifically configured to:
[0097] Acquire a quantization coefficient, and calculate a pseudo quantization operator based on the quantization coefficient and a first parameter, where the first parameter refers to a parameter in the target network layer to be quantized;
[0098] The first parameter and the pseudo quantization operator are subjected to a preset operation process, and the operation process result is used to replace the target network layer to be quantized.
[0099] In one embodiment, the number of the first parameter is at least one; the processing unit 502 is specifically configured to:
[0100] Determining the number of quantization bits, and determining a target first parameter that meets an absolute value requirement from at least one first parameter;
[0101] Substitute the target first parameter and the number of quantization bits into the quantization coefficient operation rule to perform operation to obtain the quantization coefficient.
[0102] In one embodiment, the processing unit 502 is specifically configured to:
[0103] Performing a division operation on the first parameter and the quantization coefficient, and performing a rounding operation on the division result using a rounding function;
[0104] The rounding operation result is multiplied by the quantization coefficient to obtain a pseudo quantization operator.
[0105] In one embodiment, the N network layers include M convolutional layers and W fully connected layers connected in order from shallow to deep in the network, M and W are positive integers, and both M and W are less than N; the processing unit 502 is specifically used to:
[0106] Select the network layers that are not quantized from the M convolutional layers and W fully connected layers in order from shallow to deep;
[0107] The selected network layer is used as the target network layer to be quantized.
[0108] In one embodiment, the processing unit 502 is further configured to:
[0109] During the training process of the updated pre-trained model using the second training data set, if the current number of iterations meets the parameter quantization conditions, and there is a network layer to be quantized among the N network layers, the network layer to be quantized is determined as the target network layer to be quantized, and the step of quantizing the target network layer to be quantized is triggered.
[0110] In one embodiment, the processing unit 502 is specifically configured to:
[0111] The updated pre-trained model is trained using the second training data set, and a model to be converted is obtained after the training is completed;
[0112] Based on the quantization coefficients, the N network parameters included in the model to be converted are quantized and converted to obtain a quantized model.
[0113] In one embodiment, the processing unit 502 is specifically configured to:
[0114] Obtaining parameters of a pseudo-quantization operator corresponding to the quantized network layer in the updated pre-trained model, and parameters of the quantized network layer;
[0115] The updated pre-trained model is converted according to the parameters of the pseudo-quantization operator corresponding to the quantized network layer and the parameters of the quantized network layer to obtain a quantized model.
[0116] In one embodiment, the parameter quantization condition includes: the current number of iterations is divisible by P, where P is a positive integer.
[0117] In one embodiment, the processing unit 502 is further configured to:
[0118] In response to deploying the pre-trained model in a data processing device, obtaining configuration parameters of the data processing device;
[0119] If the configuration parameters of the data processing device do not match the deployment conditions of the pre-trained model, triggering the execution of the method described in steps S201 to S204, or steps S301 to S307 to obtain a quantized model, the deployment conditions of the quantized model match the configuration parameters of the data processing device;
[0120] The quantitative model is deployed in the data processing device.
[0121] In one embodiment, the quantization model is a face recognition model; the processing unit 502 is further configured to:
[0122] Collect facial data to be identified;
[0123] quantizing the face data to be identified to obtain quantized face data;
[0124] Determining a face region from the quantized face data;
[0125] The quantization model is called to perform recognition processing on the face area, and a recognition result is output.
[0126] According to one embodiment of the present application, Figure 2 and Figure 3 Some of the steps involved in the data processing method shown can be represented by Figure 5 The data processing device shown in the figure is executed by each unit. For example, Figure 2 Steps S201 and S202 shown in FIG. 1 can be represented by Figure 5 The acquisition unit 501 shown in FIG. 1 is executed, and step S203 and step S204 can be performed by Figure 5 Processing unit 502 is shown executing. Figure 3 Steps S301 and S302 shown in FIG. 1 can be represented by Figure 5 The acquisition unit 501 shown in FIG. 1 is executed, and steps S303 to S308 can be performed by Figure 5 Processing unit 502 is shown executing. Figure 5 The various units in the data processing device shown can be respectively or all combined into one or several other units to constitute, or some of the units (some) can also be split into multiple smaller units in function to constitute, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above-mentioned units are divided based on logical functions. In practical applications, the function of a unit can also be implemented by multiple units, or the function of multiple units can be implemented by one unit. In other embodiments of the present application, the data processing device may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented by the collaboration of multiple units.
[0127] According to another embodiment of the present application, the program can be executed by running on a general computing device such as a computer including a central processing unit (CPU), a random access memory medium (RAM), a read-only memory medium (ROM) and other processing elements and storage elements. Figure 2 and Figure 3 A computer program (including program code) for each step involved in the corresponding method shown in Figure 5 The data processing device shown in and the data processing method of the embodiment of the present application are implemented. The computer program can be recorded on, for example, a computer readable recording medium, and loaded into the above-mentioned computing device through the computer readable recording medium and run therein.
[0128] Based on the same inventive concept, the principles and beneficial effects of solving the problems by the data processing device provided in the embodiment of the present application are similar to the principles and beneficial effects of solving the problems by the data processing device in the method embodiment of the present application. Please refer to the principles and beneficial effects of the implementation of the method. For the sake of concise description, they will not be repeated here.
[0129] See also Figure 6 , Figure 6 A structural diagram of a data processing device provided in an embodiment of the present application, the data processing device at least includes a processor 601, a communication interface 602 and a memory 603. Among them, the processor 601, the communication interface 602 and the memory 603 can be connected via a bus or other means. Among them, the processor 601 (or the central processing unit (CPU)) is the computing core and control core of the terminal, which can parse various instructions in the terminal and process various data of the terminal. For example, the CPU can be used to parse the power on and off instructions sent by the user to the terminal, and control the terminal to perform power on and off operations; for example, the CPU can transmit various types of interactive data between the internal structures of the terminal, and so on. The communication interface 602 can optionally include a standard wired interface, a wireless interface (such as WI-FI, a mobile communication interface, etc.), which can be used to send and receive data under the control of the processor 601; the communication interface 602 can also be used for the transmission and interaction of data within the terminal. The memory 603 (Memory) is a memory device in the terminal for storing programs and data. It can be understood that the memory 603 here can include both the built-in memory of the terminal and the extended memory supported by the terminal. The memory 603 provides a storage space, which stores the operating system of the terminal, including but not limited to: Android system, iOS system, Windows Phone system, etc., which is not limited in this application.
[0130] In the embodiment of the present application, the processor 601 is used to perform the following operations by running the executable program code in the memory 603:
[0131] Obtain a pre-trained model, the pre-trained model comprising N network layers; the pre-trained model is obtained by iterative training based on a first training data set, the first training data set comprising full-precision first training data and training labels for the first training data;
[0132] Obtaining a second training data set, and using the second training data set to iteratively train the pre-trained model; the second training data set includes quantized second training data and training labels corresponding to the second training data;
[0133] During the iterative training process, if the current number of iterations meets the parameter quantization condition, a target network layer to be quantized is determined from the N network layers, and the target network layer to be quantized is quantized; and the pre-trained model is updated according to the quantized target network layer to be quantized;
[0134] The updated pre-trained model is trained using the second training data set to obtain a quantized model.
[0135] As an optional embodiment, a specific embodiment in which the processor 601 quantizes the target network layer to be quantized is:
[0136] Acquire a quantization coefficient, and calculate a pseudo quantization operator based on the quantization coefficient and a first parameter, where the first parameter refers to a parameter in the target network layer to be quantized;
[0137] The first parameter and the pseudo quantization operator are subjected to a preset operation process, and the operation process result is used to replace the target network layer to be quantized.
[0138] As an optional embodiment, the number of the first parameter is at least one, and a specific embodiment in which the processor 601 obtains the quantization coefficient is:
[0139] Determining the number of quantization bits, and determining a target first parameter that meets an absolute value requirement from at least one first parameter;
[0140] Substitute the target first parameter and the number of quantization bits into the quantization coefficient operation rule to perform operation to obtain the quantization coefficient.
[0141] As an optional embodiment, a specific embodiment in which the processor 601 calculates the pseudo quantization operator based on the quantization coefficient and the first parameter is:
[0142] Performing a division operation on the first parameter and the quantization coefficient, and performing a rounding operation on the division result using a rounding function;
[0143] The rounding operation result is multiplied by the quantization coefficient to obtain a pseudo quantization operator.
[0144] As an optional embodiment, the N network layers include M convolutional layers and W fully connected layers connected in order from shallow to deep in the network, M and W are positive integers, and M and W are both less than N; the specific embodiment in which the processor 601 determines the target network layer to be quantized from the N network layers is:
[0145] Select the network layers that are not quantized from the M convolutional layers and W fully connected layers in order from shallow to deep;
[0146] The selected network layer is used as the target network layer to be quantized.
[0147] As an optional embodiment, the processor 601 further performs the following operations by running the executable program code in the memory 603:
[0148] During the training process of the updated pre-trained model using the second training data set, if the current number of iterations meets the parameter quantization conditions, and there is a network layer to be quantized among the N network layers, the network layer to be quantized is determined as the target network layer to be quantized, and the step of quantizing the target network layer to be quantized is triggered.
[0149] As an optional embodiment, the processor 601 uses the second training data set to train the updated pre-trained model, and a specific embodiment of obtaining the quantization model is:
[0150] The updated pre-trained model is trained using the second training data set, and a model to be converted is obtained after the training is completed;
[0151] Based on the quantization coefficients, the N network parameters included in the model to be converted are quantized and converted to obtain a quantized model.
[0152] As an optional embodiment, the processor 601 performs quantization conversion on the N network parameters included in the model to be converted based on the quantization coefficient, and a specific embodiment of obtaining the quantization model is:
[0153] Obtaining parameters of a pseudo-quantization operator corresponding to the quantized network layer in the updated pre-trained model, and parameters of the quantized network layer;
[0154] The updated pre-trained model is converted according to the parameters of the pseudo-quantization operator corresponding to the quantized network layer and the parameters of the quantized network layer to obtain a quantized model.
[0155] As an optional embodiment, the parameter quantization condition includes: the current number of iterations is divisible by P, where P is a positive integer.
[0156] As an optional embodiment, the processor 601 further performs the following operations by running the executable program code in the memory 603:
[0157] In response to deploying the pre-trained model in a data processing device, obtaining configuration parameters of the data processing device;
[0158] If the configuration parameters of the data processing device do not match the deployment conditions of the pre-trained model, triggering the execution of the method described in steps S201 to S204, or steps S301 to S307 to obtain a quantized model, the deployment conditions of the quantized model match the configuration parameters of the data processing device;
[0159] The quantitative model is deployed in the data processing device.
[0160] As an optional embodiment, the quantization model is a face recognition model; the processor 601 further performs the following operations by running the executable program code in the memory 603:
[0161] Collect facial data to be identified;
[0162] quantizing the face data to be identified to obtain quantized face data;
[0163] Determining a face region from the quantized face data;
[0164] The quantization model is called to perform recognition processing on the face area, and a recognition result is output.
[0165] Based on the same inventive concept, the principles and beneficial effects of solving the problems by the data processing device provided in the embodiment of the present application are similar to the principles and beneficial effects of solving the problems by the data processing method in the method embodiment of the present application. Please refer to the principles and beneficial effects of the implementation of the method. For the sake of concise description, they will not be repeated here.
[0166] An embodiment of the present application also provides a computer-readable storage medium, in which one or more instructions are stored, and the one or more instructions are suitable for being loaded by a processor and executing the data processing method described in the above method embodiment.
[0167] An embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the data processing method described in the above method embodiment.
[0168] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device performs the above-mentioned data processing method.
[0169] The steps in the method of the embodiment of the present application can be adjusted in order, combined and deleted according to actual needs.
[0170] The modules in the device of the embodiment of the present application can be merged, divided and deleted according to actual needs.
[0171] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the readable storage medium can include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0172] What is disclosed above is only a preferred embodiment of the present application, and it certainly cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of the above embodiment and equivalent changes made according to the claims of the present application are still within the scope of the invention.
Claims
1. A data processing method, characterized in that: The method comprises: Obtain a pre-trained model, the pre-trained model comprising N network layers; the pre-trained model is obtained by iterative training based on a first training data set, the first training data set comprising full-precision first training data and training labels for the first training data; Obtaining a second training data set, and using the second training data set to iteratively train the pre-trained model; the second training data set includes quantized second training data and training labels corresponding to the second training data; During the iterative training process, if the current number of iterations meets the parameter quantization condition, a target network layer to be quantized is determined from the N network layers, and the target network layer to be quantized is quantized; and the pre-trained model is updated according to the quantized target network layer to be quantized; The updated pre-trained model is trained using the second training data set to obtain a quantized model; the quantized model is deployed in a data processing device to perform recognition processing on the data to be processed collected by the data processing device, and output a recognition result; wherein, if the quantized model is an image recognition model and the data to be processed is image data to be processed, then the quantized model is used to recognize the image data to be processed and output a recognition result; or, if the quantized model is a speech recognition model and the data to be processed is speech data to be recognized, then the quantized model is used to perform speech recognition on the speech data to be recognized and output a recognition result.
2. The method according to claim 1, characterized in that The quantizing the target network layer to be quantized includes: Acquire a quantization coefficient, and calculate a pseudo quantization operator based on the quantization coefficient and a first parameter, where the first parameter refers to a parameter in the target network layer to be quantized; The first parameter and the pseudo quantization operator are subjected to a preset operation process, and the operation process result is used to replace the target network layer to be quantized.
3. The method according to claim 2, characterized in that The number of the first parameters is at least one, and obtaining the quantization coefficient includes: Determining the number of quantization bits, and determining a target first parameter that meets an absolute value requirement from at least one first parameter; Substitute the target first parameter and the number of quantization bits into the quantization coefficient operation rule to perform operation to obtain the quantization coefficient.
4. The method according to claim 2, characterized in that The calculating of the pseudo quantization operator based on the quantization coefficient and the first parameter includes: Performing a division operation on the first parameter and the quantization coefficient, and performing a rounding operation on the division result using a rounding function; The rounding operation result is multiplied by the quantization coefficient to obtain a pseudo quantization operator.
5. The method according to claim 1, characterized in that The N network layers include M convolutional layers and W fully connected layers connected in order from shallow to deep in the network, M and W are positive integers, and both M and W are less than N. The target network layer to be quantized is determined from the N network layers, including: Select the network layers that are not quantized from the M convolutional layers and W fully connected layers in order from shallow to deep; The selected network layer is used as the target network layer to be quantized.
6. The method according to claim 1, characterized in that The method further comprises: During the training process of the updated pre-trained model using the second training data set, if the current number of iterations meets the parameter quantization conditions, and there is a network layer to be quantized among the N network layers, the network layer to be quantized is determined as the target network layer to be quantized, and the step of quantizing the target network layer to be quantized is triggered.
7. The method according to claim 1, characterized in that The step of training the updated pre-trained model using the second training data set to obtain a quantized model includes: The updated pre-trained model is trained using the second training data set, and a model to be converted is obtained after the training is completed; Based on the quantization coefficients, the N network parameters included in the model to be converted are quantized and converted to obtain a quantized model.
8. The method according to claim 7, characterized in that The step of performing quantization conversion on the N network parameters included in the model to be converted based on the quantization coefficients to obtain the quantized model includes: Obtaining parameters of a pseudo-quantization operator corresponding to the quantized network layer in the updated pre-trained model, and parameters of the quantized network layer; The updated pre-trained model is converted according to the parameters of the pseudo-quantization operator corresponding to the quantized network layer and the parameters of the quantized network layer to obtain a quantized model.
9. The method according to claim 1, characterized in that The parameter quantization condition includes: the current number of iterations can be divided by P, where P is a positive integer.
10. The method according to claim 1, characterized in that The method further comprises: In response to deploying the pre-trained model in a data processing device, obtaining configuration parameters of the data processing device; If the configuration parameters of the data processing device do not match the deployment conditions of the pre-trained model, triggering execution of the data processing method according to any one of claims 1 to 9 to obtain a quantized model, the deployment conditions of the quantized model match the configuration parameters of the data processing device; The quantitative model is deployed in the data processing device.
11. The method according to claim 10, characterized in that The quantization model is a face recognition model. After the quantization model is deployed in the data processing device, the method further includes: Collect facial data to be identified; quantizing the face data to be identified to obtain quantized face data; Determining a face region from the quantized face data; The quantization model is called to perform recognition processing on the face area, and a recognition result is output.
12. A data processing device, characterized in that: The data processing device comprises: An acquisition unit is used to acquire a pre-trained model and a second training data set; the pre-trained model includes N network layers, and the parameters of the N network layers are initialized based on the parameters of the N network layers in the pre-trained model; the pre-trained model is obtained by iterative training based on the first training data set, and the first training data set includes full-precision first training data and training labels of the first training data; A processing unit, configured to iteratively train the pre-trained model using the second training data set; the second training data set includes quantized second training data and training labels corresponding to the second training data; and to determine a target network layer to be quantized from the N network layers if the current number of iterations meets the parameter quantization condition during the iterative training process, quantize the target network layer to be quantized, and update the pre-trained model according to the quantized target network layer to be quantized; and to train the updated pre-trained model using the second training data set to obtain a quantized model; the quantized model is deployed in a data processing device, configured to perform recognition processing on the data to be processed collected by the data processing device, and output a recognition result; wherein, if the quantized model is an image recognition model and the data to be processed is image data to be processed, the quantized model is configured to recognize the image data to be processed and output a recognition result; or, if the quantized model is a speech recognition model and the data to be processed is speech data to be recognized, the quantized model is configured to perform speech recognition on the speech data to be recognized and output a recognition result.
13. A data processing device, characterized in that: include: storage devices and processors; The storage device stores a computer program; A processor, configured to load and execute the computer program to implement the data processing method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is suitable for being loaded by a processor and executing the data processing method according to any one of claims 1 to 11.
15. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the data processing method according to any one of claims 1 to 11 are implemented.
