Neural network quantization compression method based on bit allocation operator
By using bit allocation operators and other quantization algorithms in the YOLO network model to dynamically adjust the bit width of each layer, the problem of decreased accuracy after quantization of the YOLO network model is solved, and efficient operation and accuracy on resource-constrained devices are achieved. Keep.
Patent Information
- Application Number
- CN202410898581.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-10-29
AI Technical Summary
In the existing technology, it is difficult to accurately adjust the bit width of each layer of the model during the quantification process of the YOLO network model, resulting in a decrease in the accuracy of the quantized model and the inability to effectively adapt to resource-limited hardware devices.
The neural network quantization compression method based on the bit allocation operator is used to dynamically identify the floating changes in the weight of the network layer, adjust the bit width in real time, and use the asymmetric quantization method, Clip function, bit allocation algorithm and random parameter clipping algorithm in the quantization process. , ensuring that the bit width of each layer of the model is appropriate to maintain model accuracy.
It effectively reduces the storage requirements and inference calculation amount of the model, and at the same time makes the quantized model accuracy close to the original model accuracy, solves the problem of accuracy decline caused by weight floating, and improves the adaptability of the YOLO model on resource-constrained devices.
Smart Images

Figure CN118862964A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of neural network parameter quantization, and in particular to a neural network quantization compression method based on a bit allocation operator. Background Art
[0002] With the rapid development of deep learning technology and the continuous expansion of its application fields, building more complex and deeper neural network models has become the norm. The YOLO (You Only Look Once) network model in the field of target detection has been widely used in many fields such as autonomous driving, security monitoring, and intelligent robots due to its excellent performance and real-time performance. However, with the continuous iteration and update of the YOLO model, although its recognition ability has been significantly improved, the number of model parameters has also shown an exponential growth trend. This growth not only requires a large amount of computing resources to be consumed during the training process, but also makes the model face huge challenges when deployed on resource-constrained devices. Model quantization technology provides an effective solution for compressing and accelerating the YOLO network model. Model quantization can significantly reduce the storage requirements and inference calculation amount of the model by converting the parameters and activation values in the neural network from high-precision floating-point representation to low-bit-width fixed-point or integer representation, so that the YOLO model can better adapt to resource-constrained hardware devices.
[0003] Currently, there are two common methods for model quantization: single-precision model quantization and mixed-precision model quantization. Single-precision model quantization maps the weights of the entire network model to the same bit width, such as the commonly used 8-bit integer. This method is relatively simple to implement because all weights use a unified quantization scheme and no special processing is required for different layers. However, the disadvantages of this method are also obvious: it does not take into account the differences in the importance of network weights and uses the same quantization strategy for all weights. Mixed-precision model quantization maps different weight layers of the network to different bit widths, allowing different parts of the network to have different quantization accuracies. This method can more flexibly balance the model's storage requirements, inference speed, and accuracy loss.
[0004] In recent years, more and more research has begun to focus on mixed precision model quantization and successfully applied it to the YOLO network model. Different optimization algorithms have been proposed to keep the overall model at a low bit width as much as possible, but the accuracy loss is maintained within an acceptable range. The BSQ[1] method mainly performs a sparse effect on the weight layer through regularization and then performs a mixed quantization operation on it. The QDROP[2] method mainly improves the accuracy of the overall model by modifying the activation layer weight quantization. The PACT[3] method mainly introduces new activation parameters and uses the gradient descent method to determine the optimal value of the parameter for weight quantization. However, these methods currently find it difficult to accurately locate the bit width when the weights of each layer of the model fluctuate, resulting in the final bit width of each layer of the model not being the most suitable for the model. After being used in the YOLO network model, the number of image features cannot be effectively recognized, resulting in a decrease in the recognition accuracy of the quantized model[4]. Although MPQ-YOLO[5] uses mixed precision quantization to compress the YOLO model, it still cannot be well deployed on resource-constrained hardware devices.
[0005] [1]Yang H,Duan L,Chen Y,et al.BSQ:Exploring bit-level sparsity formixed-precision neural network quantization[J].arXiv preprint arXiv:210210462,2021.
[0006] [2]Wei
[0007] [3]Choi J,Wang Z,Venkataramani S,et al.Pact:Parameterized clippingactivation for quantized neural networks[J].arXiv preprint arXiv:180506085,2018.
[0008] [4]Ashfaq S,Askarihemmat M,Sah S,et al.Accelerating deep learning model inference on arm cpus with ultra-low bit quantization and runtime[J].arXiv preprint arXiv:220708820,2022.
[0009] [5]Liu X, Wang T, Yang J, et al. MPQ-YOLO: Ultra low mixed-precision quantization of YOLO for edge devices deployment[J]. Neurocomputing, 2024,574. Summary of the invention
[0010] The purpose of the present invention is to overcome the deficiencies in the prior art and to provide a quantization compression method that can dynamically adjust the bit widths of different layers in a model during the quantization process.
[0011] To achieve the above object, the present invention proposes a neural network quantization compression method based on a bit allocation operator. The method applies the bit allocation operator to a YOLO network model, performs different degrees of quantization operations on the backbone module and the neck module in the YOLO network model, reduces storage space, and is convenient for running on resource-constrained devices.
[0012] The bit allocation operator adopts a bit allocation operator quantization algorithm, dynamically identifies weight changes by adopting hyperparameters, and can timely adjust the bit width of weight parameter quantization according to the weight floating changes of different network layers; since the network layer has a large percentage of weight after quantization, but its allocated bit width is low, the performance of the layer cannot be released, which easily leads to a serious decrease in the accuracy of the quantized model. Through the bit allocation operator, the bit width of the network layer can be readjusted, so that the accuracy of the quantized model is close to the accuracy of the original model.
[0013] Furthermore, the method comprises the following steps:
[0014] 1) Using an asymmetric quantization method to quantize the weight layer to obtain the quantized weight parameters;
[0015] 2) After the quantization work of the weight layer is completed, the quantization weight is limited to a specified bit width;
[0016] 3) Send the weight parameters that complete the quantization mapping process into the YOLO network model for forward propagation;
[0017] 4) As the YOLO network model is trained, the model weights begin to fluctuate irregularly under the effect of regularization, and the original bit width cannot meet the new weight distribution. At this time, the bit allocation operator is used to adjust it. According to the weight fluctuation change, the quantized bit width is adjusted in time through the bit allocation operator;
[0018] 5) Use the activation quantization algorithm with random parameter clipping to perform quantization operations on the activation layer.
[0019] Furthermore, the formula 1 used in step 1) is:
[0020]
[0021] In formula 1, q w Represents the quantized weight parameter; W represents the weight parameter in the network; scale represents the quantization proportional factor, which is used to control the quantization mapping range. The commonly used scale is the maximum absolute value of the weight value; zeropoint represents the offset in the quantization process, which is obtained through training parameters.
[0022] Furthermore, in step 2), the quantization weight is limited to a specified bit width by a Clip function, and the Clip function is the following formula 2:
[0023] Q w = Clip(q w ,min(q),max(q)) Formula 2
[0024] In Formula 2, max(q) and min(q) represent the maximum value and the minimum value under the specified bit width.
[0025] Furthermore, in step 4), the bit allocation operator adopts a bit allocation operator quantization algorithm, and the specific formula is:
[0026]
[0027] In formula 3, Q b represents the overall quantization bit width of the final layer of the network, Round represents the rounding function, β1 and β2 are the strength parameters used to adjust the quantization bit width, and b i and b j Represents the temporary bit width of the layer during network training, and θ is the threshold used to measure the weight distribution during training.
[0028] Furthermore, in step 4), the quantization mechanism of the bit allocation operator is to dynamically adjust the quantization bit width by evaluating the importance of the weight distribution of each layer, and the importance of the weight distribution is determined by comparing the relationship between the weight distribution of each layer and the threshold θ, and the specific method is:
[0029] The weight part greater than θ is regarded as an important weight layer, which contains a large number of features. By rounding up, more bit width is allocated to ensure sufficient accuracy and information retention;
[0030] The weight layers less than θ are rounded down to the nearest integer to compress the weight values as much as possible, and all weight data are binarized and compressed using Formula 4. By binarizing the weight layers less than θ, the model memory usage is reduced and the model inference speed is increased. Formula 4 is:
[0031]
[0032] In formula 4, x b Represents 1-bit data, x represents weight, Sign(x) represents the sign function, and returns 1 when the weight value x is greater than 0, and returns -1 when it is less than 0.
[0033] Furthermore, in step 5), the formula for activating the quantization algorithm is as follows:
[0034]
[0035] In formula 5, the two hyperparameters p and q are used to control the strength of activation layer quantization. The values of p and q are in the range of (0,1) and need to satisfy p+q<1. The α parameter is used to dynamically determine the upper limit of clipping, and the α parameter can be optimized through back propagation and can be adaptively adjusted according to the characteristics of different layers and different data.
[0036] When the activation layer weight x belongs to the interval (-∞,0) and the probability of random parameter clipping is p, the activation value is 0; when the activation layer weight x belongs to the interval [0,α) and the probability of random parameter clipping is q, the activation value is x; when the activation layer weight x belongs to the interval [α,+∞) and the probability of random parameter clipping is 1-pq, the activation value is α.
[0037] Furthermore, the method also includes step 6): using the hardware device Raspberry Pi 4B to deploy the compressed YOLO network model. After the training on the PC is completed, the weight file of the YOLO model integrated with the bit allocation operator is converted into the ONNX format. At the same time, the onnxruntime inference engine is installed in the Raspberry Pi 4B in advance. After the installation is completed, the trained ONNX format file is imported into the Raspberry Pi 4B for inference to verify the validity.
[0038] Furthermore, since multiple modules of the YOLO network model are composed of different convolutional layers and activation functions, the method of the present invention is mainly aimed at the convolutional layer and the activation layer, and the neural network quantization compression method is mainly applied to the convolutional layer and the activation layer.
[0039] Compared with the prior art, the advantages of the present invention are:
[0040] 1. The present invention integrates the bit allocation operator into the YOLO network model, adopts hyperparameters to monitor the network model in real time, dynamically identifies weight changes, and adjusts the strength of the quantization bit width through the strength parameter according to the different weight layers of the network model and their weight fluctuations, thereby dynamically adjusting the bit widths of different network model layers and extracting effective weights in the network model. While reducing the storage requirements and reasoning calculation amount of the model, the accuracy of the quantized model is also made close to the accuracy of the original model, solving the problem of severe decline in quantization accuracy caused by weight fluctuations during YOLO network training, so that the YOLO model can better adapt to resource-constrained hardware devices and reduce the accuracy loss caused by quantization operations. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 It is a quantized diagram of the backbone module and the neck module in the YOLO network model in an embodiment of the present invention;
[0042] Figure 2 A schematic diagram of a quantization mechanism of a bit allocation operator in an embodiment of the present invention;
[0043] Figure 3 The present invention is a flowchart of a neural network quantization compression method based on a bit allocation operator according to an embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be further described below.
[0045] This embodiment proposes a neural network quantization compression method based on a bit allocation operator, such as Figure 1As shown in FIG. 1 , the method integrates the bit allocation operator into the YOLO network model, and performs different degrees of quantization operations on the backbone module and the neck module in the YOLO network model, so as to reduce the storage space occupied by the backbone module and the neck module, thereby facilitating operation on resource-constrained devices.
[0046] Among them, the bit allocation operator adopts a bit allocation operator quantization algorithm, which dynamically identifies weight changes by adopting hyperparameters, and can timely adjust the quantization bit width according to the floating changes of weights of different network layers. Since the network layer has a large percentage of weight after quantization, but its allocated bit width is low, the performance of this layer cannot be released, which easily leads to a serious decrease in the accuracy of the quantized model. Through the bit allocation operator in the method in this embodiment, the bit width of the network layer can be readjusted, so that the accuracy of the quantized model is close to the accuracy of the original model.
[0047] Since multiple modules of the YOLO network model are composed of different convolutional layers and activation functions, the method in this embodiment is mainly aimed at the convolutional layer and the activation layer, such as Figure 3 As shown in the figure, the main process of this method is weight layer quantization - readjusting the bit width of the network layer through the bit allocation operator - activation layer quantization - algorithm model deployment, combined with Figure 1 The quantization diagram of the backbone module and the neck module in the YOLO network model shown in the figure, the specific steps of the implementation method are:
[0048] S1: In the backbone module, the weight data of the weight layer is quantized using formula 1 to obtain the quantized weight parameters; the formula is:
[0049]
[0050] In formula 1, q w Represents the quantized weight parameter; W represents the weight parameter in the network; scale represents the quantization proportional factor, which is used to control the quantization mapping range. The commonly used scale is the maximum absolute value of the weight value; zeropoint represents the offset in the quantization process, which is obtained through training parameters.
[0051] S2: After the quantization of the weight layer is completed, the quantization weight is limited to the specified bit width through the Clip function of formula 2. The Clip function formula is:
[0052] Q w = Clip(q w ,min(q),max(q)) Formula 2
[0053] In Formula 2, max(q) and min(q) represent the maximum value and the minimum value under the specified bit width.
[0054] S3 sends the weight parameters of the quantized mapping process to the YOLO network model for forward propagation;
[0055] S4: As the YOLO network model is trained, the model weights begin to fluctuate irregularly under the effect of regularization. The original bit width cannot meet the new weight distribution. At this time, the bit allocation operator is used to adjust the weights through Formula 3:
[0056]
[0057] In formula 3, Q b represents the overall quantization bit width of the final layer of the network, Round represents the rounding function, β1 and β2 are the strength parameters used to adjust the quantization bit width, and b i and b j Represents the temporary bit width of the layer during network training, and θ is the threshold used to measure the weight distribution during training.
[0058] Regulatory mechanisms such as Figure 2 As shown, the quantization bit width is dynamically adjusted by evaluating the importance of the weight distribution of each layer, and the importance of the weight distribution is mainly determined by comparing the relationship between the weight distribution of each layer and the threshold θ. The specific method of weight selection is:
[0059] 1) When the weight part is greater than θ, it is considered an important weight layer, which means that the layer contains a large number of features. By rounding up, more bit width is allocated to ensure sufficient accuracy and information retention;
[0060] 2) When the weight part is less than θ, the method of rounding down is used to compress the weight value as much as possible, and all weight data are binary compressed through the Sign(x) function of formula 4, and finally BatchNorm batch normalization is performed before output. Among them, the Sign(x) function of formula 4 is:
[0061]
[0062] In formula 4, x b Represents 1-bit data, x represents weight, Sign(x) represents the sign function, and returns 1 when the weight value x is greater than 0, and returns -1 when it is less than 0.
[0063] S5: In the neck module, parameter learning is first performed to determine the value of α through training; then the weights in the activation layer are compressed through the activation quantization algorithm of random parameter clipping in formula 5, and finally the output is also processed by BatchNorm batch normalization:
[0064]
[0065] In formula 5, the two hyperparameters p and q are used to control the strength of activation layer quantization. The values of p and q are in the range of (0,1) and need to satisfy p+q<1. The α parameter is used to dynamically determine the upper limit of clipping, and the α parameter can be optimized through back propagation and can be adaptively adjusted according to the characteristics of different layers and different data.
[0066] S6: Use the hardware device Raspberry Pi 4B to deploy the compressed YOLO network model. After the training is completed on the PC, convert the weight file of the YOLO model with the bit allocation operator into the ONNX format. At the same time, install the onnxruntime inference engine in the Raspberry Pi 4B in advance and wait for completion. After the installation is complete, import the trained ONNX format file into the Raspberry Pi 4B for inference and verify the validity. The results are shown in Table 1 below.
[0067] Table 1
[0068] Model Weight / Act mAP@0.5 Latency(s) YOLOv5n 32 / 32 31.2 1.32 YOLO-n 8 / 8 28.4 1.19 YOLO-n 4 / 4 26.7 0.83 YOLO-n 2 / 2 13.5 0.42
[0069] Table 1 shows the experimental results of the method of this embodiment on the COCO dataset. Table 1 shows the deployment results of the original YOLOv5n model on the Raspberry Pi and the deployment results of the quantized YOLO-n on the Raspberry Pi, where Weight / Act represents the bit width of the weight layer and the bit width of the activation layer; mAP@0.5 represents the accuracy of all-category judgment; Latency represents the delay in processing each image.
[0070] It can be seen from Table 1 that the accuracy of the model reaches 31.2 at 32-bit full precision, and the inference time for each picture is 1.32 seconds; after 8-bit quantization, the model accuracy reaches 28.4, and the inference time for processing each picture is 1.19 seconds; after 4-bit quantization, the model accuracy reaches 26.7, and the inference time for processing each picture is 0.83 seconds. These data fully indicate that although the accuracy of the quantized model is slightly reduced, the network delay time of the deployed YOLO model in the picture processing process has also decreased, indicating that the model successfully achieves convergence while avoiding serious loss of accuracy, thereby verifying the effectiveness of the method of this embodiment.
[0071] The above is only a preferred embodiment of the present invention and does not limit the present invention in any way. Any technician in the relevant technical field, without departing from the scope of the technical solution of the present invention, makes any form of equivalent replacement or modification to the technical solution and technical content disclosed in the present invention, which does not depart from the content of the technical solution of the present invention and still falls within the protection scope of the present invention.
Claims
1. A neural network quantization compression method based on a bit allocation operator, characterized in that: Applying a bit allocation operator to a YOLO network model, and performing different degrees of quantization operations on a backbone module and a neck module in the YOLO network model; The bit allocation operator adopts a bit allocation operator quantization algorithm. The bit allocation operator quantization algorithm dynamically identifies weight changes by adopting hyperparameters, and timely adjusts the bit width of weight parameter quantization according to the floating changes of weights of different network layers, so that the accuracy of the quantized model is close to the accuracy of the original model.
2. The neural network quantization compression method based on the bit allocation operator according to claim 1, characterized in that: The following steps are involved: 1) Using an asymmetric quantization method to quantize the weight layer to obtain the quantized weight parameters; 2) After the quantization work of the weight layer is completed, the quantization weight is limited to a specified bit width; 3) Send the weight parameters that complete the quantization mapping process into the YOLO network model for forward propagation; 4) According to the floating change of the weight, timely adjust the quantized bit width through the bit allocation operator; 5) Use the activation quantization algorithm with random parameter clipping to perform quantization operations on the activation layer.
3. The neural network quantization compression method based on the bit allocation operator according to claim 2 is characterized in that: The formula 1 used in step 1) is: In formula 1, q w Represents the quantized weight parameter, W represents the weight parameter in the network, scale represents the quantization scale factor, and scale is used to control the quantization mapping range. Zeropoint represents the offset in the quantization process.
4. The neural network quantization compression method based on the bit allocation operator according to claim 3 is characterized in that: In step 2), the quantization weight is limited to a specified bit width through the Clip function, and the Clip function is the following formula 2: Q w = Clip(q w , min(q), max(q)) Formula 2 In Formula 2, max(q) and min(q) represent the maximum value and the minimum value under the specified bit width.
5. The neural network quantization compression method based on the bit allocation operator according to claim 2, characterized in that: In step 4), the bit allocation operator adopts a bit allocation operator quantization algorithm, and the specific formula is: In formula 3, Q b represents the overall quantization bit width of the final layer of the network, Round represents the rounding function, β1 and β2 are the strength parameters used to adjust the quantization bit width, and b i and b j Represents the temporary bit width of the layer during network training, and θ is the threshold used to measure the weight distribution during training.
6. The neural network quantization compression method based on the bit allocation operator according to claim 5, characterized in that: In step 4), the quantization mechanism of the bit allocation operator is to dynamically adjust the quantization bit width by evaluating the importance of the weight distribution of each layer. The importance of the weight distribution is determined by comparing the relationship between the weight distribution of each layer and the threshold θ. The specific method is: The weight part greater than θ is regarded as an important weight layer, and more bit width is allocated by rounding up to ensure sufficient accuracy and information retention; The weight layer that is less than θ is rounded down to compress the weight value, and all weight data are binary compressed using Formula 4, which is: In formula 4, x b Represents 1-bit data, x represents weight, Sign(x) represents the sign function, and returns 1 when the weight value x is greater than 0, and returns -1 when it is less than 0.
7. The neural network quantization compression method based on the bit allocation operator according to claim 2, characterized in that: In step 5), the formula for activating the quantization algorithm is as follows: In formula 5, when the activation layer weight x belongs to the interval (-∞, 0) and the probability of random parameter clipping is p, the activation value is 0; when the activation layer weight x belongs to the interval [0, Q) and the probability of random parameter clipping is q, the activation value is x; when the activation layer weight x belongs to the interval [α, +∞) and the probability of random parameter clipping is 1-pq, the activation value is α.
8. The neural network quantization compression method based on the bit allocation operator according to claim 2, characterized in that: The method also includes step 6): using the hardware device Raspberry Pi 4B to deploy the compressed YOLO network model; after the server-side training is completed, converting the weight parameter file of the YOLO model integrated with the bit allocation operator into the ONNX format; at the same time, pre-installing the onnxruntime inference engine in the Raspberry Pi 4B, and importing the prepared ONNX format weight parameter file into the Raspberry Pi 4B for inference, verifying the effectiveness of the method.
9. The neural network quantization compression method based on the bit allocation operator according to claim 2, characterized in that: The neural network quantization compression method based on the bit allocation operator is applied to the convolution layer and the activation layer.
