Target recognition model reasoning optimization method and device
By optimizing the hierarchical quantization strategy of the target recognition model, the problem of model accuracy loss on resource-constrained devices in the existing technology is solved, and a high-efficiency, low-power target recognition effect is achieved.
Patent Information
- Application Number
- CN202511614205.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-06
- Publication Date
- 2026-03-17
AI Technical Summary
In existing technologies, target recognition models suffer from severe loss of accuracy in key layers due to the use of a uniform low-bit quantization strategy on resource-constrained edge computing devices, making it impossible to achieve both high compression ratio and high recognition accuracy.
By performing structural analysis on the target recognition model, extracting the structural features and activation distribution features of each network layer, calculating the quantization sensitivity score, generating a hierarchical quantization strategy, and using a heterogeneous quantization strategy combined with hierarchical quantization perception training, the model is optimized to adapt to the characteristic differences of different layers.
It achieves significant reduction in memory usage and computational power consumption while maintaining model accuracy, making it suitable for resource-constrained edge hardware platforms and providing real-time, efficient, and low-power target recognition capabilities.
Smart Images

Figure CN121683896A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer technology, and in particular to a target recognition model inference optimization method and device. BACKGROUND
[0002] With the wide application of deep neural networks in the field of computer vision, target recognition technology has been deeply deployed in many scenarios such as security monitoring, automatic driving and industrial detection. In order to pursue higher recognition accuracy, the mainstream target recognition model usually adopts a deep structure and retains full-precision weights and activation tensors in 32-bit floating-point format, which leads to huge model parameter quantity and high computational complexity.
[0003] In practical applications, especially on resource-constrained edge computing devices and embedded platforms, the above full-precision model faces the challenges of large memory occupation, high computational delay and high power consumption, and it is difficult to meet the real-time and energy efficiency requirements. To alleviate this problem, existing technologies propose neural network low-bit quantization methods, which compress weights and activations from floating-point representation to low-bit integer format (such as INT8) to reduce model size and speed up inference.
[0004] However, existing quantization schemes tend to use a unified fixed bit width and quantization strategy for all layers in the network. This one-size-fits-all approach ignores the significant differences in structural complexity, data distribution characteristics and sensitivity to quantization error among different network layers. As a result, some network layers that bear key feature extraction or positioning functions suffer severe accuracy loss after quantization, while other redundant layers fail to be fully compressed, thereby restricting the overall model from achieving higher compression ratio and acceleration benefits while maintaining recognition performance. In addition, existing technologies lack a systematic mapping mechanism that associates network structure characteristics with quantization configurations, and fail to effectively introduce hierarchical perception optimization in the training stage to compensate for quantization errors, resulting in difficulty in balancing low-bit high-efficiency inference and maintaining model accuracy.
[0005] Therefore, there is an urgent need in the art for a target recognition inference optimization scheme that can adapt to internal structural differences, achieve fine-grained hierarchical quantization, and effectively maintain accuracy. SUMMARY
[0006] In view of this, the embodiments of the present application provide a target recognition model inference optimization method and device, which solves the problem that the existing technology uses a unified quantization strategy to ignore the differences in sensitivity to quantization error among different layers of the neural network, resulting in severe accuracy loss in key layers after compression, and failing to balance high compression ratio and high recognition accuracy.
[0007] One aspect of the present application provides a target recognition model inference optimization method based on neural network low-bit quantization, which comprises the following steps: For a specified target recognition task, a dataset containing multiple samples is obtained, each sample containing raw image data and bounding box locations and category labels for multiple target objects therein; The target recognition model to be optimized is structurally analyzed, and the layer type, layer position index, number of input channels, number of output channels, number of parameters, and connection relationships of each network layer are extracted to construct a structural feature vector. The target recognition model is then subjected to multiple rounds of forward inference based on the dataset. The output of each network layer is used as an activation tensor, and an activation distribution feature vector containing the activation mean, activation variance, and activation sparsity is calculated for each network layer. A sensitivity score is calculated for each network layer using quantization perturbation evaluation. The structural feature vectors, activation distribution feature vectors, and sensitivity scores of each network layer are then used to construct a structural feature and sensitivity dataset. Based on the structural features and sensitivity dataset, a preset quantization configuration knowledge base is queried, and a set of hierarchical quantization strategies is generated for each network layer by matching preset mapping rules. Hierarchical low-bit quantization operations are then performed on the target recognition model to generate a heterogeneous quantization neural network model. The dataset is then used to perform hierarchical quantization perception training on the heterogeneous quantization neural network model to obtain the optimized target recognition model, which is then deployed to the target hardware platform.
[0008] In some embodiments, before performing structural analysis on the target recognition model to be optimized, the method further includes: Obtain a training sample set containing multiple samples, each sample containing a sample image and bounding box locations and category labels for multiple sample objects therein; The initial recognition model is trained using the training sample set. The sample image is input into the initial recognition model, which outputs a prediction of the bounding box position and category of the sample object. A joint loss function based on bounding box position loss and classification loss is constructed. The parameters of the initial recognition model are updated by minimizing the joint loss function to obtain the target recognition model to be optimized. The formula for calculating the joint loss function is: ; in, Let the joint loss function be... The number of samples in the training sample set. For sample index, For the first The number of sample objects contained in the sample image described above. For the index of the sample object, The weighting coefficients for the bounding box position loss are: For the bounding box position loss, Smooth L1 loss or IoU loss is used; a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image, a bounding box position predicted by the model for the i-th sample object in the j-th sample image,
[0009] In some embodiments, the sensitivity score is calculated by using a quantization perturbation evaluation for each network layer, including: keeping the parameters of the rest of the network layers of the target recognition model unchanged, and only performing a low-bit quantization operation on the single network layer to be evaluated; using the quantized target recognition model to perform inference on the dataset, recording the change in recognition accuracy and dividing by the parameter quantity of the network layer to be evaluated to obtain the sensitivity score.
[0010] In some embodiments, the structure feature and sensitivity dataset are matched to query a preset quantization configuration knowledge base, and a hierarchical quantization strategy set is generated for each network layer by matching a preset mapping rule, including: by matching the structure feature and sensitivity dataset, obtaining the corresponding quantization parameter configuration in the quantization configuration knowledge base, and obtaining an initial quantization parameter set including quantization bit width, quantization type, quantization dimension, and quantization method; correcting each item in the initial quantization parameter set, if the sensitivity score of the network layer is higher than a preset value, the initial bit width of the network layer is improved without exceeding the maximum bit width limit; if the sensitivity score of the network layer is less than or equal to the preset value or the current bit width has reached the upper limit, the original configuration is kept unchanged; the updated quantization parameter configuration is obtained after the correction; the updated quantization parameter configurations of each network layer are summarized to obtain the hierarchical quantization strategy set.
[0011] In some embodiments, the structure feature and sensitivity dataset are matched to query a preset quantization configuration knowledge base, and a hierarchical quantization strategy set is generated for each network layer by matching a preset mapping rule, including: The structure features and the sensitivity dataset are taken as a query vector group, each historical structure feature vector, historical activation statistical feature vector and historical sensitivity score in each historical configuration record in the quantization configuration knowledge base are taken as a queried item, and the corresponding historical quantization parameter configuration is taken as a verified quantization sample in combination; The comprehensive matching distance between the query content of each network layer in the query vector group and the queried item is calculated by matching the distance function, and the calculation formula is: ; Wherein, is the comprehensive matching distance between the current network layer to be matched and the verified quantization sample, is the comprehensive matching distance between the current network layer to be matched and the verified quantization sample, is the comprehensive matching distance between the current network layer to be matched and the verified quantization sample, is the weighting coefficient of the structure feature item, is the structure feature vector of the network layer, is the structure feature vector of the network layer, is the historical structure feature vector corresponding to the verified quantization sample, is the historical structure feature vector corresponding to the verified quantization sample, is the weighting coefficient of the activation statistical feature item, is the activation distribution feature vector of the network layer, is the activation distribution feature vector of the network layer, is the historical activation statistical feature vector, is the historical activation statistical feature vector, is the weighting coefficient of the sensitivity score item, is the sensitivity score of the network layer, is the sensitivity score of the network layer, is the historical sensitivity score, is the historical sensitivity score, is the square of the Euclidean distance; The verified quantization sample with the minimum matching distance corresponding to the query content of the network layer is determined, the historical quantization parameter configuration corresponding to the verified quantization sample is taken as the initial quantization parameter configuration of the current network layer, and the initial quantization parameter set of all the network layers is obtained by summarizing.
[0012] In some embodiments, a hierarchical low-bit quantization operation is performed on the target recognition model to generate a heterogeneous quantization neural network model, including: From the hierarchical quantization strategy set, a quantization parameter configuration is extracted for each network layer in the target recognition network, and the quantization parameter configuration includes bit width, quantization type, quantization dimension, and quantization mode of weight and activation; The scaling factor and zero point offset required for quantizing the network layer weight are calculated according to the bit width, the quantization type and the quantization dimension, and a weight quantization operation is performed to obtain a quantized weight tensor; wherein the scaling factor is used to map the numerical range of the floating-point weight tensor to the integer representation interval, and the zero point offset is used to adjust the quantized integer range to make it symmetric or asymmetric distribution; According to the quantization mode of the weight and the activation, it is judged whether the current network layer adopts independent quantization mode, if the network layer is set to independent quantization, the activation tensor needs to be quantized separately, including: calculating the scaling factor and the zero point offset according to the numerical distribution of the activation tensor, using the scaling factor and the zero point offset to perform quantization mapping operation on the floating-point value in the activation tensor to obtain a quantized activation tensor, if the network layer does not adopt independent quantization mode, skip this step, the activation tensor and the quantized weight tensor share the same quantization parameters; The quantized weight tensor and the quantized activation tensor are combined to replace the weight tensor and the activation tensor of each network layer in the target recognition model, completing the low-bit quantization replacement of the network layer, and obtaining a hierarchical quantization network layer; All the hierarchical quantization network layers obtained by hierarchical low-bit quantization processing are combined to obtain the heterogeneous quantization neural network model.
[0013] In some embodiments, the hierarchical quantization perception training of the heterogeneous quantization neural network model is performed using the data set to obtain an optimized target recognition model, including: During the forward propagation process of the hierarchical quantization perception training of the heterogeneous quantization neural network model based on the data set, an analog quantization operation is inserted in each network layer, and the analog quantization operation is realized by the following pseudo quantization function: ; For the pseudo quantization function, The tensor to be quantized in the network layer of the heterogeneous quantization neural network model, including the weight tensor or the activation tensor to be quantized; The scaling factor, The zero point offset, The minimum integer value that can be represented by the target bit width, The maximum integer value that can be represented by the target bit width; The rounding operation is performed on the quantization mapping result, The interval clipping operation is performed on the result after the rounding operation; In the back propagation process, a layered loss weight coefficient of each network layer in the heterogeneous quantized neural network model is calculated according to a sensitivity score, and the calculation formula is: ; Among them, is the layered loss weight coefficient of the i-th network layer in the heterogeneous quantized neural network model, is the sensitivity score of the i-th network layer in the heterogeneous quantized neural network model, is the total number of network layers, is the index of the network layer in the heterogeneous quantized neural network model, is the sensitivity score of the i-th network layer in the heterogeneous quantized neural network model; is the sensitivity score of the i-th network layer in the heterogeneous quantized neural network model; is the sensitivity score of the i-th network layer in the heterogeneous quantized neural network model; is the sensitivity score of the i-th network layer in the heterogeneous quantized neural network model. Based on the layered loss weight coefficient of each network layer in the heterogeneous quantized neural network model, the positioning error term and the classification error term of the loss function in the back propagation process are weighted and integrated to obtain a layered weighted loss function; the heterogeneous quantized neural network model is iteratively trained based on the layered weighted loss function using stochastic gradient descent until convergence, and the optimized target recognition model is obtained.
[0014] In another aspect, the present application also provides a target recognition model inference optimization device based on neural network low-bit quantization, which comprises a processor, a memory and a computer program or instructions stored on the memory, wherein the processor is used to execute the computer program or instructions, and when the computer program / instructions are executed, the device realizes the steps of the above method.
[0015] In another aspect, the present application also provides a computer readable storage medium having a computer program or instructions stored thereon, wherein the computer program or instructions are executed by a processor to realize the steps of the above method.
[0016] In another aspect, the present application also provides a computer program product comprising a computer program or instructions, wherein the computer program or instructions are executed by a processor to realize the steps of the above method.
[0017] The target recognition model inference optimization method and device provided by the application first perform structural analysis and sensitivity evaluation on the pre-trained model, extract the structural feature vector, activation distribution feature vector and quantization sensitivity score of each network layer, and construct a dataset that can accurately reflect the characteristics and fault tolerance of each level. Based on the dataset, query the quantization configuration knowledge base, and dynamically generate the optimal heterogeneous quantization strategy set for different network layers through the preset mapping rule. Finally, the layered low-bit quantization operation is performed according to the strategy, and the model is further optimized through the quantization-aware training of the layered weighted loss function, which effectively compensates for the precision loss caused by bit width compression. Through the layered heterogeneous quantization strategy, the application realizes high compression ratio and significant acceleration while maximizing the key recognition accuracy of the model, especially protecting the performance of the high sensitivity layer. The generated heterogeneous quantization model significantly reduces the memory occupation and computing power, so that it can be efficiently deployed on the resource-constrained edge hardware platform. The whole method forms a complete and automated process from analysis, configuration to training compensation, has strong universality and high engineering practical value, and provides reliable technical support for real-time, efficient and low-power inference of complex visual tasks on the edge side.
[0018] Additional advantages, objects, and features of the application will be set forth in part by the description that follows, and will become apparent to those skilled in the art upon examination of the following detailed description and drawings. The objects and other advantages of the application can be realized and attained by means of the instrumentalities particularly pointed out in the specification and drawings.
[0019] Those skilled in the art will appreciate that the objects and advantages of the application can be realized and attained by means of the instrumentalities particularly pointed out in the specification and drawings. BRIEF DESCRIPTION OF DRAWINGS
[0020] The drawings described herein are intended to provide a further understanding of the application, and constitute a part of this application. The drawings do not constitute a limitation of the application. In the drawings: Figure 1 The flowchart of the target recognition model inference optimization method based on neural network low-bit quantization according to an embodiment of the application is shown.
[0021] Figure 2 The network layer structure feature extraction and precision sensitivity score flowchart in the target recognition inference optimization method based on neural network low-bit quantization according to another embodiment of the application is shown.
[0022] Figure 3 The structure feature driven layered quantization strategy mapping flowchart in the target recognition inference optimization method based on neural network low-bit quantization according to another embodiment of the application is shown. DETAILED DESCRIPTION
[0023] In order to make the objects, technical solutions and advantages of the present application clearer, the following further describes the present application with reference to the embodiments and drawings. Herein, the illustrative embodiments of the present application and their descriptions are used to explain the present application but not to limit the present application.
[0024] Herein, it should also be noted that, in order to avoid the present application being obscured by unnecessary details, only the structures and / or processing steps closely related to the solutions according to the present application are shown in the drawings, and other details not closely related to the present application are omitted.
[0025] It should be emphasized that the term "comprises / comprising" as used herein is used to indicate the presence of a feature, element, step or component but does not preclude the presence or addition of one or more other features, elements, steps or components.
[0026] The prior art generally uses a fixed low-bit configuration for all network layers, without fully considering the differences between layers in terms of structural complexity, data distribution and precision sensitivity, resulting in a significant reduction in recognition performance after quantization of key layers, and a lack of mapping relationship with network features and systematic training compensation mechanism. The present application introduces hierarchical structure sensitivity analysis, adaptive quantization strategy mapping and hierarchical quantization-aware training, while maintaining model precision, to realize low-bit efficient inference, suitable for resource-constrained edge computing platforms.
[0027] Specifically, the present application provides a target recognition model inference optimization method based on neural network low-bit quantization, as shown in Figure 1 The method comprises the following steps S101-S103: Step S101: For a specified target recognition task, a data set containing a plurality of samples is obtained, each sample containing original image data and a plurality of target object label boundary box positions and class labels.
[0028] Step S102: The structure of the target recognition model to be optimized is analyzed, and the layer type, layer position index, input channel number, output channel number, parameter quantity and connection relationship of each network layer are extracted to construct a structure feature vector; the target recognition model is subjected to a plurality of forward inference operations based on the data set, the output of each network layer is taken as an activation tensor, and the activation distribution feature vector containing the activation mean, activation variance and activation sparsity of each network layer is calculated; the sensitivity score is calculated by using a quantization disturbance evaluation for each network layer; and the structure feature vector, the activation distribution feature vector and the sensitivity score of each network layer are constructed into a structure feature and sensitivity data set.
[0029] Step S103: Based on the structural features and sensitivity dataset, query the preset quantization configuration knowledge base, match the preset mapping rules to generate a set of hierarchical quantization strategies for each network layer, perform hierarchical low-bit quantization operation on the target recognition model to generate a heterogeneous quantization neural network model, and use the dataset to perform hierarchical quantization perception training on the heterogeneous quantization neural network model to obtain an optimized target recognition model, which is then deployed to the target hardware platform.
[0030] In steps S101-S103, the target recognition model to be optimized in this invention is based on a convolutional neural network (CNN) and is used to identify and locate a specified type of target object in an image. It consists of convolutional layers, normalization layers, activation layers, and fully connected layers connected in a predetermined topological structure. Mainstream target detection models include the YOLO series, SSD, and Faster R-CNN. These models can directly output the bounding box position and category label of the target in the image. The optimization method of this invention has universality; its core lies in the analysis of the model structure and the hierarchical quantization strategy. Therefore, it is applicable to most recognition models based on convolutional neural networks that require target localization and classification.
[0031] In this application, the target recognition model can be pre-trained and awaiting deployment, or it can be trained first in a specific scenario and then optimized for deployment.
[0032] Specifically, in some embodiments, before performing structural analysis on the target recognition model to be optimized, the method further includes steps S201-S202: Step S201: Obtain a training sample set containing multiple samples, each sample containing a sample image and bounding box locations and category labels for multiple sample objects.
[0033] Step S202: Train the initial recognition model using the training sample set, input the sample image into the initial recognition model to output the prediction of the bounding box position and category of the sample object, construct a joint loss function based on bounding box position loss and classification loss, minimize the joint loss function to update the parameters of the initial recognition model to obtain the target recognition model to be optimized.
[0034] The formula for calculating the joint loss function is: ; in, For the joint loss function, The number of samples in the training sample set. For sample index, For the first The number of sample objects contained in a sample image. Indexing for sample objects, These are the weighting coefficients for the bounding box position loss. For the bounding box position loss, Smooth L1 loss or IoU loss is used; For the model to the first The first sample image The predicted bounding box location for each sample object. For the first The first sample image The true bounding box position of each sample object The weighting coefficients for the classification loss are... For classification loss, cross-entropy loss is used. For the model to the first The first sample image The predicted category of each sample object. For the first The first sample image The true category label of each sample object.
[0035] In step S102, the core objective is to gain a deeper understanding of the internal structure and operating state of the model to be quantified, providing data support for subsequent precise quantification based on layer-by-layer strategies. This step mainly includes the analysis of the structural characteristics, activation distribution characteristics, and sensitivity of each network layer.
[0036] The static analysis process of extracting structural feature vectors primarily aims to obtain the inherent properties of each network layer. Layer type records whether the corresponding network layer is a convolutional layer, fully connected layer, or other type. Layer position index indicates whether the corresponding network layer is located in a shallow, middle, or deep layer of the model; the extracted feature content and importance differ between network layers at different positions. The number of input channels, output channels, and parameters of each network layer indicate model complexity. The preceding and following connections indicate the context of the corresponding network layer in the overall computation process.
[0037] The activation distribution feature vector is used to indicate the statistical characteristics of the output data of each layer during actual inference. Based on the prepared dataset, the target recognition model performs multiple forward inferences, and the intermediate results output by each network layer are used as activation tensors to statistically represent the activation mean, activation variance, and activation sparsity. Activation sparsity is the proportion of activation values whose absolute values are less than a preset threshold.
[0038] Sensitivity scores are used to quantitatively evaluate the tolerance of each layer to quantization operations. In some embodiments, sensitivity scores are calculated for each network layer using quantization perturbation evaluation, including steps S301-S302: Step S301: Keep the parameters of the other network layers of the target recognition model unchanged, and only perform low-bit quantization operation on the single network layer to be evaluated.
[0039] Low-bit quantization operation is a data compression and format conversion process, which aims to convert the high-precision floating-point number (such as FP32) representation in the neural network layer into low-precision integer (such as INT8, INT4) representation, thereby greatly reducing the memory occupation and calculation overhead of the model. In the standard neural network, the weights and activation values are usually represented by 32-bit floating-point numbers (FP32). This format has high precision and wide representation range, but occupies a large space (4 bytes / value) and consumes high energy for calculation. The quantization operation converts them to 8-bit integers (INT8, 1 byte / value) or even 4-bit integers (INT4). This directly reduces the storage requirement by 75%~87.5%, and the speed of integer operation on hardware, especially mobile and edge chips, is usually much faster than floating-point operation.
[0040] Step S302: using the quantized target recognition model to perform inference on the data set, recording the change amplitude of the recognition accuracy and dividing by the parameter quantity of the current network layer to be evaluated to obtain a sensitivity score.
[0041] Step S103 is the execution stage of the present application, which is used to formulate and execute a personalized quantization scheme for the model, and to offset the side effects brought by quantization through training.
[0042] The first stage is to generate a set of hierarchical quantization strategies, using the "structure features and sensitivity dataset" obtained in S102 as input, querying a pre-constructed quantization configuration knowledge base, which stores a large amount of historical experience (mapping rules). Each rule can be in the form of: "if the structure feature of a certain layer is A, the activation feature is B, and the sensitivity is C, then the optimal quantization parameter configuration is D". The present application finds the most matched historical record in the knowledge base for each network layer. Further generate the initial strategy, in the most matched historical record of each network layer, extract the bit width, quantization type, quantization dimension and weight and activation quantization method, form the initial quantization parameter configuration. Finally, perform rule correction, and fine-tune the initial configuration according to the sensitivity score of the network layer. If the sensitivity score of a layer is higher than the preset threshold, i.e. very sensitive, then the initial bit width is increased, for example, from 4bit to 8bit, to reduce the precision loss. Finally, the modified quantization parameter configurations of all layers are collected together to form a set of hierarchical quantization strategies. This strategy set clearly specifies how each layer in the model will be quantized, thereby realizing heterogeneous quantization.
[0043] Specifically, the structure feature and sensitivity dataset are used to query the preset quantization configuration knowledge base, and the preset mapping rules are matched to generate a set of hierarchical quantization strategies for each network layer, including steps S401-S403: Step S401: Obtain the corresponding quantization parameter configuration in the quantization configuration knowledge base by matching the query structure features and the sensitivity dataset, to obtain an initial quantization parameter set including quantization bit width, quantization type, quantization dimension and quantization mode.
[0044] Step S402: Perform a correction operation on each item in the initial quantization parameter set, if the sensitivity score of the network layer is higher than the preset value, the initial bit width of the network layer is improved without exceeding the set maximum bit width limit; if the sensitivity score of the network layer is less than or equal to the preset value or the current bit width has reached the upper limit, the original configuration is kept unchanged; the updated quantization parameter configuration is obtained after the correction is completed.
[0045] Step S403: Aggregate the updated quantization parameter configurations of each network layer to obtain a hierarchical quantization strategy set.
[0046] In step S401, the corresponding quantization parameter configuration in the quantization configuration knowledge base is obtained by matching the query structure features and the sensitivity dataset, including steps S4011-S4013: Step S4011: Take the structure features and the sensitivity dataset as a query vector group, take each historical structure feature vector, historical activation statistical feature vector and historical sensitivity score in each historical configuration record in the quantization configuration knowledge base as a queried item, and combine the corresponding historical quantization parameter configuration as a verified quantization sample.
[0047] Step S4012: Calculate the comprehensive matching distance between the query content of each network layer in the query vector group and the queried item by a matching distance function, the calculation formula is: ; Wherein, is the comprehensive matching distance between the current network layer to be matched and the mth verified quantization sample, is the weighting coefficient of the structure feature item, is the structure feature vector of the mth network layer, is the historical structure feature vector corresponding to the mth verified quantization sample, is the weighting coefficient of the activation statistical feature item, is the activation distribution feature vector of the mth network layer, is the mth historical activation statistical feature vector, is the weighting coefficient of the sensitivity score item, is the sensitivity score of the mth network layer, For the first sensitivity score, is the square of the Euclidean distance.
[0048] Step S4013: Determine the verified quantization sample with the minimum matching distance of the query content corresponding to the network layer, and configure the corresponding historical quantization parameter as the initial quantization parameter configuration of the current network layer. The initial quantization parameter set of all network layers is obtained by summarizing.
[0049] The second stage is to perform quantization and perception training. First, hierarchical low-bit quantization is performed. According to the "hierarchical quantization strategy set" generated above, the original full-precision model is quantized layer by layer. Specifically, according to the configuration of each layer, the scaling factor and zero-point offset of its weight (and activation) are calculated, and then the floating-point number is converted to an integer. After all layers are quantized, a heterogeneous quantization neural network model is obtained. At this time, the model is in low-bit form, but the accuracy is usually greatly lost.
[0050] Further hierarchical quantization perception training is performed to adapt the model to the numerical changes caused by quantization and restore its recognition accuracy. In the forward propagation of training, the simulated quantization operation is inserted. That is, in the calculation, the weight and activation are simulated as low-precision values after quantization, but the full-precision gradient is still used to update the parameters in the back propagation. This enables the model to perceive the existence of quantization and learn to adapt to it. In order to optimize more finely, the loss function used in training is layered and weighted. The network layer with high sensitivity score will be given higher weight in the loss function, so as to be given special attention and optimization in the training process. Through this training process, the model relearns under low-bit representation, and finally obtains the optimized target recognition model. It not only maintains high accuracy, but also has the advantages of small size and high-speed reasoning of low-bit model, and can be smoothly deployed to the target hardware platform.
[0051] In some embodiments, the step S103 of performing hierarchical low-bit quantization operation on the target recognition model to generate a heterogeneous quantization neural network model comprises steps S501-S505: Step S501: Extract the quantization parameter configuration from the hierarchical quantization strategy set for each network layer in the target recognition network, respectively. The quantization parameter configuration includes bit width, quantization type, quantization dimension, and quantization method of weight and activation.
[0052] Step S502: Calculate the scaling factor and zero-point offset required for network layer weight quantization according to the bit width, quantization type and quantization dimension, and perform weight quantization operation to obtain a quantized weight tensor; wherein the scaling factor is used to map the numerical range of the floating-point weight tensor to the integer representation interval, and the zero-point offset is used to adjust the range of the quantized integer to make it symmetrically or asymmetrically distributed.
[0053] Step S503: According to the weight and the activated quantization mode, it is judged whether the current network layer adopts independent quantization mode. If the network layer is set to independent quantization, the activation tensor needs to be quantized separately, including: calculating the scaling factor and zero point offset according to the numerical distribution of the activation tensor, using the scaling factor and zero point offset to perform quantization mapping operation on the floating point values in the activation tensor to obtain the quantized activation tensor, if the network layer does not adopt independent quantization mode, skip this step, the activation tensor and the quantized weight tensor share the same quantization parameters.
[0054] Step S504: The quantized weight tensor and the quantized activation tensor are combined to replace the weight tensor and the activation tensor of each network layer in the target recognition model, completing the low-bit quantization replacement of the network layer, and obtaining the hierarchical quantization network layer.
[0055] Step S505: All hierarchical quantization network layers obtained by hierarchical low-bit quantization processing are combined to obtain a heterogeneous quantization neural network model.
[0056] Steps S501 to S505 systematically convert the original target recognition model into an efficient heterogeneous low-bit model according to the quantization strategy customized for each layer in advance. The process starts from S501, and the unique quantization configuration (such as bit width, quantization type) of each network layer is obtained from the hierarchical quantization strategy set, which realizes heterogeneity, i.e. different layers adopt different precision. Then, S502 calculates and quantizes the layer's weight according to the configuration, and converts it from floating point number to integer; S503 judges whether independent quantization of activation is needed according to the configuration, so as to finely control the precision of data flow. Then, S504 replaces the quantized weight and activation tensor back to the original model, completing the quantization modification of a single layer. Finally, S505 reassembles all layers processed by independent quantization into a complete heterogeneous quantization neural network model. The core principle is to achieve optimal balance between efficiency and performance by differentiating quantization according to the needs of each layer, maximizing model size compression and calculation speed while effectively protecting the precision of key layers.
[0057] In some embodiments, step S103 utilizes the dataset to perform hierarchical quantization-aware training on the heterogeneous quantization neural network model to obtain an optimized target recognition model, including steps S601-S603: Step S601: During the forward propagation process of hierarchical quantization-aware training of the heterogeneous quantization neural network model based on the dataset, a simulated quantization operation is inserted in each network layer, and the simulated quantization operation is realized by the following pseudo-quantization function: ; Wherein, is the pseudo-quantization function, The tensor to be quantized in the network layer of the heterogeneous quantized neural network model includes the weight tensor or the activation tensor to be quantized. The scaling factor, This is the zero-point offset. The smallest integer value that the target bit width can represent. The maximum integer value that the target bit width can represent; To perform rounding on the quantization mapping results, To perform a range clipping operation on the result after rounding.
[0058] Step S602: During backpropagation, calculate the layer loss weight coefficient for each network layer in the heterogeneous quantized neural network model based on the sensitivity score. The calculation formula is as follows: ; in, In the heterogeneous quantization neural network model, the first The hierarchical loss weight coefficients of each network layer In the heterogeneous quantization neural network model, the first Sensitivity score of each network layer The total number of network layers. This refers to the index of network layers in a heterogeneous quantized neural network model. In the heterogeneous quantization neural network model, the first Sensitivity scores for each network layer.
[0059] Step S603: Based on the hierarchical loss weight coefficients of each network layer in the heterogeneous quantized neural network model, the localization error term and classification error term of the loss function during backpropagation are weighted and integrated to obtain the hierarchical weighted loss function; based on the hierarchical weighted loss function, the heterogeneous quantized neural network model is iteratively trained using stochastic gradient descent until convergence, and the optimized target recognition model is obtained.
[0060] Steps S601-S603 simulate the quantization effect and differential weighting, so that the model actively learns and adapts to the information loss caused by low-bit quantization during training, thereby recovering and maintaining accuracy. Specifically, in forward propagation, it inserts a simulated quantization operation into the computation graph of each layer, simulates the quantized integer values of the floating-point weights and activation values for forward calculation, which enables the model to "perceive" the rounding error and truncation effect introduced by quantization; in back propagation, a layered weighting loss function is used to assign greater loss weights to network layers with high quantization sensitivity, so as to focus on optimizing and protecting these key layers during parameter updating. This process is essentially a targeted model fine-tuning and compensation mechanism that guides the model parameters to self-adjust, so that the model can still maintain its representation ability and recognition accuracy in the final low-bit integer inference environment.
[0061] In another aspect, the present application also provides a neural network low-bit quantization-based target recognition model inference optimization device, comprising a processor, a memory and a computer program or instructions stored on the memory, wherein the processor is configured to execute the computer program or instructions, and when the computer program / instructions are executed, the device implements the steps of the above method.
[0062] In another aspect, the present application also provides a computer readable storage medium having a computer program or instructions stored thereon, wherein the computer program or instructions are executed by a processor to implement the steps of the above method.
[0063] In another aspect, the present application also provides a computer program product comprising a computer program or instructions, wherein the computer program or instructions are executed by a processor to implement the steps of the above method. The present application will be described below in conjunction with a specific embodiment: Embodiment 1 Reference Figures 2-3 The present embodiment provides a neural network low-bit quantization-based target recognition inference optimization method, comprising the following steps S1-S: Step S1: Collecting original image data containing multiple target categories and performing cleaning, size normalization, format conversion and annotation verification to generate a structured training sample set.
[0064] Step S2: Constructing a target recognition neural network model, training based on the structured training sample set, and obtaining a pre-trained target recognition neural network model.
[0065] Step S3: Structure analysis is performed on the pre-trained target recognition neural network model, structural feature information of each network layer is extracted, and the structural features are scored based on a quantization sensitivity scoring mechanism to generate a structure feature and sensitivity dataset.
[0066] Step S4: input the structural features and the sensitivity dataset into the quantization configuration knowledge base, match with the preset mapping rules, and generate a corresponding set of hierarchical quantization strategies.
[0067] Step S5: according to the set of hierarchical quantization strategies, perform hierarchical low-bit quantization operation on the pre-trained target recognition neural network model to generate a heterogeneous quantized neural network model.
[0068] Step S6: perform hierarchical quantization perception training on the heterogeneous quantized neural network model, and perform key training optimization on the accuracy sensitive layer to obtain a heterogeneous quantized neural network model after hierarchical quantization perception training.
[0069] Step S7: deploy the heterogeneous quantized neural network model after hierarchical quantization perception training to the target hardware platform to perform target recognition inference tasks.
[0070] In the embodiment step S1, the collection of original image data containing multiple target categories and the cleaning, size normalization, format conversion and annotation verification generate a structured training sample set, which specifically includes steps S11-S16: Step S11: collect original image data covering multiple target categories, the original image data is a color image with red, green and blue channels, forming an image set, wherein each image has a unified data structure, including the height, width and color channel of the image, and the number of images is multiple.
[0071] Step S12: perform target annotation operation on each image in the image set, automatically label the position of each target to be recognized in the image, and assign a corresponding category label, the target position is represented in the form of a rectangular bounding box, including the coordinate information of the upper left corner and the lower right corner, the category label is one category in the predefined category set to which the target belongs, and a target annotation set is obtained.
[0072] Step S13: perform preprocessing operation on each image in the image set, specifically including uniformly adjusting the size of the image to the preset standard height and width, normalizing the pixel value of the image, mapping the original pixel value to the value range of 0 to 1, converting the image format to the tensor format acceptable by the neural network model, and performing denoising processing on the image to obtain a preprocessed image set meeting the training input requirements.
[0073] Step S14: perform consistency verification on the target annotation set, specifically including: checking the legality of the boundary box coordinates of all targets in each image to ensure that each set of boundary box coordinates is within the effective size range of the image, and the upper left corner coordinate is less than the lower right corner coordinate; and verifying the validity of the category label corresponding to each boundary box to ensure that the category label belongs to the predefined target category set.
[0074] Step S15: After completing the dual verification of coordinates and categories, remove the annotations that do not meet the requirements, retain the annotations that meet the conditions, and generate a set of verified annotations.
[0075] Step S16: Combine the preprocessed image set with the corresponding verified annotation set one by one, and construct a structured training sample set according to the method of pairing images with their target annotation information. Each training sample consists of a normalized image and all verified target bounding boxes and category labels in the image.
[0076] In step S2 of this implementation, constructing a target recognition neural network model and training it based on a structured training sample set to obtain a pre-trained target recognition neural network model specifically includes steps S21 to S25: Step S21: Construct a target recognition neural network model. The target recognition neural network model consists of multiple network layers connected in a predetermined topology. Each network layer is used to extract image features at different levels. The network layers include convolutional layers, normalization layers, activation layers, and fully connected layers, with each network layer corresponding to a specific index number.
[0077] Step S22: Input each pair of images and their corresponding annotation information from the structured training sample set into the target recognition neural network model in sequence to perform the forward inference process.
[0078] Step S23: During the inference process, the target recognition neural network model detects targets in the input image and outputs the predicted bounding box position and category label of each target, thereby obtaining the predicted bounding box set and the predicted category set, which respectively represent the spatial localization result and classification recognition result of each target in the image in the current training state.
[0079] Step S24: Construct a joint loss function based on the predicted bounding box set, the predicted class set, and the real annotation set in the structured training sample set: The formula for calculating the joint loss function is: ; in, For the joint loss function, The number of training samples. For sample index, For the first The number of targets contained in an image For the target index, These are the weighting coefficients for the location loss term. The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used, The bounding box position loss function is used to calculate the difference between the predicted bounding box and the real bounding box, and the Smooth L1 loss or the IoU loss is usually used,
[0080] The joint loss function in this embodiment is composed of position regression loss and classification loss, which is derived from the classical multi-task learning framework in the fields of machine learning and object detection. The dimensions of the left and right ends of the joint loss function are both dimensionless real values, satisfying the dimensional consistency requirement.
[0081] Step S25: Taking the joint loss function as the optimization objective, the gradient descent-based optimization algorithm is used to iteratively update the parameters in the target recognition neural network model, specifically including: in each round of training, the gradient information of the loss value is calculated according to the current parameter state, and the target recognition neural network model parameters are adjusted using the gradient information.
[0082] In the training process, the loss value and the performance indicators of the target recognition neural network model on the validation set are continuously monitored. When the preset convergence condition is met or the maximum number of training rounds is reached, the training process is terminated, and a set of converged target recognition neural network model parameters are obtained, forming a pre-trained target recognition neural network model.
[0083] In step S3 of this embodiment, the pre-trained target recognition neural network model is structurally analyzed, the structural feature information of each network layer is extracted, the structural features are scored based on the quantification sensitivity scoring mechanism, and the structural feature and sensitivity dataset is generated. Specifically, steps S31-S34 are included: Step S31: Perform a structure information extraction operation on each network layer in the pre-trained target recognition neural network model, the structure information including layer type, layer position index, input channel number, output channel number, parameter quantity, and front and back connection relationship, and record the structure information of all layers as a structure feature set.
[0084] Step S32: Perform a multi-round forward inference operation on the pre-trained target recognition neural network model on the structured training sample set, collect the intermediate output generated by each network layer of the pre-trained target recognition neural network model on the input data during the inference process, and the intermediate output is an activation tensor, which refers to the output result obtained by a network layer after receiving the output of the previous layer through network layer parameter calculation and nonlinear transformation during the network forward propagation process.
[0085] Based on the activation tensor, calculate the activation distribution feature, the activation distribution feature including activation mean, activation variance, and activation sparsity, the sparsity being the proportion of elements in the activation value that satisfy the absolute value less than a preset threshold, combine the activation distribution feature of each network layer to form an activation distribution feature set.
[0086] Step S33: For each network layer in the pre-trained target recognition neural network model, calculate the sensitivity score using the quantization perturbation evaluation method, specifically including: performing a low-bit quantization operation only on the single network layer to be evaluated while keeping the parameters of the remaining layers of the pre-trained target recognition neural network model unchanged.
[0087] Then, use the quantized pre-trained target recognition neural network model to perform inference on the validation set, record the change amplitude of the overall performance indicator (such as recognition accuracy) of the pre-trained target recognition neural network model, denoted as the accuracy drop value of the network layer, and then divide the accuracy drop value by the parameter quantity of the current layer to obtain the sensitivity score, which is used to measure the sensitivity of the network layer to the quantization operation. The higher the score value, the more sensitive the network layer is to the performance loss caused by quantization.
[0088] Step S34: Combine the structure feature set, the activation distribution feature set, and the sensitivity score to form a structure feature and sensitivity data set.
[0089] In step S4 of the embodiment, the structure feature and sensitivity data set is input into the quantization configuration knowledge base, matched with the preset mapping rule, and a corresponding hierarchical quantization strategy set is generated, specifically including steps S41-S44: Step S41: Construct a quantization configuration knowledge base, the quantization configuration knowledge base being used to store the quantization parameter configuration relationship of each type of neural network hierarchical structure feature, including a plurality of mapping rule entries, each mapping rule entry containing structure features, activation distribution features, sensitivity scores, and corresponding optimal quantization parameter configurations.
[0090] Structural features include the type of network layer, its location index, the number of input and output channels, the number of parameters, and the connection relationships. Activation distribution features include the mean, variance, and sparsity of activations during inference. Sensitivity scores are used to reflect the sensitivity of the layer to changes in quantization precision. The corresponding quantization parameter configurations include quantization bit width, quantization type (such as symmetric or asymmetric), quantization dimension (such as channel dimension or tensor dimension), and the quantization method of weights and activations (such as joint quantization or independent quantization).
[0091] Step S42: Input the structural features and sensitivity dataset into the quantization configuration knowledge base, perform a matching operation on each network layer, and obtain the initial quantization parameter set.
[0092] Specifically, the combined features corresponding to each network layer in the structural features and sensitivity dataset are used as query inputs in sequence to construct a query vector group for each layer. Specifically, for each network layer, the structural feature information of that layer is extracted, including the layer type, number of input channels, number of output channels and number of parameters, to form a structural feature vector. The activation statistical features corresponding to that layer are extracted, including activation mean, variance and sparsity, to form an activation feature vector. Then, combined with the sensitivity score, a complete set of query vectors is formed.
[0093] Extract all historical configuration records from the quantization configuration knowledge base to construct a historical record set. Each historical record represents a set of verified quantization samples, including historical structural feature vectors, historical activation statistical feature vectors, historical sensitivity scores, and corresponding historical quantization parameter configurations. The historical structural feature vectors include historical layer type, number of input and output channels, and number of parameters. The historical activation statistical feature vectors include mean, variance, and sparsity. The historical quantization parameter configurations include bit width, quantization type, quantization dimension, weight, and activation quantization method.
[0094] For each network layer, based on the query vector group and each record in the historical record set, a comprehensive matching distance is calculated using a matching distance function: ; in, For the current unmatched number The network layer and the first The overall matching distance between historical records These are the weighting coefficients for the structural feature terms in the matching distance function. For the first The structural feature vectors of each network layer To quantify the configuration of the knowledge base The structural feature vector corresponding to each historical record. The weighting coefficients for the activation statistical feature terms in the matching distance function. the activation statistical feature vector of the first network layer, the activation statistical feature vector corresponding to the first historical record in the quantization configuration knowledge base, the weighting coefficient of the sensitivity score item in the matching distance function, the sensitivity score of the first network layer, the sensitivity score corresponding to the first historical record in the quantization configuration knowledge base, the square of the Euclidean distance.
[0095] The matching distance function in the embodiment is used to quantify the similarity between the current neural network layer features and the historical records in the knowledge base, which belongs to the common multi-dimensional feature vector distance weighted calculation method in the mathematical field, and its form is derived from the combination of Euclidean distance and absolute difference measure, wherein the structure feature vector , the activation feature vector and the sensitivity score are all dimensionless variables; by introducing the weighting factors , , , the formula realizes the flexible regulation of the importance of different feature dimensions, ensures the dimensional consistency of the physical quantities on both sides of the formula, and at the same time expands the adaptability and precision control ability of the traditional similarity measure formula in the low-bit quantization parameter configuration scene. Find the historical record number in the quantization configuration knowledge base that makes the comprehensive matching distance minimum, and determine the historical quantization parameter configuration corresponding to the historical record number as the initial quantization parameter configuration of the current network layer. The initial quantization parameter configurations matched by all network layers are summarized to form a complete initial quantization parameter set.
[0096] Step S43: Perform rule correction operation on each item in the initial quantization parameter set, judge the influence degree of the network layer on the quantization precision according to the sensitivity score of the corresponding network layer, if the sensitivity score of the network layer is higher than the preset sensitivity threshold, the initial bit width of the network layer is improved to reduce the precision loss caused by quantization, and the improvement of the bit width is carried out under the condition that the maximum bit width limit is not exceeded.
[0097] If the sensitivity score of the network layer does not exceed the preset sensitivity threshold, or the current bit width has reached the upper limit, the original configuration is kept unchanged. Through the above rule correction, the updated quantization parameter configuration is generated.
[0098] Step S44: According to the updated quantization parameter configuration of each network layer, the bit width, quantization type, quantization dimension, and weight and activation quantization mode corresponding to all network layers are sequentially summarized to construct a hierarchical quantization strategy set.
[0099] In step S5 of this embodiment, the hierarchical low-bit quantization operation is performed on the pre-trained target recognition neural network model according to the hierarchical quantization strategy set to generate a heterogeneous quantization neural network model, which specifically includes steps S51-S5: Step S51: For each network layer in the pre-trained target recognition neural network model, the corresponding quantization parameter configuration is extracted from the hierarchical quantization strategy set, including bit width, quantization type, quantization dimension, and weight and activation quantization mode.
[0100] Step S52: According to the bit width, quantization type, and quantization dimension in the quantization parameter configuration, the scaling factor and zero-point offset required for weight quantization of the network layer are calculated, and the weight quantization operation is performed to obtain a quantized weight tensor.
[0101] Specifically, according to the quantization parameter configuration corresponding to each network layer in the hierarchical quantization strategy set, the bit width, quantization type, and quantization dimension information are extracted, and the scaling factor and zero-point offset required for weight quantization are calculated, wherein the scaling factor is used to map the numerical range of the floating-point weight tensor to the integer representation interval, and the zero-point offset is used to adjust the integer range after quantization to make it symmetrically or asymmetrically distributed.
[0102] Based on the scaling factor and zero-point offset, the floating-point weight tensor of the network layer is discretized, converted to the corresponding fixed-point integer tensor through the rounding function, and the quantized weight tensor is obtained.
[0103] Step S53: According to the weight and activation quantization mode in the quantization parameter configuration, it is judged whether the current network layer adopts independent quantization mode, if the network layer is set to independent quantization, the activation tensor needs to be quantized separately, which specifically includes: calculating the scaling factor and zero-point offset according to the numerical distribution of the activation tensor, performing quantization mapping operation on the floating-point values in the activation tensor using the scaling factor and zero-point offset to obtain a quantized activation tensor, if the network layer does not adopt independent quantization mode, this step is skipped, and the activation tensor and the weight tensor share the same quantization parameter.
[0104] Step S54: The quantized weight tensor and the quantized activation tensor are combined to replace the weight tensor and the activation tensor of each network layer in the pre-trained target recognition neural network model, completing the low-bit quantization replacement of the network layer, and obtaining a hierarchical quantization network layer.
[0105] Step S55: combine all the layered quantization network layers obtained by the layered low-bit quantization processing to form a complete heterogeneous quantization neural network model, in which each network layer uses different quantization bit widths, quantization types or quantization dimensions.
[0106] In step S6 of this embodiment, the heterogeneous quantization neural network model is subjected to layered quantization perception training, and the precision-sensitive layers are subjected to key training and optimization, to obtain a heterogeneous quantization neural network model subjected to layered quantization perception training, which specifically includes steps S61-S65: Step S61: taking the heterogeneous quantization neural network model as a training starting point, extracting the quantization weight tensor and the quantization activation tensor of each network layer in the heterogeneous quantization neural network model, and the corresponding quantization parameter configuration in the layered quantization strategy set, to obtain an initial state of the heterogeneous quantization neural network model.
[0107] Step S62: based on the structured training sample set, performing layered quantization perception training on the heterogeneous quantization neural network model, and inserting a simulated quantization operation in the forward propagation path of each network layer, the simulated quantization operation being implemented by the following pseudo-quantization function: ; wherein, is a pseudo-quantization function, is a tensor to be quantized in the network layer of the heterogeneous quantization neural network model, including a weight tensor to be quantized or an activation tensor, which is an original floating-point tensor not subjected to quantization processing, is a scaling factor, is a zero-point offset value, is the minimum integer value that can be represented by the target bit width, which is determined according to the bit width setting in the layered quantization strategy, for example, 0 (symmetric quantization) or -128 (asymmetric quantization) under INT8, is the maximum integer value that can be represented by the target bit width, which is determined according to the bit width setting in the layered quantization strategy, for example, 255 (symmetric quantization) or 127 (asymmetric quantization) under INT8, is a rounding operation performed on the quantization mapping result, is an interval clipping operation performed on the round result.
[0108] The basic form of the pseudo-quantization function formula is derived from the fixed-point mapping principle in the field of computer science and the pseudo-quantization algorithm in deep learning. In this embodiment, the algorithm is refined and the structure is optimized for the actual application scenario of layered quantization and heterogeneous bit width based on the traditional fixed-point mapping formula.
[0109] In the pseudo-quantization function formula used in this embodiment, the tensor to be quantized and the zero-point offset All are floating-point numbers with the same numerical unit; scaling factor Used to map floating-point numbers to a dimensionless integer range, its unit is "the original numerical value corresponding to each integer step", hence the numerator With denominator Since the units are the same, dividing the two yields a dimensionless result; the integer tensor obtained through rounding and truncation operations corresponds to the upper and lower bounds of the quantization interval. and All are dimensionless integers; finally, during the reverse mapping, by multiplying by a scaling factor and adding zeros, the result is restored to be the same as the tensor to be quantized. The same numerical units are used; the physical dimensions of all physical quantities are consistent throughout the quantization and dequantization process, ensuring the physical meaning and numerical validity of the data.
[0110] Step S63: Calculate the layer loss weight coefficient for each network layer in the heterogeneous quantized neural network model based on structural features and sensitivity scores, and form a layer weight coefficient set by combining all layer loss weight coefficients. The layer loss weight coefficient is defined as: ; in, For the first The hierarchical loss weight coefficients of each network layer For the first Sensitivity score of each network layer To identify the total number of network layers in a neural network model for pre-training objectives, For the index of the network layer, For the first Sensitivity scores for each network layer.
[0111] Step S64: Based on the set of hierarchical weight coefficients, construct a hierarchical weighted loss function for training optimization. The hierarchical weighted loss function includes the localization error term and classification error term of each network layer, and integrates them by weighting through the corresponding weight coefficients.
[0112] Step S65: Based on the hierarchical weighted loss function, the heterogeneous quantized neural network model is iteratively trained using a stochastic gradient descent optimization algorithm. In each training round, forward propagation and backward propagation operations are performed to update the parameters. When the change in the hierarchical weighted loss function is lower than a preset threshold in several consecutive rounds, or the improvement in the accuracy of the validation set is lower than a set threshold, the training process is judged to have reached the convergence condition, the training is terminated, and the heterogeneous quantized neural network model after hierarchical quantization perception training is obtained.
[0113] In step S7 of the embodiment, deploying the heterogeneous quantization neural network model trained by the layered quantization perception training to a target hardware platform to perform a target recognition inference task specifically includes steps S71-S75: Step S71: exporting the heterogeneous quantization neural network model optimized by the layered quantization perception training to a deployment model compatible with the target hardware platform, wherein the weights and activations of each network layer in the deployment model are stored and calculated using different quantization parameter configurations according to the set of layered quantization strategies.
[0114] Step S72: loading the deployment model on the target hardware platform, configuring the memory allocation, batch size, input and output data format, and inference scheduling parameters of the deployment model according to the requirements of the platform running environment, and completing the deployment initialization of the model.
[0115] Step S73: data preprocessing of the test sample set to be inferred to generate standardized inference input data of the same specification as the structured training sample set.
[0116] Step S74: inputting the standardized inference input data into the deployment model, performing forward inference operation under low-bit quantization according to the quantization parameter configuration of each layer, and obtaining an inference output result set, each item of the inference output result set including the position, class label, and confidence of the target.
[0117] Step S75: performing summarization and post-processing operations on the inference output result set, calculating performance indicators including the accuracy, inference delay, and power consumption of target recognition, evaluating the inference effect of the deployment model under low-bit quantization based on the performance indicators, and verifying that the deployment model meets the requirements of high-precision, low-delay, and low-power target recognition inference.
[0118] Embodiment 2: To verify the feasibility of the application in implementation, the application is applied to a certain multi-class target recognition scene, and a public image dataset containing traffic signs, pedestrians, and vehicle target categories is selected as the basis for training and inference. The dataset contains 40,000 labeled image samples, covers high-density urban road scenes, has complex background and light interference, and can effectively test the performance of low-bit quantization models in real scenes.
[0119] In a specific implementation, first, the original image data is subjected to size normalization processing, and the annotation information is checked to construct a structured training sample set. Subsequently, a convolutional neural network is used to construct a target recognition model backbone, and structural feature information of each network layer is extracted, including layer type, channel number, activation distribution, and sensitivity score. Based on the extracted structural feature set, a self-defined structural sensitivity analysis function is called to generate a hierarchical quantization strategy set, including quantization bit width, quantization type (symmetric / asymmetric), and quantization dimension (channel-by-channel / layer-by-layer). Then, the optimal strategy combination is matched by consulting a knowledge base, and layer-by-layer quantization-aware training is performed to compensate for the accuracy loss caused by low bits, and a final heterogeneous quantization neural network model is obtained.
[0120] In the inference deployment link, the heterogeneous quantization model is deployed to an embedded AI chip platform to perform a target recognition task. In the test, 10,000 images are selected as inference samples, which are run on a full-precision model (FP32) and a low-bit heterogeneous quantization model (including 4-bit and 8-bit mixed precision) proposed by the present application. The inference accuracy, delay time, and power consumption are compared and evaluated. The results show that, under the premise of keeping the model structure unchanged, the inference delay of the heterogeneous quantization model constructed by the present application is reduced by about 34.7% and the overall energy consumption is reduced by about 41.2% under the condition that the inference accuracy is reduced by not more than 1.3%, which improves the execution efficiency of the target recognition system on the edge device.
[0121] The following table shows the performance comparison results of the method of the present application and the baseline model: Table 1 Comparison of inference performance based on heterogeneous low-bit quantization model As can be seen from the above table, the heterogeneous low-bit quantization model of the present application has advantages over the full-precision model and the traditional uniform quantization model in terms of multiple key performance indicators in the target recognition inference task. First, in terms of accuracy, the Top-1 accuracy of the heterogeneous quantization model reaches 90.1% under the configuration of INT4 and INT8 mixed precision, which is only 1.2 percentage points lower than that of the full-precision model, but is significantly better than the 89.2% of the INT8 full quantization model, indicating that the hierarchical quantization strategy driven by structural sensitivity can effectively suppress the recognition performance degradation caused by the decrease in quantization precision.
[0122] Secondly, in terms of inference delay, the average inference delay of the model proposed by the present application is 74.1 milliseconds, which is reduced by 34.7% compared with the delay of 113.4 milliseconds of the full-precision model, and is reduced by 12.4% compared with the INT8 full quantization model. The results show that the hierarchical heterogeneous quantization strategy can improve the inference execution efficiency on the basis of ensuring the recognition accuracy, and is especially suitable for scenarios where the edge processing unit has high requirements for real-time response.
[0123] Finally, in terms of power consumption, the average running power consumption of the heterogeneous quantization model is 3.10 watts, which is reduced by 41.3% compared with 5.28 watts of the full-precision model, and also reduced compared with the INT8 full quantization model, fully illustrating the advantages of the method in terms of energy efficiency. As can be seen from the above, the method of the application not only takes into account the accuracy and speed, but also greatly reduces the hardware running power consumption, and is suitable for deployment in application scenarios that are limited in resources but sensitive to accuracy.
[0124] In summary, the target recognition model inference optimization method and device of the application first performs structural analysis and sensitivity evaluation on the pre-trained model, extracts the structural feature vector, activation distribution feature vector and quantization sensitivity score of each network layer, and constructs a data set that can accurately reflect the characteristics and fault tolerance of each level. Based on the data set, query the quantization configuration knowledge base, and dynamically generate the optimal heterogeneous quantization strategy set for different network layers through the preset mapping rule. Finally, according to the strategy, perform layered low-bit quantization operation, and further optimize the model through the quantization-aware training of the layered weighted loss function, effectively compensating for the accuracy loss caused by bit width compression. The application realizes high compression ratio and significant acceleration through the layered heterogeneous quantization strategy, maximizes the key recognition accuracy of the model, especially protects the performance of the high-sensitive layer. The generated heterogeneous quantization model significantly reduces the memory occupation and computing power, so that it can be efficiently deployed on resource-limited edge hardware platforms. The whole method forms a complete and automated process from analysis, configuration to training compensation, has strong universality and high engineering practical value, and provides reliable technical support for real-time, efficient and low-power inference of complex visual tasks on the edge side.
[0125] Those of ordinary skill in the art should understand that the exemplary components, systems and methods described in connection with the embodiments disclosed herein can be implemented in hardware, software, or a combination of both. Whether the implementation is in hardware or software depends on the specific application and design constraints imposed on the overall system. Those of skill can use various approaches to implement the described functionality depending on the specific application and design constraints. Such implementation should not be interpreted as causing a departure from the scope of the application. When implemented in hardware, the hardware can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), suitable firmware, a plug-in, a functional card, etc. When implemented in software, the elements of the application are the program or code segments to perform a specific task. The program or code segments can be stored in a machine-readable medium, or transmitted by a data signal carried in a carrier wave over a transmission medium or communication link.
[0126] It is to be expressly understood that the invention is not limited to the specific configurations and process described above and illustrated in the accompanying drawings. For the sake of clarity, detailed descriptions of known methods are omitted. In the above-described embodiments, several specific steps are described and illustrated as examples. However, the method processes of the present invention are not limited to the specific steps described and illustrated, and various changes, modifications and additions can be made thereto by one of ordinary skill in the art without departing from the spirit of the present invention, and the order of the steps can be changed.
[0127] In the present invention, features described and / or illustrated with respect to one embodiment can be used in the same or a similar way in one or more other embodiments, and / or in combination with or instead of features of other embodiments.
[0128] The above description is only preferred embodiments of the present invention, and is not intended to limit the present invention. The embodiments of the present invention can be variously changed and modified by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of the present invention.
Claims
1. A method for inference optimization of a target recognition model based on neural network low-bit quantization, characterized in that, The method comprises the following steps: obtaining a data set containing multiple samples for a specified target recognition task, each of the samples containing original image data and a bounding box position and a class label annotated for multiple target objects therein; performing structural analysis on the target recognition model to be optimized, extracting layer types, layer position indexes, input channel numbers, output channel numbers, parameter amounts, and connection relationships of front and back of each network layer to construct a structural feature vector; performing multiple rounds of forward inference operations on the target recognition model based on the data set, taking the output of each network layer as an activation tensor, and calculating an activation distribution feature vector containing activation mean, activation variance, and activation sparsity of each network layer; calculating a sensitivity score for each network layer using a quantitative disturbance evaluation; and constructing the structural feature vector, the activation distribution feature vector, and the sensitivity score of each network layer into a structural feature and sensitivity data set; querying a preset quantitative configuration knowledge base based on the structural feature and sensitivity data set, generating a hierarchical quantization strategy set for each network layer by matching a preset mapping rule, performing hierarchical low-bit quantization operations on the target recognition model to generate a heterogeneous quantization neural network model, and performing hierarchical quantization perception training on the heterogeneous quantization neural network model using the data set to obtain an optimized target recognition model for deployment to a target hardware platform.
2. The neural network low-bit quantization based target recognition model inference optimization method according to claim 1, characterized in that, Before performing structural analysis on the target recognition model to be optimized, the method further comprises: obtaining a training sample set containing multiple samples, each of the samples containing a sample image and a bounding box position and a class label annotated for multiple sample objects therein; training an initial recognition model using the training sample set, inputting the sample image into the initial recognition model to output a prediction of the bounding box position and the class of the sample object, constructing a joint loss function based on a bounding box position loss and a classification loss, minimizing the joint loss function to update parameters of the initial recognition model to obtain the target recognition model to be optimized; the calculation formula of the joint loss function is: ; in, Let the joint loss function be... The number of samples in the training sample set. For sample index, For the first The number of sample objects contained in the sample image described above. For the index of the sample object, The weighting coefficients for the bounding box position loss are: For the bounding box position loss, Smooth L1 loss or IoU loss is used; For the model to the first The sample image described above is the first one. The predicted bounding box positions of the sample objects. For the first The sample image described above is the first one. The true bounding box positions of the sample objects. The weighting coefficients for the classification loss are... For the classification loss, cross-entropy loss is used. For the model to the first The sample image described above is the first one. The predicted category of each sample object. For the first The first sample image The true category labels of the sample objects.
3. The neural network low-bit quantization based target recognition model inference optimization method according to claim 1, characterized in that, calculating a sensitivity score for each network layer using a quantitative disturbance evaluation, comprising: keeping the parameters of the remaining network layers of the target recognition model unchanged, and only performing a low-bit quantization operation on a single network layer to be evaluated; using the quantized target recognition model to perform inference on the data set, recording the change amplitude of the recognition accuracy and dividing it by the parameter amount of the network layer to be evaluated to obtain the sensitivity score.
4. The neural network low-bit quantization based target recognition model inference optimization method according to claim 1, characterized in that, querying a preset quantitative configuration knowledge base based on the structural feature and sensitivity data set, generating a hierarchical quantization strategy set for each network layer by matching a preset mapping rule, comprising: obtaining corresponding quantization parameter configurations in the quantitative configuration knowledge base by matching and querying the structural feature and sensitivity data set, obtaining an initial quantization parameter set including quantization bit width, quantization type, quantization dimension, and quantization method; If the sensitivity score of the network layer is higher than a preset value, the initial bit width of the network layer is increased without exceeding a preset maximum bit width limit; if the sensitivity score of the network layer is less than or equal to the preset value or the current bit width has reached an upper limit, the original configuration is kept unchanged; and the initial quantization parameter configuration of each network layer is obtained by performing the modification operation on each item in the initial quantization parameter set, thereby obtaining an updated quantization parameter configuration of each network layer. The updated quantization parameter configurations of all network layers are summarized to obtain the set of hierarchical quantization strategies.
5. The method of claim 4, wherein the method further comprises: The corresponding quantization parameter configuration in the quantization configuration knowledge base is obtained by matching the structure feature and sensitivity data set, including: The structure feature and sensitivity data set are used as a query vector group, each historical structure feature vector, historical activation statistical feature vector and historical sensitivity score in each historical configuration record in the quantization configuration knowledge base are used as a queried item, and the corresponding historical quantization parameter configuration is used as a verified quantization sample; The comprehensive matching distance between the query content of each network layer in the query vector group and the queried item is calculated by using a matching distance function, and the calculation formula is: ; wherein, is a comprehensive matching distance between the current to-be-matched network layer and the i-th verified quantized sample, is a weighting coefficient of a structural feature item, is a structural feature vector of the i-th network layer, is a weighting coefficient of an activation statistical feature item, is the activation distribution feature vector of the i-th network layer, is a weighting coefficient of a sensitivity score item, is the sensitivity score of the i-th network layer, is a weighting coefficient of a sensitivity score item, is the sensitivity score of the i-th network layer, is a weighting coefficient of a sensitivity score item, is the sensitivity score of the i-th network layer, is a weighting coefficient of a sensitivity score item, is the sensitivity score of the i-th network layer, is a weighting coefficient of a sensitivity score item, is the sensitivity score of the i-th network layer, is a weighting coefficient of a sensitivity score item, is the sensitivity score of the i-th network layer, is a weighting coefficient of a sensitivity score item, is a square of a Euclidean distance; The verified quantization sample with the minimum matching distance of the query content of the network layer is determined, and the corresponding historical quantization parameter configuration is used as the initial quantization parameter configuration of the current network layer, and the initial quantization parameter set of all network layers is obtained by summarizing.
6. The neural network low-bit quantization based target recognition model inference optimization method according to claim 1, characterized in that, The hierarchical low-bit quantization operation is performed on the target recognition model to generate a heterogeneous quantization neural network model, including: The quantization parameter configuration is extracted from the set of hierarchical quantization strategies for each network layer in the target recognition network, and the quantization parameter configuration includes bit width, quantization type, quantization dimension and quantization mode of weight and activation; The scaling factor and zero point offset required for weight quantization of the network layer are calculated according to the bit width, the quantization type and the quantization dimension, and the weight quantization operation is performed to obtain a quantized weight tensor; wherein the scaling factor is used to map the numerical range of the floating-point weight tensor to the integer representation interval, and the zero point offset is used to adjust the integer range after quantization to make it symmetrically or asymmetrically distributed; According to the quantization mode of the weight and the activation, it is judged whether the current network layer adopts independent quantization, if the network layer is set to independent quantization, the activation tensor needs to be quantized separately, including: calculating the scaling factor and the zero point offset according to the numerical distribution of the activation tensor, performing quantization mapping operation on the floating-point values in the activation tensor using the scaling factor and the zero point offset to obtain a quantized activation tensor, if the network layer does not adopt independent quantization, the step is skipped, and the activation tensor and the quantized weight tensor share unified quantization parameters; The quantized weight tensor and the quantized activation tensor are combined to replace the weight tensor and the activation tensor of each network layer in the target recognition model, the low-bit quantization replacement of the network layer is completed, and a hierarchical quantization network layer is obtained. The layered quantization network layers obtained through the layered low-bit quantization processing are combined to obtain the heterogeneous quantization neural network model.
7. The neural network low-bit quantization based target recognition model inference optimization method according to claim 1, characterized in that, The hierarchical quantization-aware training of the heterogeneous quantization neural network model using the data set obtains the optimized target recognition model, including: During the forward propagation process of the hierarchical quantization-aware training of the heterogeneous quantization neural network model based on the data set, an analog quantization operation is inserted in each network layer, and the analog quantization operation is implemented through the following pseudo-quantization function: ; wherein, is the pseudo-quantization function, is a tensor to be quantized in the network layer of the heterogeneous quantization neural network model, including the weight tensor or the activation tensor to be quantized; is the scaling factor, is the zero-point offset, is the minimum integer value that can be represented by the target bit width, is the maximum integer value that can be represented by the target bit width; is a rounding operation performed on the quantization mapping result, is an interval clipping operation performed on the result after the rounding operation; During the back propagation process, a hierarchical loss weight coefficient is calculated for each network layer in the heterogeneous quantization neural network model according to the sensitivity score, and the calculation formula is: ; in, In the heterogeneous quantization neural network model, the first... The hierarchical loss weight coefficients of each network layer In the heterogeneous quantization neural network model, the first... Sensitivity score of each network layer The total number of network layers. This refers to the index of the network layer in the heterogeneous quantized neural network model. In the heterogeneous quantization neural network model, the first... Sensitivity scores for each network layer; Based on the hierarchical loss weight coefficient of each network layer in the heterogeneous quantization neural network model, the positioning error term and the classification error term of the loss function in the back propagation process are weighted and integrated to obtain a hierarchical weighted loss function; and based on the hierarchical weighted loss function, the heterogeneous quantization neural network model is iteratively trained using a stochastic gradient descent until convergence, thereby obtaining the optimized target recognition model.
8. A neural network low-bit quantization-based target recognition model inference optimization apparatus, comprising a processor, a memory, and a computer program or instructions stored on the memory, characterized in that, The processor is configured to execute the computer program or instruction, and when the computer program / instruction is executed, the device implements the steps of the method according to any one of claims 1 to 7.
9. A computer readable storage medium having stored thereon a computer program or instructions, characterized in that, The computer program or instruction is executed by the processor to implement the steps of the method according to any one of claims 1 to 7.
10. A computer program product comprising computer programs or instructions, characterized in that, The computer program or instruction is executed by the processor to implement the steps of the method according to any one of claims 1 to 7. The computer program or instruction is executed by the processor to implement the steps of the method according to any one of claims 1 to 7.
Citation Information
Cited By
Risk perception neural network quantification method and device for aero-engine health management
CN121920453A
Low-bit quantization method, system and device for YOLO target detection model and medium
CN122024012A
A low-bit quantization method, system, device and medium for a YOLO target detection model
CN122024012B
Multi-strategy fusion layered optimization CV model quantification method and system
CN122047390A
Mixed precision model inference acceleration method and system applied to large language model
CN122242780A
