Unconstrained post-training quantization image classification method
Through the unconstrained post-training quantization method, based on the activation distribution optimization quantization range and the introduction of lookup table matrix multiplication, the calculation and memory problems of the Transformer model in edge device deployment are solved, significantly improving the accuracy and efficiency of image classification.
Patent Information
- Application Number
- CN202411283186.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2025-01-03
AI Technical Summary
When deploying on resource-constrained edge devices, the existing Transformer image classification model has high computing requirements, large memory usage, long inference delays, and large quantization errors, especially in softmax and nonlinear activation layers.
An unconstrained post-training quantization method is proposed. Through the quantization optimization problem based on the activation distribution, the quantization range is dynamically adjusted, uniform quantization and search table matrix multiplication are adopted to reduce quantization errors, and an efficient scale offset algorithm is introduced to reduce distribution offsets .
More flexible quantization is achieved on the Transformer model, reducing quantization errors, improving image classification accuracy and efficiency, and significantly improving the performance of the model under low parameters.
Smart Images

Figure CN119251555A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image classification, and more specifically, relates to an unconstrained post-training quantized image classification method. Background Art
[0002] Transformer-based models are increasingly being used in various visual fields, especially in image classification. However, these successes are accompanied by huge computational requirements, resulting in large amounts of memory usage, high power consumption, and increased inference latency. As a result, it becomes very challenging to deploy these image classification Transformer models on resource-constrained edge devices, limiting their practical applications. To address these efficiency bottlenecks, model compression techniques have been widely studied, including distillation, pruning, and quantization. Among these techniques, model quantization shows significant advantages, especially in practical scenarios where low-cost deployment and real-time inference are critical.
[0003] Model quantization compresses the weights and runtime activation function outputs into a low-bit format representation. Post-training quantization (PTQ) is one of the most popular quantization methods in image classification. It only requires a small number of unlabeled samples to calibrate the quantization parameters without retraining the model. Two commonly used PTQ quantizers are uniform quantizer and log2 quantizer, both of which can achieve efficient inference through a simple quantization process. Uniform quantizers require equal quantization ranges, while log2 quantizers require quantization ranges to satisfy a doubling relationship. These quantization range restrictions impose certain constraints on quantization. Although the weights of most Transformer models can be effectively quantized and maintain low quantization errors, the model activations cannot maintain accuracy due to high variance. Especially in softmax and nonlinear activation layers, these distributions are critical to the accuracy of the model's image classification. Therefore, it is necessary to remove these constraints and develop more flexible and powerful quantizers. This allows image classification Transformer models to achieve better classification results while using fewer parameters. Summary of the invention
[0004] The purpose of the present invention is to overcome the deficiencies of the prior art and provide an unconstrained post-training quantization image classification method that allows flexible quantization based on activation distribution without being restricted to a fixed quantization range, thereby improving the performance of the image classification model after quantization compression.
[0005] In order to achieve the above-mentioned object of the invention, the unconstrained post-training quantized image classification method of the present invention comprises the following steps:
[0006] S1: For the trained image classification Transformer model, determine the number of network layers N that need to be quantized in the image classification model according to the actual situation, and record the number of channels of the input feature map of the i-th network layer to be quantized as D i , the feature vector to be quantized is The feature to be quantified is x i,j , i=1,2,…,N, j=1,2,…,D i , the weight vector to be quantized is The weight to be quantized is w i,j ;
[0007] S2: Use uniform quantization to obtain the quantized value A of each network layer weight g and quantization boundary B g , g = 1, 2, ..., G, G represents the number of quantization intervals of weights;
[0008] S3: Obtain several actual sample images, input them into the trained image classification Transformer model, and then solve the following quantization optimization problem to obtain the quantization value and quantization boundary of the features to be quantized in each network layer to be quantized;
[0009]
[0010] Among them, σ 2 represents the quantization error, x represents the parameter to be quantized, represents the inverse quantized value of the parameter x to be quantized, p(x) represents the probability of occurrence of the parameter x to be quantized, K represents the number of quantization intervals of the parameter, and a k 、b k Respectively represent the quantization value and quantization boundary of the kth quantization interval, k = 1, 2, ..., K;
[0011] S4: Input the image to be classified into the image classification Transformer model. When the network layer is a quantized network layer, quantize its input feature map and weight to integer values according to the corresponding quantization value and quantization boundary to obtain the quantized input feature map. and quantized weights Then quantize the input feature map Dequantize to get the dequantized input feature map Then solve for Output as the output feature map to complete the image classification.
[0012] The unconstrained post-training quantization image classification method of the present invention determines the network layer to be quantized according to actual needs for the trained image classification Transformer model, determines the features to be quantized and the weights to be quantized, firstly adopts uniform quantization to solve and obtain the quantization value and quantization boundary of the weight of each network layer, then obtains several actual sample images in the calibration stage and inputs them into the trained image classification Transformer model to obtain each feature value to be quantized of each sample image, then solves the quantization optimization problem to obtain the quantization value and quantization boundary of the features to be quantized of each network layer to be quantized, and finally inputs the image to be classified into the image classification Transformer model in the inference stage to quantize the features to be quantized and the weights to complete the image classification.
[0013] The present invention has the following beneficial effects:
[0014] 1) The present invention proposes an unconstrained post-training quantization image classification method, designs a quantization optimization problem, and adopts a variable quantization range based on activation distribution characteristics, which can reduce errors by iteratively optimizing the quantization range;
[0015] 2) The present invention proposes a method for performing matrix multiplication using a lookup table to accelerate quantization matrix multiplication in an unconstrained post-training quantization method;
[0016] 3) Extensive experiments on various Transformer networks and image classification tasks demonstrate the flexibility and effectiveness of the proposed method. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a structural diagram of the image classification Transformer model in this embodiment;
[0018] Figure 2 is a uniform quantizer and a log2 quantizer pair Figure 1 An example diagram of data quantization for the image classification Transformer model shown;
[0019] Figure 3 This is a performance comparison chart of the Transformer model when different activation parts are not quantized;
[0020] Figure 4 It is a flowchart of a specific implementation of the unconstrained post-training quantized image classification method of the present invention;
[0021] Figure 5 is a flow chart of solving the quantization value and quantization boundary in this embodiment;
[0022] Figure 6 In this embodiment, the present invention Figure 1An example diagram of data quantization for the image classification Transformer model shown;
[0023] Figure 7 It is a visualization diagram of the benefits brought by the present invention in this embodiment. DETAILED DESCRIPTION
[0024] The specific implementation of the present invention is described below in conjunction with the accompanying drawings so that those skilled in the art can better understand the present invention. It should be noted that in the following description, when the detailed description of known functions and designs may dilute the main content of the present invention, these descriptions will be omitted here.
[0025] In order to better illustrate the technical solution of the present invention, the existing quantizer is first briefly described.
[0026] The formula for the uniform quantizer is as follows:
[0027]
[0028] Among them, x and x q Represents the floating point value and quantized integer value of the parameter in the image classification model, respectively. represents the floor function, and b represents the quantization bit width. represents the quantitative scale, denote the quantized zeros, which are calculated according to the following formula:
[0029]
[0030] The formula for the log2 quantizer is:
[0031]
[0032] The log2 quantizer usually starts at zero, so the zero point is omitted. During the quantization process, integer multiplication and base 2 power operations can be efficiently implemented using integer and bit shift operations. In order to find the optimal quantization parameters z and s among these quantizers, the optimization goal is:
[0033]
[0034] in, Represents the inverse quantized value, that is, the quantized integer value x q The floating-point number obtained by the transformation.
[0035] This means that the quantization error is bounded by the quantizer, specifically by the scale s and the zero point z. In these quantizers, only the scale s and the zero point z are optimized, not the parameter values and the quantization boundaries. While this simplifies the quantization process and works well in the case of Gaussian distributions, it fails when quantizing nonlinearities and long-tailed activations. Figure 1 It is a structural diagram of the image classification Transformer model in this embodiment. Figure 2 is a uniform quantizer and a log2 quantizer pair Figure 1 The data quantization example diagram of the image classification Transformer model is shown in Figure 1. Figure 2 As shown, the quantization errors of the uniform quantizer and log2 quantizer reach 0.20 and 0.22 respectively, which are almost twice that of the Gaussian distribution case.
[0036] According to the rate-distortion theory, when the number of quantization bits is fixed, further restrictions on the quantization form will lead to an increase in the lower limit of the quantization error. In uniform quantization, it is assumed that the parameter value a to be quantized is obtained. k and quantization interval s, then a k′ =a k +s(k′-k) is certain. However, a k and a k′ can be any value and is not restricted by the quantization interval. This will lead to a trade-off between truncation error and rounding error. Figure 2 As shown in Figure 2, in post-GELU activation, a large quantization interval s reduces truncation error but introduces more rounding error. On the contrary, a small s reduces rounding error but introduces more truncation error. The log2 quantizer also has a similar problem.
[0037] Furthermore, further experiments have shown that activation quantization with large amounts of errors seriously affects the accuracy of model image classification. Figure 3 This is a performance comparison chart of the Transformer model when different activation parts are not quantized. Figure 3 As shown in Figure 1, the unquantized parts are retained in the activations of different modules and compared with the fully quantized baseline for image classification accuracy. The results reveal an important finding: the full-precision post-GELU activation brings the most significant accuracy improvement, an improvement of 7.14% on ViT. The full-precision post-Softmax activation also brings a significant accuracy improvement, an improvement of 1.9%. In contrast, other activations with smaller quantization errors do not bring significant improvements.
[0038] Therefore, it is crucial to quantize these nonlinear and long-tail activations with a small quantization error. Since the existing quantizers limit the quantization interval, such activations cannot be effectively quantized. To address this problem, the present invention designs an unconstrained quantizer that can adaptively adjust the quantization interval according to the density estimation of the activation distribution, and then proposes an unconstrained post-training quantization image classification method.
[0039] Figure 4 It is a flowchart of a specific implementation of the unconstrained post-training quantized image classification method of the present invention.
[0040] like Figure 4 As shown, the specific steps of the unconstrained post-training quantization image classification method of the present invention include:
[0041] S401: Determine the parameters to be quantified:
[0042] For the trained Transformer-based image classification model, determine the number of network layers N that need to be quantized in the image classification model according to the actual situation, and denote the number of channels of the input features of the i-th network layer as D i The features that need to be quantified are The feature to be quantified is x i,j , i=1,2,…,N, j=1,2,…,D i , the weight vector to be quantized is The weight to be quantized is w i,j .
[0043] S402: Solve the quantization value and quantization boundary of each layer weight:
[0044] Use uniform quantization to solve the quantized value A of each network layer weight g and quantization boundary B g , g = 1, 2,…, G, G represents the number of quantization intervals of the weight.
[0045] S403: Solve the quantization value and quantization boundary of each layer feature:
[0046] Obtain several actual sample images, input them into the trained image classification Transformer model, and then solve the quantization optimization problem to obtain the quantization value and quantization boundary of the features to be quantized in each layer of the network layer to be quantized. The quantization optimization problem proposed in the present invention is expressed as follows:
[0047]
[0048] Among them, σ 2 represents the quantization error, x represents the parameter to be quantized, represents the inverse quantized value of the parameter x to be quantized, p(x) represents the probability of occurrence of the parameter x to be quantized, K represents the number of quantization intervals of the parameter, and a k 、b k They respectively represent the quantization value and quantization boundary of the kth quantization interval, k = 1, 2,…, K.
[0049] In this embodiment, the Lloyd-Max algorithm is used to solve the above optimization problem to obtain the quantized value and quantized boundary of the weight. First, the quantized value a is calculated using the following formula: k The partial derivative of :
[0050]
[0051] Setting it to zero gives:
[0052]
[0053] This shows that the quantized value of each decision interval is the centroid of the probability mass of that interval. Similarly, considering the quantized boundary b k The partial derivative of :
[0054]
[0055] Setting it to zero gives:
[0056]
[0057] This shows that the decision boundary is just the midpoint of adjacent quantized values. k And update the quantization boundary b k , fixed quantization boundary b k And update the parameter value a k , and the iterative optimization can obtain a set of optimal quantization values {a k} and quantization boundary {b k}. Then the quantized value x can be obtained according to the following formula q and the dequantized value
[0058] x q =Q(x)=k,if x∈[b k-1 ,b k )
[0059]
[0060] Among them, b 0 =x min , x min Indicates the minimum value of the parameter x to be quantized.
[0061] Benefiting from the absence of quantization constraints, this method can adapt to those nonlinear activations with low quantization errors.
[0062] Based on the above principles, the specific method for solving the quantization value and the quantization boundary in this embodiment can be obtained. Figure 5 is a flow chart of solving the quantization value and quantization boundary in this embodiment. Figure 5 As shown, the specific steps of solving the parameter value and quantization boundary in this embodiment include:
[0063] S501: Initialize quantization value:
[0064] Determine the value range of the parameter value x to be quantized according to the actual situation [xmin ,x max ], and then initialize the quantization value a of each quantization interval k In this embodiment, the following formula is used to initialize the quantization value a k :
[0065]
[0066] S502: Calculate quantization boundary:
[0067] The quantization boundary b is calculated using the following formula: k :
[0068]
[0069] S503: Update quantization value:
[0070] Use the following formula to update the quantized value a k :
[0071]
[0072] S504: Calculate the inverse quantization value:
[0073] The following formula is used to calculate the inverse quantization value of each specific value of the quantized parameter x:
[0074]
[0075] S505: Calculate quantization error:
[0076] The quantization error σ corresponding to the current quantization value and the quantization boundary is calculated using the following formula: 2 :
[0077]
[0078] S506: Determine whether the iteration end condition is met, if yes, the solution ends, otherwise return to step S502. The iteration end condition can be set according to actual needs, such as reaching the maximum number of iterations, or the difference between two adjacent quantization errors is less than a preset threshold.
[0079] S404: Image classification:
[0080] The image to be classified is input into the image classification Transformer model. When the network layer is a quantized network layer, its input feature map and weight are quantized to integer values according to the corresponding quantization value and quantization boundary to obtain the quantized input feature map. and quantized weights Then quantize the input feature map Dequantize to get the dequantized input feature map Then solve for Output as the output feature map to complete the image classification.
[0081] In the image classification stage, the distribution at runtime may be different from that in the calibration stage, and this iterative optimization requires a long inference time. To solve this problem, the present invention proposes an efficient scale shift algorithm (ESA) to process the dequantized input feature map to dynamically align the model distribution and reduce the distribution shift between the calibration and image classification inference stages. To this end, the efficient scale shift algorithm proposed in this embodiment introduces two factors: the scale factor α i,scale and the offset factor α i,shift :
[0082]
[0083] Among them, || L1 It means to obtain the L1 norm.
[0084] The following formula is used to perform offset correction on the dequantized input feature map to obtain the dequantized input feature map after offset correction:
[0085]
[0086] Then dequantize the input feature map It can be multiplied by the quantization weight. i,scale and the offset factor α i,shift ,The distribution of the model in image classification inference is aligned to the distribution in the calibration phase, thereby reducing the quantization error. Although the efficient scale shift algorithm requires dynamic calculation at runtime, it only introduces negligible computation.
[0087] After introducing offset correction, the dequantized input feature map and quantized weights Matrix multiplication It can be expressed as:
[0088]
[0089] The offset factor α can be i,shift Expressed as a binary number, i.e. α i,shift =r / s t , where r and t are both positive integers. Then, This can be implemented efficiently using integer arithmetic and bit shift operations. i,scale This can be summarized as a pre-calculation that only needs to be calculated once and can be ignored. However, some existing hardware (such as GPU) does not support this multiplication operation. And if no offset correction is used, it is also necessary to calculate Therefore, in order to solve this efficiency problem, a lookup table matrix multiplication is proposed in this embodiment. The lookup table is an efficient operation supported by a hash table, which can effectively improve the computing efficiency.
[0090] According to the quantization optimization problem, the input feature map and weight in the present invention are quantized using K and G quantization intervals respectively. Then the dequantized input feature map is There are K values, quantizing the weights There are G values, so dequantize the input features and quantized weights There are K×G possible values of . Therefore, in this embodiment, a product result lookup table of size K×G is calculated in advance based on the K inverse quantization values of the input features and the G quantized integer values of the weights. When each dequantized input feature and quantized weights The value of is looked up in the product result lookup table to get the relative result, and then accumulated to get the matrix multiplication Obviously, when K and G are small, the space occupied by the product result lookup table is negligible, so that the image classification efficiency can be greatly improved in exchange for extremely low storage occupancy.
[0091] Figure 6 In this embodiment, the present invention Figure 1 An example of data quantization for the image classification Transformer model shown. Figure 6 and Figure 2 It can be seen that the present invention can effectively reduce the quantization error.
[0092] In order to better illustrate the technical effect of the present invention, a specific example is used to experimentally verify the present invention.
[0093] Example 1
[0094] The experimental conditions set in this embodiment are:
[0095] (1) Dataset selection: This example evaluates the image classification task on the ImageNet-1k dataset.
[0096] (2) Model selection: This example performs quantitative evaluation on a variety of Transformer-based image classification models, including ViT, DeiT, and Swin.
[0097] (3) Implementation details: All experiments are implemented in Pytorch. According to the mainstream quantization method, this embodiment quantizes all weights and activation function output values in matrix multiplication. This embodiment maintains layer normalization and softmax operations at full precision. This embodiment quantizes the activation function output values layer by layer and the weights channel by channel. For the visual Transformer model, all pre-training checkpoints are from the Timm library. This embodiment uses RepQ-ViT as the base model and applies the present invention in the operations after softmax and GELU activation. This embodiment randomly extracts 32 images from the training set as calibration samples. All experiments are performed on an Nvidia A6000 GPU.
[0098] Table 1 shows the accuracy of the classification task performed by the present invention on different models, and compares it with methods such as PTQ4ViT, APQ-ViT, and RepQ-ViT. When various models are compressed to one-fourth of their original size by different methods, the present invention maintains the highest classification accuracy.
[0099] method Full-Precision PTQ4ViT APQ-ViT RepQ-ViT The present invention Bits(WIA) 32 / 32 4 / 4 4 / 4 4 / 4 4 / 4 ViT-T 75.47 16.53 17.56 26.72 55.41 ViT-S 81.39 42.57 47.95 65.05 70.95 ViT-B 84.54 30.69 41.41 68.48 73.72 DeiT-T 72.21 36.96 47.94 57.43 62.57 DeiT-S 79.85 34.08 43.55 69.03 72.57 DeiT-B 81.80 64.39 67.48 75.61 78.02 Swin-T 81.37 73.06 - 72.37 73.80 Swin-S 83.23 76.09 77.15 79.45 80.65 Swin-B 85.27 74.02 76.48 80.74 81.84 Avg. 80.57 49.82 52.44 66.10 72.17
[0100] Table 1
[0101] As shown in Table 1, the present invention surpasses the existing state of the art on various Vision Transformer (ViT) backbone networks. Specifically, on the ViT-Tiny model, the present invention achieves an image classification accuracy of 55.41%, which is twice that of APQ-ViT. On the DeiT model, the present invention improves the image classification accuracy by 3.54% compared to RepQ-ViT. For hierarchical visual Transformer models like Swin-Base, the present invention achieves an image classification accuracy of 81.84%, which is only 3.42% behind the full-precision model. Overall, the present invention is on average 6.07% more accurate than the previous state-of-the-art technology, demonstrating its efficiency and flexibility.
[0102] Example 2
[0103] In order to verify the effectiveness and efficiency of the present invention, this embodiment verifies the additional memory usage of the lookup table, the visualization of quantization error and model performance, the calibration time and delay. Although the present invention requires a lookup table to pre-calculate multiplications, which results in additional memory usage, experiments have shown that these additional parameters are negligible. This embodiment compares the present invention with the mainstream constrained quantization image classification method in a 4-bit scenario. Table 2 is a comparison table of the inference calibration time of the image classification task in the ablation experiment of this embodiment.
[0104]
[0105] Table 2
[0106] The time cost in Table 2 is calculated in GPU minutes. As shown in Table 2, the lookup table used in the present invention only adds about 0.01MB of memory, which accounts for only 0.1% of the DeiT-S model. On the other hand, the present invention significantly improves the model performance, improving the classification accuracy by 4.30% on the DeiT-S-based model and 1.62% on the Swin-S-based model. In terms of calibration time during image classification, the present invention does not require reconstruction and avoids gradient calculation, making the calibration time shorter. Specifically, the calibration time of the present invention on Swin-S is 17.67% shorter than PTQ4ViT, and a better classification effect is achieved in a shorter time.
[0107] To demonstrate the impact of the present invention on quantization error and model performance, we visualized the comparison of model image classification accuracy before and after applying the present invention. The quantization error is calculated by averaging the post-Softmax and post-GELU quantization errors. Figure 7 This is a visualization diagram of the benefits brought by the present invention in this embodiment. Figure 7 As shown, the present invention almost halves the quantization error and significantly improves the accuracy of image classification, showing a clear and strong upper left trend. It is worth noting that similar trends are shown in all ViT backbone networks, highlighting the flexibility and effectiveness of the present invention.
[0108] In order to measure the real-time delay in the image classification task, this embodiment also conducted a comparative experiment between the present invention and the full-precision model. The experiment was conducted on an Nvidia A6000 GPU using pytorch.
[0109] Table 3 is a comparison table of delay times of the present invention and the full-precision model in this embodiment.
[0110] Method MM-LUT Size(MB) Latency(s) Full-Precision - 89.44 0.91 The present invention × 11.18 1.07 The present invention √ 11.19 0.47
[0111] Table 3
[0112] As shown in Table 3, due to hardware problems, the average delay of the present invention without using MM-LUT in image classification is 1.07s, which is even slower than the full-precision model. After using MM-LUT to accelerate quantization matrix multiplication, the delay of the present invention is 0.47s, which is 50% less than the full-precision model. It is worth noting that the use of sophisticated hardware (such as FPGA) can further improve the speed of image classification.
[0113] Although the above describes the illustrative specific embodiments of the present invention to facilitate those skilled in the art to understand the present invention, it should be clear that the present invention is not limited to the scope of the specific embodiments. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations using the concept of the present invention are protected.
Claims
1. An unconstrained post-training quantization image classification method, characterized in that: The following steps are involved: S1: For the trained image classification Transformer model, determine the number of network layers N that need to be quantized in the image classification model according to the actual situation, and record the number of channels of the input feature map of the i-th network layer to be quantized as D i , the feature vector to be quantized is The feature to be quantified is x i,j , i=1,2,…,N, j=1,2,…,D i , the weight vector to be quantized is The weight to be quantized is w i,j ; S2: Use uniform quantization to obtain the quantized value A of each network layer weight g and quantization boundary B g , g = 1, 2, ..., G, G represents the number of quantization intervals of weights; S3: Obtain several actual sample images, input them into the trained image classification Transformer model, and then solve the following quantization optimization problem to obtain the quantization value and quantization boundary of the features to be quantized in each network layer to be quantized; Among them, σ 2 represents the quantization error, x represents the parameter to be quantized, represents the inverse quantized value of the parameter x to be quantized, p(x) represents the probability of occurrence of the parameter x to be quantized, K represents the number of quantization intervals of the parameter, and a k 、b k Respectively represent the quantization value and quantization boundary of the kth quantization interval, k = 1, 2, ..., K; S4: Input the image to be classified into the image classification Transformer model. When the network layer is a quantized network layer, quantize its input feature map and weight to integer values according to the corresponding quantization value and quantization boundary to obtain the quantized input feature map. and quantized weight W i q , and then quantize the input feature map Dequantize to get the dequantized input feature map Then solve for Output as the output feature map to complete the image classification.
2. The post-training quantized image classification method according to claim 1, characterized in that: The method for solving the quantitative optimization problem in step S3 is as follows: S2.1: Determine the value range of the parameter value x to be quantized according to the actual situation [x min ,x max ], and then initialize the quantization value a of each quantization interval k ; S2.2: The quantization boundary b is calculated using the following formula k : S2.3: Update the quantized value a using the following formula k : S2.4: Calculate the inverse quantization value of each specific value of the parameter x to be quantized using the following formula S2.5: Use the following formula to calculate the quantization error σ corresponding to the current quantization value and the quantization boundary 2 : S2.6: Determine whether the difference between two adjacent quantization errors is less than a preset threshold. If so, the solution ends; otherwise, return to step S2.
2.
3. The post-training quantized image classification method according to claim 2, characterized in that: The quantized value a in step S2.1 k The initialization uses the following formula:
4. The post-training quantized image classification method according to claim 1, characterized in that: In step S4, the dequantized input feature map Perform offset correction. The specific method is as follows: The scale factor α is calculated using the following formula: i,scale and the offset factor α i,shift : Among them, | | L1 Indicates the L1 norm is obtained; The following formula is used to perform offset correction on the dequantized input feature map to obtain the dequantized input feature map after offset correction:
5. The post-training quantized image classification method according to claim 1, characterized in that: Said The calculation of is implemented by lookup table matrix multiplication, the specific method is: A product result lookup table of size K×G is calculated in advance based on K inverse quantization values of the input features and G quantized integer values of the weights; In calculating matrix multiplication When each dequantized input feature and quantized weights The value of is looked up in the product result lookup table to get the relative result, and then accumulated to get the matrix multiplication result.
Citation Information
Cited By
Image block-by-block post-training quantization method and system for ViTs
CN119445127A
