A cross-range quantized convolutional neural network compression method

Through cross-range quantization and differentiable quantization functions, the information loss and non-differentiability problems caused by truncation operations in existing quantization methods are solved, and the accuracy and training effect of convolutional neural networks are improved.

CN114970853BActive Publication Date: 2024-09-06SOUTH CHINA UNIV OF TECH +1
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210260332.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-16
Publication Date
2024-09-06
Estimated Expiration
2042-03-16

AI Technical Summary

Technical Problem

Existing quantization methods use truncation operations on values ​​outside the quantization threshold, resulting in information loss and non-differentiability, which limits the performance and training effect of convolutional neural networks.

Method used

The cross-range quantization method is used to quantize the weights and activation values ​​of the convolutional neural network across the range, and the quantization function is made differentiable through learnable step sizes and gradient approximations, retaining information outside the quantization threshold range.

Benefits of technology

On the basis of increasing a small amount of calculation, the classification accuracy of the convolutional neural network is significantly improved, and the training convergence and performance of the model are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114970853B
    Figure CN114970853B
Patent Text Reader

Abstract

The present invention discloses a cross-range quantized convolutional neural network compression method, comprising the following steps: determining the quantization bit of the quantized convolutional neural network and the quantization range under the quantization bit, as well as a quantization function based on step size quantization; training a full-precision convolutional neural network, and using the full-precision convolutional neural network to initialize the quantized convolutional neural network and the quantization step size; in the forward propagation stage, quantizing the weight parameters and activation values ​​of the convolutional neural network, and adopting a conventional quantization method for values ​​within the quantization threshold range; for values ​​outside the quantization threshold range, first subtracting the quantization threshold, and then performing conventional quantization; in the back propagation stage, using gradient approximation to make the non-differentiable quantization function differentiable. Based on conventional quantization, the present invention adopts different quantization methods for values ​​outside the quantization range, and realizes compression and acceleration of the convolutional neural network while retaining the image recognition accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of image recognition and relates to a cross-range quantized convolutional neural network compression method. Background Art

[0002] In recent years, deep convolutional neural networks have developed rapidly and achieved superior performance in a variety of tasks, such as image recognition and target detection. More and more smart devices have deployed deep convolutional neural networks. However, the fact that deep convolutional neural networks require a large amount of memory and computing resources limits their deployment and application. To this end, researchers have begun to study convolutional neural network compression technology to make the bloated deep convolutional neural network lightweight while ensuring the performance of the deep convolutional neural network.

[0003] At present, there are four main convolutional neural network compression methods based on image recognition tasks, namely low-rank decomposition, pruning, knowledge distillation and quantization.

[0004] (1) Low-rank decomposition

[0005] Generally speaking, if a matrix contains a lot of redundant information, it can be considered that the matrix is ​​not full rank. Therefore, the matrix can be decomposed into multiple small matrices with fewer parameters, lower rank, and simpler form, and the original matrix can be reconstructed through operations such as the outer product of multiple small matrices, thereby achieving the purpose of reducing memory and accelerating calculations. Generally speaking, the low-rank decomposition method aims to minimize the reconstruction error while ensuring the performance of the convolutional neural network.

[0006] (2) Pruning

[0007] Pruning methods are generally used to compress pre-trained convolutional neural networks. The larger and deeper a convolutional neural network is, the more likely it is to have redundant and invalid parameters. Pruning removes redundant and invalid parameters so that they do not participate in the convolutional neural network reasoning, thereby achieving the purpose of compressing the convolutional neural network. Pruning is generally divided into unstructured pruning and structured pruning. Unstructured pruning generally resets some smaller weights to zero. Although the performance of the model is largely retained after pruning, it is difficult to achieve this compression effect in hardware. Structured pruning generally prunes modules such as convolution kernels, which is more friendly to hardware deployment and implementation, and is therefore the main research direction in the field of pruning.

[0008] (3) Knowledge Distillation

[0009] Knowledge distillation is to transfer the "knowledge" of a deeper, more complex or better-performing large convolutional neural network to a relatively simple small convolutional neural network to improve the performance of the small convolutional neural network. Eventually, the small convolutional neural network can be used to replace the large convolutional neural network for actual deep learning tasks, thereby saving memory and accelerating computing. There are generally two ways to do knowledge distillation. One is to let the final output of the small convolutional neural network imitate the final output of the large convolutional neural network, and the other is to let the intermediate output of the small convolutional neural network imitate the intermediate output of the large convolutional neural network. The two methods can be used independently or together.

[0010] (4) Quantification

[0011] Quantization generally means that the weight parameters and even activation values ​​of a convolutional neural network are represented by a lower-bit value, which can greatly reduce memory usage and speed up calculations. From the perspective of quantization bits, quantization can be divided into binary quantization and multi-bit quantization. The compression efficiency and computational efficiency of binary quantization are very high, but the performance loss of convolutional neural networks cannot be underestimated. Multi-bit quantization can bring less performance loss while ensuring a certain compression efficiency and computational efficiency.

[0012] Current multi-bit quantization methods generally use learnable quantization functions. Some of the learnable quantization function methods use the floating-point quantization range of different convolutional layers or fully connected layers as a learnable parameter, such as DSQ (Ruihao Gong, Xianglong Liu, Shenghu Jiang, Tianxiang Li, Peng Hu, Jiazhen Lin, Fengwei Yu, and Junjie Yan. Differentiable soft quantization: Bridging full-precision and low-bit neural networks. In ICCV, 2019. 2, 4, 5) explicitly makes the left and right thresholds of the floating-point range involved in quantization of each convolutional layer learnable; LSQ (Steven K Esser, Jeffrey L McKinstry, Deepika Bablani, Rathinakumar Appuswamy, and Dharmendra S Modha. Learned stepsize quantization. In ICLR, 2020.2, 3, 4, 5, 6, 8) uses the quantization step size as a learnable parameter, indirectly making the range of floating-point numbers involved in quantization learnable.

[0013] Quantization methods such as LSQ and DSQ will truncate values ​​outside the quantization range. Although the number of values ​​outside the quantization range is small, these values ​​are often important. Truncating these values ​​to the quantization threshold will cause certain information loss, and the truncation operation is not differentiable. These two reasons affect the normal training of low-bit quantized convolutional neural networks and cause certain precision loss.

[0014] The lower the quantization bit, the more serious the decline in the classification accuracy of the corresponding quantized convolutional neural network. By cross-range quantization of the values ​​of the low-bit convolutional neural network that exceed the quantization range, although the actual amount of calculation will increase after cross-range quantization, since the proportion of this part of the value is small, compared with the conventional quantization method, only a small amount of calculation is added, which can effectively improve the classification accuracy.

[0015] The above four methods can achieve the compression effect of convolutional neural network from different angles, but quantization often has a greater compression rate and computational acceleration effect. Since most of the current quantization methods use truncated quantization functions, that is, the values ​​exceeding the quantization threshold range are uniformly truncated to the quantization threshold. Although this part of the larger values ​​occupies a smaller proportion of the overall parameters, they are often more important, and truncating all these values ​​will bring certain information loss, thus affecting the performance of the convolutional neural network. At the same time, the truncation operation is not differentiable, which further limits the training and updating of the parameters of the quantized convolutional neural network. Therefore, if the information of the values ​​outside the quantization threshold range can be retained, the performance of the quantized convolutional neural network can be effectively improved. Summary of the invention

[0016] In view of the deficiency of existing quantization methods that simply truncate values ​​outside the quantization threshold, the present invention provides a cross-range quantization convolutional neural network compression method. In image recognition tasks, only a small amount of calculation is added to the conventional quantization method, which can bring a higher classification accuracy improvement on the basis of the conventional quantization method.

[0017] The present invention is achieved by at least one of the following technical solutions.

[0018] A cross-range quantized convolutional neural network compression method comprises the following steps:

[0019] Preprocessing the original image to obtain a preprocessed image;

[0020] Quantize and train the weights and activation values ​​of convolutional neural networks across a range to build low-bit quantized convolutional neural networks;

[0021] Use the quantized convolutional neural network to perform image recognition on the preprocessed images.

[0022] Furthermore, the weight quantization process of the convolutional neural network includes:

[0023] ① In the initialization stage of the quantized convolutional neural network, the weight parameters of the quantized convolutional neural network are initialized with the weight parameters of the full-precision convolutional neural network, and the statistical information of the weights and activation values ​​of the full-precision convolutional neural network is calculated at the same time, and then the quantization step size of the weights and activation values ​​of the quantized convolutional neural network is initialized with the statistical information and the set quantization bits;

[0024] ② During the forward propagation phase of the training process, weights and activation values ​​are quantized across ranges;

[0025] ③. In the back propagation phase of the training process, the cross entropy loss function is derived and the quantized convolutional neural network parameters are updated.

[0026] Furthermore, the initialization of the quantization step size sw of each layer weight W of the quantized convolutional neural network is calculated by the set quantization bits and the distribution of the full-precision convolutional neural network weight parameters.

[0027] Furthermore, the full-precision model is used to classify and identify samples, and the distribution information of the activation values ​​of each layer is recorded. The quantization step sA of the activation value A of each layer of the quantized convolutional neural network is calculated by the set quantization bits and the distribution of the activation value of the full-precision convolutional neural network.

[0028] Furthermore, for the set quantization bits, the quantization range thresholds QW and QA of the weight W and activation value A of each layer of the quantized convolutional neural network are both fixed values.

[0029] Furthermore, the quantization function includes a Round operation, that is, for an input floating point number x, an integer value corresponding to rounding the floating point number x is obtained; the Round operation converts the original floating point number into a low-bit integer.

[0030] Furthermore, for the original floating-point input, it is first divided by the quantization step size for scaling. If the scaled value is within the quantization threshold range, the Round operation is used to obtain the quantized output; if the scaled value exceeds the quantization threshold range, the quantization threshold is first subtracted, and then the value after subtracting the quantization threshold is subjected to the Round operation to obtain the quantized output. If the quantized output at this time still exceeds the quantization threshold, it is truncated to the quantization threshold; when performing convolution calculations, values ​​outside the quantization threshold range are represented as the quantization threshold plus the quantization value after subtracting the quantization threshold.

[0031] Furthermore, the Round operation in the quantization function is not differentiable. During the back-propagation phase of the training process, the gradient of the quantization function is approximated to make it differentiable.

[0032] Furthermore, in the back-propagation phase, the gradient of the quantization step size parameter is reduced to ensure that the training of the quantized convolutional neural network can converge.

[0033] Furthermore, the reduction coefficient of the weight quantization step gradient of each convolutional layer is related to the set quantization bits and the number of layer weight parameters; the reduction coefficient of the activation value quantization step gradient of each convolutional layer is related to the set quantization bits and the number of activation value parameters.

[0034] Compared with the prior art, the present invention has the following beneficial effects:

[0035] The present invention can compress and accelerate commonly used convolutional neural networks, realize the lightweight of convolutional neural networks, and promote the application of image recognition algorithms on lightweight devices. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 The present invention provides a cross-range quantized convolutional neural network compression method and system implementation process;

[0037] Figure 2 The present invention is an implementation process of the cross-range weight two-bit quantization;

[0038] Figure 3 The present invention is an implementation process of two-bit quantization of cross-range activation values;

[0039] Figure 4 The figure is a process of image recognition in one embodiment of the present invention. DETAILED DESCRIPTION

[0040] The present invention is further described in detail below through specific implementation modes, but the implementation modes of the present invention are not limited thereto.

[0041] Principle of the present invention: Quantizing the weights and activation values ​​of a convolutional neural network can greatly reduce the memory and computational complexity of the convolutional neural network. Most of the existing low-bit quantization methods take a truncation operation on values ​​that exceed the quantization threshold, that is, values ​​that exceed the quantization threshold Q will be truncated to Q. This operation causes information loss in this part of the value, and the truncation operation is not differentiable, which further limits the training and updating of the convolutional neural network. The above two reasons explain that the truncation operation of conventional quantization will affect the performance of the quantized convolutional neural network. The present invention proposes a cross-range quantization compression method and system thereof, which retains the information of values ​​that exceed the quantization range threshold Q. In theory, compared with the original quantization method, only a small amount of calculation is added to obtain a significant performance improvement.

[0042] Example 1

[0043] like Figure 1 , Figure 4As shown, a cross-range quantized convolutional neural network compression method includes the following steps:

[0044] S1. Perform preprocessing such as zero padding, random cropping, random flipping and normalization on the original image to obtain a preprocessed image.

[0045] S2, quantize and train the weights and activation values ​​of the convolutional neural network to construct a low-bit quantized convolutional neural network;

[0046] Specifically, the steps include:

[0047] ①. Use the preprocessed images to train a full-precision convolutional neural network as a pre-training model (including but not limited to common convolutional neural networks such as ResNet and MobileNet);

[0048] ②. Set the quantization bits and calculate the quantization thresholds of weights and activation values.

[0049] Assume that the quantization bit is b bits. The basic structure of the convolutional neural network is: convolution layer → batch normalization layer → ReLU activation function. Since the ReLU function generally truncates the value less than zero to zero, the quantization thresholds of the weight and activation value are different. Assume and are the left and right boundaries of the weight quantization range, respectively.

[0050]

[0051]

[0052] set up and are the left and right boundaries of the activation value quantization range, respectively.

[0053]

[0054]

[0055] ③. Use the weight parameters of the full-precision convolutional neural network to initialize the weight parameters of the quantized convolutional neural network;

[0056] ④. Calculate the statistical information of the weights and activation values ​​of the full-precision convolutional neural network, and then use the statistical information and the pre-set quantization bits to initialize the quantization step size of the quantized convolutional neural network weights and activation values.

[0057] Let the weight of the current convolutional layer be the matrix in Indicates K row Cd 2The matrix of columns, C is the number of input channels, K is the number of convolution kernels, and d is the size of the convolution kernel. The quantization step size s of the current layer weight W Initialized to:

[0058]

[0059] Among them, ||W||1 is the L1 norm of weight W.

[0060] ⑤. Use the full-precision convolutional neural network to classify and identify a certain number of samples (such as 128), record the activation value of each layer during the inference process, and quantize the quantization step sA of each layer of the activation value A of the convolutional neural network. The quantization bit is set in advance, and the mean of the L1 norm of the activation value currently recorded by the full-precision convolutional neural network is jointly determined. Use the statistical information of the activation value of the pre-trained full-precision convolutional neural network and the activation value quantization threshold to initialize the quantization step of the current layer activation value.

[0061] Let the current layer input activation value be the matrix in Represents a matrix with B rows and CHW columns, where B is the number of input samples (e.g. 128), C is the number of input channels, H and W are the length and width of the input feature map, and the quantization step size s of the current layer activation value A Initialized to:

[0062]

[0063] Here, ||A||1 is the L1 norm of the activation value A.

[0064] ⑥ In the forward propagation stage, the weight W is uniformly quantized based on the learnable step size, where w i The i-th element of the weight W is the floating point number w i For floating point numbers w i , first divided by the weight quantization step s w , use the Round function to convert it into an integer, where cross-range quantization is used for values ​​exceeding the quantization threshold, that is, the quantization threshold is first subtracted, and then the value after subtracting the quantization threshold is subjected to the Round operation to obtain the quantized output. If the quantized output at this time still exceeds the quantization threshold, it is truncated to the quantization threshold. is a quantized integer, is the final quantized output, such as Figure 2 As shown, the specific formula is as follows:

[0065]

[0066]

[0067] ⑦. In the forward propagation stage, the activation value A is uniformly quantized based on the learnable step size, where a i Represents the i-th element of the activation value A. For a floating point number a i , first divided by the activation value quantization step s A , use the Round operation to convert it into an integer, where cross-range quantization is used for values ​​exceeding the quantization threshold, that is, the quantization threshold is first subtracted, and then the value after subtracting the quantization threshold is subjected to the Round operation to obtain the quantized output. If the quantized output at this time still exceeds the quantization threshold, it is truncated to the quantization threshold. is a quantized integer, is the final quantized output, such as Figure 3 As shown, the specific formula is as follows:

[0068]

[0069]

[0070] ⑧. In the back-propagation stage, the gradient of the quantization step parameter needs to be reduced to ensure that the training of the quantized convolutional neural network can converge.

[0071] The Round operation in the quantization function is not differentiable. Here, the gradient of the Round operation is approximated based on the Straight Through Estimation (STE) method. Assuming the input is x, the specific formula is as follows:

[0072]

[0073] ⑨. In the derivation process, since the weights of each convolutional layer share a quantization step size, and the number of weight parameters is several orders of magnitude higher than the number of their corresponding quantization steps, this results in the gradient amplitude of the quantization step size being larger than that of a single weight parameter w after derivation by the chain rule. i The gradient amplitude is several orders of magnitude higher, and the same is true for the activation value. The extreme imbalance in the parameter gradient size is not conducive to the training and convergence of the quantized convolutional neural network, so the gradient of the quantization step size needs to be reduced. The reduction coefficient of the quantization step size gradient is related to the pre-set quantization bits and the number of weight parameters or activation values ​​of the layer.

[0074] The weight matrix for the convolutional layer Among them, C is the number of input channels, K is the number of convolution kernels, d is the size of the convolution kernel, and its corresponding quantization step gradient reduction coefficient g w for:

[0075]

[0076] For the input activation matrix of the convolutional layer Among them, B is the number of input samples (such as 128), C is the number of input channels, H and W are the input feature map sizes. The corresponding quantization step size gradient reduction coefficient g A It has nothing to do with the number of input samples and is:

[0077]

[0078] ⑩. Use cross entropy as the loss function and stochastic gradient descent as the optimizer to update the quantized convolutional neural network.

[0079] As a preferred embodiment, the parameters of the first convolution layer and the last fully connected layer of the quantized convolutional neural network, and the batch normalization layer are not quantized; the original input of the quantized convolutional neural network is also not quantized.

[0080] As a preferred embodiment, the quantization function often includes a Round operation, that is, for the input floating point number x, the integer value corresponding to the rounding of x is calculated. For the value x to be quantized, if x is within the range of the quantization threshold Q, conventional quantization is used and the quantized output Round(x) is obtained; if x exceeds the range of the quantization threshold Q, the quantization threshold Q is first subtracted, and then conventional quantization is performed, and the quantized output is expressed as Q+Round(xQ).

[0081] S3. Use the quantized convolutional neural network to perform image recognition on the preprocessed images.

[0082] The method of the present invention is experimentally verified based on convolutional neural networks ResNet20 and ResNet32.

[0083] Example 2

[0084] This embodiment conducts experiments on the convolutional neural network ResNet20 on the commonly used dataset CIFAR-10, and performs two-bit and three-bit quantization on ResNet20 respectively. The experimental comparison results are shown in Table 1, and LSQ comes from Reference 1 (see: Steven K Esser, Jeffrey L McKinstry, Deepika Bablani, Rathi-nakumar Appuswamy, and Dharmendra S Modha. Learned step size quantization. International Conference on Learning Representations (ICLR), 2020.).

[0085] In the table, all methods use the same training settings. They are all initialized with the same full-precision ResNet20 convolutional neural network. For quantized convolutional neural network training, gradient descent training is performed using a stochastic gradient descent optimizer with momentum = 0.9, an initial learning rate of lr = 0.01, 400 epochs of training, a cosine learning rate that eventually decays to zero, weight decay weight_decay = 1e-4, and a sample batch size of batch size = 128.

[0086] Table 1 Comparison results with LSQ two-bit quantization

[0087]

[0088] Table 2 Comparison results with LSQ three-bit quantization

[0089]

[0090] It can be seen from Table 1 and Table 2 that the cross-range quantization method of the present invention can effectively improve the accuracy of the convolutional neural network of ResNet20, wherein the accuracy of the method of the present invention is improved by more than 1% on two-bit quantization. Moreover, cross-range quantization of the activation value alone can effectively improve the quantization accuracy. After cross-range quantization of the weights and activation values ​​at the same time, the accuracy improvement effect is more obvious. It can be seen from the results in the rightmost column of Table 1 and Table 2 that compared with the method of directly increasing the quantization bits, the increased computational effort of the cross-range quantization unit can bring more accuracy increases.

[0091] Example 3

[0092] This embodiment conducts experiments on the convolutional neural network ResNet32 on the commonly used data set CIFAR-100, and performs two-bit quantization on ResNet32. The experimental results are shown in Table 3. The parameter settings of Example 2 are the same as those of Example 1.

[0093] Table 3 Comparison results with LSQ two-bit quantization

[0094]

[0095]

[0096] It can be seen from Table 3 that the cross-range quantization method of the present invention improves the accuracy of the convolutional neural network of ResNet32 by 1.54% on two-bit quantization, and the effect is obvious.

[0097] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.

Claims

1. A cross-range quantized convolutional neural network compression method, characterized in that: The following steps are involved: Preprocessing the original image to obtain a preprocessed image; Quantize and train the weights and activation values ​​of convolutional neural networks across a range to build low-bit quantized convolutional neural networks; The weight quantization process of convolutional neural network includes: ① In the initialization stage of the quantized convolutional neural network, the weight parameters of the quantized convolutional neural network are initialized with the weight parameters of the full-precision convolutional neural network, and the statistical information of the weights and activation values ​​of the full-precision convolutional neural network is calculated at the same time, and then the quantization step size of the weights and activation values ​​of the quantized convolutional neural network is initialized with the statistical information and the set quantization bits; ② During the forward propagation phase of the training process, weights and activation values ​​are quantized across ranges; ③. In the back propagation phase of the training process, the cross entropy loss function is derived and the quantized convolutional neural network parameters are updated; The quantization function includes a Round operation, that is, for an input floating point number x, the integer value corresponding to the rounding of the floating point number x is calculated; the Round operation converts the original floating point number into a low-bit integer; For the original floating-point input, first divide it by the quantization step size to scale it. If the scaled value is within the quantization threshold range, use the Round operation to get the quantized output. If the scaled value exceeds the quantization threshold range, first subtract the quantization threshold, and then use the Round operation to get the quantized output after subtracting the quantization threshold. If the quantized output still exceeds the quantization threshold at this time, it is truncated to the quantization threshold. Use the quantized convolutional neural network to perform image recognition on the preprocessed images.

2. The cross-range quantized convolutional neural network compression method according to claim 1, characterized in that: Quantize the quantization step size s of each layer weight W of the convolutional neural network w The initialization of is calculated by the set quantization bits and the distribution of the full-precision convolutional neural network weight parameters.

3. The cross-range quantized convolutional neural network compression method according to claim 1, characterized in that: Use the full-precision model to classify and identify samples, record the distribution information of the activation values ​​of each layer, and quantize the quantization step size s of the activation value A of each layer of the convolutional neural network. A It is calculated by the set quantization bits and the distribution of activation values ​​of the full-precision convolutional neural network.

4. The cross-range quantized convolutional neural network compression method according to claim 1, characterized in that: For the set quantization bits, the quantization range threshold Q of the weight W and activation value A of each layer of the quantized convolutional neural network is quantized W and Q A All are fixed values.

5. The cross-range quantized convolutional neural network compression method according to claim 1, characterized in that: The Round operation in the quantization function is not differentiable. During the back-propagation phase of the training process, the gradient of the quantization function is approximated to make it differentiable.

6. The cross-range quantized convolutional neural network compression method according to claim 1, characterized in that: In the back-propagation phase, the gradient of the quantization step size parameter is reduced to ensure that the training of the quantized convolutional neural network can converge.

7. The cross-range quantized convolutional neural network compression method according to claim 5, characterized in that: The reduction coefficient of the weight quantization step gradient of each convolution layer is related to the set quantization bits and the number of weight parameters; the reduction coefficient of the activation value quantization step gradient of each convolution layer is related to the set quantization bits and the number of activation value parameters.

Citation Information

Patent Citations

  • Convolutional neural network low bit width quantization method based on weight distribution

    CN110222821A

  • Lightweight convolutional neural network image recognition method based on low rank and sparse decomposition

    CN111079781A

  • Neural network model compression method and device based on evolutionary algorithm

    CN111898750A

  • Joint pruning and quantization scheme for deep neural networks

    US20210089922A1