A network reasoning acceleration method and system for image defect detection based on dynamic quantization
By adopting dynamic quantization technology in the image defect detection network and dynamically adjusting the quantization parameters to optimize the inference results, the problem of high computing resources consumption in the prior art is solved, and efficient image defect detection in resource-constrained environments is achieved.
Patent Information
- Application Number
- CN202411354536.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-09-27
AI Technical Summary
In the prior art, image defect detection methods rely on deep learning models, resulting in high consumption of computing resources. Especially in environments such as edge computing and mobile devices, how to effectively deploy complex deep learning models has become a key issue.
The image defect detection network inference acceleration method based on dynamic quantization is adopted to improve the adaptability and flexibility of the model in different application scenarios by collecting image data, preprocessing, preliminary inference, dynamically adjusting quantitative parameters and optimizing inference results.
Through the adjustment of dynamic quantization parameters, the adaptability and flexibility of the model in different application scenarios is improved, computing resources are effectively saved, and the performance of the image defect detection network is improved.
Smart Images

Figure CN118887212B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of defect detection technology, and in particular to a method and system for accelerating network reasoning for image defect detection based on dynamic quantization. Background Art
[0002] With the continuous improvement of industrial automation, image defect detection technology has been widely used in many fields such as manufacturing, semiconductor testing, and medical image analysis. In order to meet the needs of efficient and real-time defect detection, a method is needed that can reduce computing resource consumption while ensuring detection accuracy. Especially in resource-constrained environments such as edge computing and mobile devices, how to effectively deploy complex deep learning models has become a key issue.
[0003] Most current image defect detection methods rely on deep learning models. Although these models have high detection accuracy, they often require a lot of computing resources for inference. In order to deploy these models on edge devices, model compression techniques such as quantization are usually used to convert floating-point operations in the model into integer operations to reduce the computational cost and memory usage of the model. However, traditional quantization methods are often static, that is, the quantization parameters are fixed after the model training is completed, which may lead to a decrease in model performance when processing different types of data.
[0004] The following are the shortcomings of the existing solutions:
[0005] Poor adaptability: Once static quantization parameters are set, they will not change and cannot adapt to changes in the characteristics of different input data, which may lead to degraded model performance in certain specific situations.
[0006] Lack of flexibility: Since the quantization parameters are fixed, the model cannot be dynamically adjusted to optimize performance when the input data changes. Summary of the invention
[0007] The embodiments of the present application provide a method and system for accelerating network reasoning for image defect detection based on dynamic quantization, and are used to solve the problems of poor adaptability, insufficient flexibility, and waste of resources in the prior art.
[0008] In a first aspect, an embodiment of the present application provides an image defect detection network reasoning acceleration method based on dynamic quantization, comprising:
[0009] Collecting image data and preprocessing the image data;
[0010] Based on the preprocessed image data, the pre-trained image defect detection network is used for reasoning to obtain preliminary reasoning results;
[0011] Dynamically adjusting the quantization parameters in the image defect detection network according to the statistical characteristics of the image data to obtain optimized quantization parameters;
[0012] Re-inference is performed according to the optimized quantization parameters to obtain optimized inference results;
[0013] The method of re-inferring the image data according to the optimized quantization parameters to obtain the optimized inference results includes: quantizing the weights and activation functions in the image defect detection network using the optimized quantization parameters; and re-inferring the image data through the quantized network to obtain the optimized inference results.
[0014] Optionally, the dynamically adjusting the quantization parameters in the image defect detection network includes:
[0015] Analyze the pixel value distribution of the image data to determine a suitable quantization bit width;
[0016] According to the pixel value distribution, the weight quantization bit width and activation quantization bit width in the image defect detection network are adjusted.
[0017] Optionally, dynamically adjusting the quantization parameters in the image defect detection network according to the statistical characteristics of the image data includes:
[0018] Calculating a histogram of the image data, and determining a quantization threshold according to the histogram;
[0019] The quantization granularity in the image defect detection network is adjusted according to the quantization threshold.
[0020] Optionally, the calculation formula of the quantization threshold includes:
[0021]
[0022] in, is the quantization threshold, is the pixel value The frequency in the histogram, is the length of the histogram, is a positive real number used to adjust the weight of pixel frequency, and are the mean and standard deviation of the image pixel values, respectively.
[0023] Optionally, re-performing reasoning according to the optimized quantization parameter to obtain an optimized reasoning result includes:
[0024] quantizing the weights and activation functions in the image defect detection network using the optimized quantization parameters;
[0025] The image data is re-inferred through the quantized network to obtain an optimized inference result.
[0026] Optionally, a calculation formula for quantization error in the weight quantization process is as follows:
[0027]
[0028] in, is the quantization error, is the original weight value, is the quantized weight value, is the number of weights, is the regularization term coefficient, is the skewness penalty coefficient, is the average value of the weights.
[0029] Optionally, the quantization process of the activation function includes:
[0030] A quantization function is defined for a quantization process of an activation function, wherein the quantization function is used to map a floating point value to an integer value of a specified quantization bit width;
[0031] The calculation formula of the quantization function is as follows:
[0032]
[0033] in, Expressed as a quantization function, Expressed as a scaling factor, Represented as input value, Expressed as zero offset, Represented as input value Zoom and pan adjustments are made, and by adding and round down to the nearest integer. It represents the floor symbol, is the quantization bit width, The function is expressed as The value is clipped to the interval Inside;
[0034] Determine the scaling factor and zero offset The calculation formula is as follows:
[0035]
[0036]
[0037] in, is the input value, is the quantization bit width, is the scaling factor, represents the maximum absolute value of the activation function output, Represents the minimum value of the activation function output.
[0038] In a second aspect, an embodiment of the present application provides an image defect detection network reasoning acceleration system based on dynamic quantization, comprising:
[0039] A data acquisition module, used for acquiring image data and preprocessing the image data;
[0040] The inference module is used to perform inference based on the preprocessed image data using the pre-trained image defect detection network to obtain preliminary inference results;
[0041] A quantization parameter adjustment module, used to dynamically adjust the quantization parameters in the image defect detection network according to the statistical characteristics of the image data to obtain optimized quantization parameters;
[0042] The optimized reasoning module is used to re-perform reasoning according to the optimized quantization parameters to obtain optimized reasoning results.
[0043] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute any of the dynamic quantization-based image defect detection network inference acceleration methods described in the first aspect.
[0044] In a fourth aspect, an embodiment of the present application provides a computer storage medium having computer program instructions stored thereon, wherein the computer program instructions, when executed by a processor, implement the image defect detection network inference acceleration method based on dynamic quantization as described in any one of the first aspects.
[0045] In the embodiment of the present application, image data is collected and preprocessed; based on the preprocessed image data, a pre-trained image defect detection network is used for inference to obtain a preliminary inference result; according to the statistical characteristics of the image data, the quantization parameters in the image defect detection network are dynamically adjusted to obtain an optimized quantization parameter; according to the optimized quantization parameter, the inference is re-performed to obtain an optimized inference result. The technical solution provided by the present application not only improves the adaptability and flexibility of the model in different application scenarios, but also effectively saves computing resources.
[0046] These and other aspects of the present application will become more clearly understood in the description of the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0048] Figure 1 A flowchart of a network reasoning acceleration method for image defect detection based on dynamic quantization provided in an embodiment of the present application;
[0049] Figure 2 A schematic diagram of the structure of an image defect detection network inference acceleration system based on dynamic quantization provided in an embodiment of the present application;
[0050] Figure 3 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0052] In some of the processes described in the specification and claims of this application and the above-mentioned figures, multiple operations that appear in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this article or executed in parallel. The serial numbers of the operations, such as 101, 102, etc., are only used to distinguish between different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this article are used to distinguish different messages, devices, modules, etc., do not represent the order of precedence, and do not limit the "first" and "second" to be different types.
[0053] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0054] Figure 1 A flowchart of a method for accelerating image defect detection network reasoning based on dynamic quantization is provided for an embodiment of the present application, such as Figure 1 As shown, the method includes:
[0055] 101. Collect image data and pre-process the image data;
[0056] In this step, you first need to collect image data, which usually refers to obtaining raw image information from a camera, sensor, or other image source. Then, the collected image data is preprocessed. The purpose of preprocessing is to improve the effect of subsequent processing steps. Common preprocessing operations include but are not limited to resizing, normalization, grayscale, noise removal, etc.
[0057] In an embodiment of the present application, it is assumed that there is a quality inspection scenario on an industrial production line, and it is necessary to detect the surface defects of the products on the production line in real time. First, a high-resolution industrial camera (IC) is used to capture images of products transmitted on the production line. Then, the captured image is preprocessed, including converting the image from the RGB color space to a grayscale image to reduce the computational complexity, and applying a Gaussian blur filter to remove high-frequency noise in the image. Next, in order to meet the requirements of the neural network input, the image size needs to be uniformly adjusted to 224x224 pixels, and each pixel value needs to be normalized so that it falls between 0-1. Specifically, assuming that the size of the image captured at a certain time is 640x480 pixels, it needs to be scaled to 224x224 pixels, and the following normalization operation is performed on each pixel value:
[0058] Normalized Pixel Value
[0059] The processed image can be used as the input of the image defect detection network in the next step.
[0060] 102. Based on the preprocessed image data, the pre-trained image defect detection network is used for reasoning to obtain preliminary reasoning results;
[0061] In this step, based on the preprocessed image data, the pre-trained image defect detection network is used for inference, which refers to inputting the preprocessed image into a trained deep learning model that can identify defects in the image. "Inference" here refers to the process of making predictions based on the learned knowledge after receiving new data. The image defect detection network is a neural network model specially designed to identify specific defects or anomalies in images. It may contain convolutional layers, pooling layers, fully connected layers, etc., and has learned how to distinguish between normal images and defective images during the network training stage.
[0062] In an embodiment of the present application, it is assumed that we have an Image Defect Detection Network (IDDN) for detecting scratches on the surface of metal sheets. The network is pre-trained on a large number of labeled metal sheet image data sets and can identify different types of scratch defects. After we obtain the preprocessed 224x224 pixel metal sheet image, we input it into the IDDN for inference. IDDN extracts image features through multi-layer convolution operations internally, and then maps the features to defect categories through a fully connected layer. Assume that the output of IDDN is a vector representing the probability distribution of different types of defects. For example, for an input image, IDDN may output the following probability distribution vector: , here we assume that there are five possible defect categories, among which the third category has the highest probability (0.9), which means that IDDN believes that this image is most likely to belong to the third category of defects.
[0063] Therefore, based on this inference result, we can draw a preliminary conclusion: the input metal sheet image has a third-category scratch defect. This preliminary inference result provides a basis for further decision-making, such as whether further manual review is required or whether the metal sheet is directly judged to be unqualified.
[0064] 103. Dynamically adjust the quantization parameters in the image defect detection network according to the statistical characteristics of the image data to obtain optimized quantization parameters;
[0065] Optionally, the dynamic adjustment of the quantization parameters in the image defect detection network in step 103 includes: analyzing the pixel value distribution of the image data to determine a suitable quantization bit width; and adjusting the weight quantization bit width and activation quantization bit width in the image defect detection network according to the pixel value distribution.
[0066] Optionally, the dynamically adjusting the quantization parameters in the image defect detection network according to the statistical characteristics of the image data in step 103 includes: calculating a histogram of the image data and determining a quantization threshold based on the histogram; and adjusting the quantization granularity in the image defect detection network according to the quantization threshold.
[0067] The calculation formula of the quantization threshold includes:
[0068] in, is the quantization threshold, is the pixel value The frequency in the histogram, is the length of the histogram, is a positive real number used to adjust the weight of pixel frequency, and are the mean and standard deviation of the image pixel values, respectively.
[0069] In this step, the quantization parameters in the image defect detection network are dynamically adjusted to optimize the accuracy and efficiency of the inference process. The adjustment of the quantization parameters is mainly based on the statistical characteristics of the image data, such as analyzing the pixel value distribution of the image data to determine the appropriate quantization bit width (QBW), and then adjusting the weight quantization bit width (WQBW) and activation quantization bit width (AQBW) in the network. In addition, the quantization threshold (QT) can be determined by calculating the histogram of the image data, and the quantization granularity (QG) in the network can be adjusted by this threshold.
[0070] In this embodiment of the application, assume that we are dealing with a batch of surface defect detection tasks for industrial ceramic parts. We have obtained preprocessed image data and performed preliminary reasoning using a pre-trained defect detection network. Now, we need to dynamically adjust the quantization parameters according to the statistical characteristics of the image data to optimize the reasoning results.
[0071] First, we analyze the pixel value distribution of the image data to determine the appropriate quantization bit width. For example, we found that the pixel values of this batch of image data are concentrated between 0-255, but mainly in the range of 0-100. Therefore, we decided to use an 8-bit quantization bit width (QBW=8), which can ensure sufficient accuracy to capture image details while also reducing the computational burden. Next, we adjust the weight quantization bit width WQBW and the activation quantization bit width AQBW. Since weights generally require higher precision to maintain network performance, we set WQBW to 8 bits and the activation quantization bit width AQBW to 6 bits, which can reduce the demand for computing resources while maintaining a certain accuracy.
[0072] Next, we determine the quantization threshold T based on the histogram of the image data. We calculated the histogram H(i) of the image data and used the formula:
[0073] To calculate the quantization threshold. Assuming the histogram length , the mean value of the image pixel value , standard deviation , we get the quantization threshold by calculation According to this threshold, we adjust the quantization granularity QG in the network to better match the actual distribution of image data.
[0074] Through the above steps, we obtain the optimized quantization parameters, which will be used in the subsequent reasoning process to improve the performance of the image defect detection network.
[0075] 104. Re-inference is performed according to the optimized quantization parameters to obtain optimized inference results.
[0076] Optionally, the re-inference according to the optimized quantization parameters in step 104 to obtain an optimized inference result includes: quantizing the weights and activation functions in the image defect detection network using the optimized quantization parameters; and re-inferring the image data through the quantized network to obtain an optimized inference result.
[0077] The calculation formula of the quantization error in the weight quantization process is as follows:
[0078]
[0079] in, is the quantization error, is the original weight value, is the quantized weight value, is the number of weights, is the regularization term coefficient, is the skewness penalty coefficient, is the average value of the weights.
[0080] The quantization process of the activation function includes:
[0081] A quantization function is defined for a quantization process of an activation function, wherein the quantization function is used to map a floating point value to an integer value of a specified quantization bit width;
[0082] The calculation formula of the quantization function is as follows:
[0083]
[0084] in, Expressed as a quantization function, Expressed as a scaling factor, Represented as input value, Expressed as zero offset, Represented as input value Zoom and pan adjustments are made, and by adding and round down to the nearest integer. It represents the floor symbol, is the quantization bit width, The function is expressed as The value is clipped to the interval Inside;
[0085] Determine the scaling factor and zero offset The calculation formula is as follows:
[0086]
[0087]
[0088] in, is the input value, is the quantization bit width, is the scaling factor, represents the maximum absolute value of the activation function output, Represents the minimum value of the activation function output.
[0089] In this step, re-inference is performed according to the optimized quantization parameters, which means that the weights and activation functions in the image defect detection network are quantized using the adjusted quantization parameters. Quantization is the process of converting floating-point numbers to fixed-precision integers. Its purpose is to reduce the storage space requirements of the model and speed up the calculation speed, but it may also cause a certain loss of precision. The calculation of quantization error (QE) is used to evaluate the degree of this loss of precision. Quantization of activation functions maps continuous floating-point outputs to finite discrete integer values in order to perform efficient inference on low-precision hardware.
[0090] In the present embodiment, we continue to use the industrial ceramic parts surface defect detection network mentioned above. Assume that we have dynamically adjusted the quantization parameters according to the statistical characteristics of the image data and obtained the optimized quantization parameters. We now need to re-infer based on these parameters to obtain the optimized inference results.
[0091] We first use the optimized quantization parameters to quantize the weights in the network. Assuming that we have determined the new quantization bit width to be 8 bits (QBW=8), we need to quantize the weight values in the network. The calculation formula for the quantization error E is as follows:
[0092]
[0093] here, is the original weight value, is the quantized weight value, is the number of weights, is the regularization term coefficient, is the skewness penalty coefficient, is the average value of the weights. We assume ,and , through calculation, we get the quantization error This error value can help us understand the impact of the quantization process on network performance.
[0094] Next, we quantize the activation function. Define the quantization function , used to map floating-point values to a specified quantization bit width The calculation formula of the quantization function is as follows:
[0095]
[0096] in, Expressed as a quantization function, Expressed as a scaling factor, Represented as input value, Expressed as zero offset, Represented as input value Zoom and pan adjustments are made, and by adding and round down to the nearest integer. It represents the floor symbol, is the quantization bit width, The function is expressed as The value is clipped to the interval Inside;
[0097] Scaling Factor and zero offset The calculation formula is as follows:
[0098]
[0099]
[0100] Assume that the maximum absolute value of the activation function output , minimum , quantization bit width , then the scaling factor , zero offset .
[0101] Finally, the quantized network is used to re-infer the image data. In this way, we get optimized inference results, which will more accurately reflect the defects in the image and the inference process will be more efficient.
[0102] The above steps show how to re-perform inference based on the optimized quantization parameters, thereby improving the computational efficiency of the model while maintaining high accuracy.
[0103] Figure 2 A structural diagram of an image defect detection network inference acceleration system based on dynamic quantization is provided for an embodiment of the present application, such as Figure 2 As shown, the system includes:
[0104] The data acquisition module 21 is used to acquire image data and pre-process the image data;
[0105] The reasoning module 22 is used to perform reasoning based on the preprocessed image data using a pre-trained image defect detection network to obtain a preliminary reasoning result;
[0106] A quantization parameter adjustment module 23, used to dynamically adjust the quantization parameters in the image defect detection network according to the statistical characteristics of the image data to obtain optimized quantization parameters;
[0107] The optimization reasoning module 24 is used to re-perform reasoning according to the optimized quantization parameters to obtain optimized reasoning results.
[0108] Figure 2 The image defect detection network reasoning acceleration system based on dynamic quantization can perform Figure 1 The implementation principle and technical effect of the image defect detection network inference acceleration method based on dynamic quantization described in the illustrated embodiment will not be repeated. The specific way in which each module and unit performs operations in the image defect detection network inference acceleration system based on dynamic quantization in the above embodiment has been described in detail in the embodiment of the method, and will not be elaborated here.
[0109] In one possible design, Figure 2 The image defect detection network inference acceleration system based on dynamic quantization of the embodiment shown can be implemented as a computing device, such as Figure 3 As shown, the computing device may include a storage component 31 and a processing component 32;
[0110] The storage component 31 stores one or more computer instructions, wherein the one or more computer instructions are called and executed by the processing component 32 .
[0111] The processing component 32 is used to: collect image data and preprocess the image data; perform reasoning based on the preprocessed image data using a pre-trained image defect detection network to obtain preliminary reasoning results; dynamically adjust the quantization parameters in the image defect detection network according to the statistical characteristics of the image data to obtain optimized quantization parameters; and re-perform reasoning based on the optimized quantization parameters to obtain optimized reasoning results.
[0112] The processing component 32 may include one or more processors to execute computer instructions to complete all or part of the steps in the above method. Of course, the processing component may also be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0113] The storage component 31 is configured to store various types of data to support operations at the terminal. The storage component can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0114] Of course, the computing device may also include other components, such as input / output interfaces, display components, communication components, etc.
[0115] The input / output interface provides an interface between the processing component and the peripheral interface module, which may be an output device, an input device, etc.
[0116] The communication component is configured to facilitate, among other things, wired or wireless communications between the computing device and other devices.
[0117] Among them, the computing device can be a physical device or an elastic computing host provided by a cloud computing platform, etc. In this case, the computing device can refer to a cloud server, and the above-mentioned processing components, storage components, etc. can be basic server resources rented or purchased from the cloud computing platform.
[0118] The present application also provides a computer storage medium storing a computer program, wherein the computer program can achieve the above-mentioned Figure 1 The illustrated embodiment is a method for accelerating image defect detection network reasoning based on dynamic quantization.
[0119] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0120] The system embodiment described above is merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
[0121] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0122] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A network reasoning acceleration method for image defect detection based on dynamic quantization, characterized in that: include: Collecting image data and preprocessing the image data; Based on the preprocessed image data, the pre-trained image defect detection network is used for reasoning to obtain preliminary reasoning results; Dynamically adjusting the quantization parameters in the image defect detection network according to the statistical characteristics of the image data to obtain optimized quantization parameters; Re-inference is performed according to the optimized quantization parameters to obtain optimized inference results; The re-inference according to the optimized quantization parameters to obtain the optimized inference results includes: quantizing the weights and activation functions in the image defect detection network using the optimized quantization parameters; and re-inferring the image data through the quantized network to obtain the optimized inference results; The dynamically adjusting the quantization parameters in the image defect detection network according to the statistical characteristics of the image data includes: Calculating a histogram of the image data, and determining a quantization threshold according to the histogram; Adjusting the quantization granularity in the image defect detection network according to the quantization threshold; The calculation formula of the quantization threshold includes: ; in, is the quantization threshold, is the pixel value The frequency in the histogram, is the length of the histogram, is a positive real number used to adjust the weight of pixel frequency, and are the mean and standard deviation of the image pixel values, respectively; The calculation formula of the quantization error in the weight quantization process is as follows: ; in, is the quantization error, is the original weight value, is the quantized weight value, is the number of weights, is the regularization term coefficient, is the skewness penalty coefficient, is the average value of the weights; The quantization process of the activation function includes: A quantization function is defined for the activation function to perform a quantization process, wherein the quantization function is used to map a floating point value to an integer value of a specified quantization bit width; The calculation formula of the quantization function is as follows: ; in, Expressed as a quantization function, Expressed as a scaling factor, Represented as input value, Expressed as zero offset, Represented as input value Zoom and pan adjustments are made, and by adding and round down to the nearest integer. It represents the floor symbol, is the quantization bit width, The function is expressed as The value is clipped to the interval Inside; Determine the scaling factor and zero offset The calculation formula is as follows: ; ; in, is the input value, is the quantization bit width, is the scaling factor, represents the maximum absolute value of the activation function output, Represents the minimum value of the activation function output.
2. The method according to claim 1, characterized in that The dynamically adjusting the quantization parameters in the image defect detection network includes: Analyze the pixel value distribution of the image data to determine a suitable quantization bit width; According to the pixel value distribution, the weight quantization bit width and activation quantization bit width in the image defect detection network are adjusted.
3. A dynamic quantization-based image defect detection network inference acceleration system, used to execute the dynamic quantization-based image defect detection network inference acceleration method according to any one of claims 1-2, characterized in that: include: A data acquisition module, used for acquiring image data and preprocessing the image data; The inference module is used to perform inference based on the preprocessed image data using the pre-trained image defect detection network to obtain preliminary inference results; A quantization parameter adjustment module, used to dynamically adjust the quantization parameters in the image defect detection network according to the statistical characteristics of the image data to obtain optimized quantization parameters; The optimization reasoning module is used to re-perform reasoning according to the optimized quantization parameters to obtain optimized reasoning results; The quantization parameter adjustment module is specifically used to quantize the weights and activation functions in the image defect detection network using the optimized quantization parameters; The image data is re-inferred through the quantized network to obtain an optimized inference result.
4. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the image defect detection network inference acceleration method based on dynamic quantization as described in any one of claims 1 to 2.
5. A computer storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the image defect detection network inference acceleration method based on dynamic quantization described in any one of claims 1 to 2 is implemented.
Citation Information
Patent Citations
Neural network quantification method and device
CN114372553A
Image deep false detection acceleration method and system based on quantization technology
CN115719520A