A lightweight target detection method based on dynamic weight pruning
By co-optimizing dynamic weight pruning and structured pruning, a lightweight target detection model is generated, which solves the real-time detection problem in resource-constrained scenarios in existing technologies, and achieves efficient model compression and adaptive real-time inference while maintaining detection accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING INST OF INTELLIGENT TECH INST OF MICROELECTRONICS OF THE CHINESE ACAD OF
- Filing Date
- 2026-05-27
- Publication Date
- 2026-07-31
AI Technical Summary
Existing target detection models struggle to achieve real-time detection in resource-constrained scenarios. Static pruning cannot adapt to different input scenarios, structured pruning is prone to network structure conflicts, multi-stage lightweight processes are complex and accumulate errors, and dynamic pruning has high computational overhead, leading to a decrease in detection accuracy.
A dynamic weighted pruning method is adopted, which generates a layer-by-layer dynamic pruning threshold through comprehensive importance evaluation, performs layer-by-layer and channel-by-channel collaborative pruning in combination with the input image complexity index, and performs adaptive quantization during the end-to-end optimization process to generate a lightweight object detection model.
While ensuring detection accuracy, the model achieves efficient compression and hardware-friendly deployment, supports real-time inference with adaptive input, and reduces waste of computing resources and error accumulation.
Smart Images

Figure CN122493069A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of deep learning and edge computing technology, and in particular to a lightweight target detection method based on dynamic weight pruning. Background Technology
[0002] Object detection technology is widely used in scenarios such as drone inspection, autonomous driving, mobile robots, intelligent security, and industrial inspection. In recent years, deep learning-based object detection models, such as the YOLO series, SSD, and Faster R-CNN, have achieved significant improvements in detection accuracy. However, these models typically have a large number of network layers, a large number of parameters, and high computational costs, often requiring high-performance graphics processing units (GPUs) for real-time inference.
[0003] In resource-constrained scenarios such as drones, mobile robots, and embedded edge computing platforms, computing power, storage space, and battery capacity are all severely limited. Directly deploying large-scale object detection models would result in high inference latency, high power consumption, and significant device overheating, making it difficult to meet real-time detection requirements. Therefore, lightweighting object detection models to enable them to run efficiently on edge devices has become a hot research topic.
[0004] Existing lightweight technologies mainly include model pruning, model quantization, knowledge distillation, and lightweight network structure design. Among them, model pruning has received widespread attention due to its intuitive principle and significant compression effect. The core idea of model pruning is to remove unimportant weights, channels, or network layers from the model, thereby reducing the number of parameters and computational cost. Depending on the pruning granularity, pruning methods can be divided into unstructured pruning and structured pruning. Unstructured pruning removes weights at a single weight level, easily generating sparse matrices. However, conventional GPUs, tensor processors (TPUs), and embedded inference frameworks struggle to efficiently utilize this irregular sparse structure, resulting in only a minor improvement in actual inference speed. Structured pruning removes weights, convolutional kernels, or network layers at a time. The pruned model maintains a regular dense tensor format, which is more conducive to hardware acceleration.
[0005] However, existing model pruning methods still have the following technical problems.
[0006] First, static pruning is difficult to adapt to different input scenarios. Existing static pruning methods typically determine the pruning targets based on the absolute value of the weights, the L1 norm, or a preset fixed threshold. Before pruning, the pruning ratio or threshold needs to be manually set, and the model structure is fixed after pruning. For simple images, a fixed model may waste computational resources; for complex images, over-pruning may lead to the loss of key features, resulting in missed detections or false detections.
[0007] Second, structured pruning can easily cause network structure conflicts. When structured pruning is performed on a channel or network layer basis, if the input and output dimensions between adjacent layers are not adjusted synchronously, network structure mismatch can easily occur. For example, after the output channel of the current convolutional layer is pruned, the input channels of the next convolutional layer also need to be adjusted synchronously; otherwise, the model cannot perform inference correctly. Existing structured pruning methods often require complex dimension matching logic, increasing the difficulty of deployment.
[0008] Third, multi-stage lightweight quantization processes are complex and prone to error accumulation. Existing methods combining pruning and quantization typically employ a multi-stage sequential process of "pruning-fine-tuning-quantization-further fine-tuning." This process has a long training cycle, numerous hyperparameters, and the pruning and quantization errors may overlap, leading to a significant decrease in model detection accuracy.
[0009] Fourth, dynamic pruning methods incur significant additional computational overhead. While some dynamic pruning methods can adjust the model structure based on input features, their dynamic decision-making process itself may introduce substantial computational costs. If poorly designed, this can negate the speedup benefits of pruning.
[0010] Therefore, how to achieve efficient model compression, hardware-friendly deployment, and real-time inference with adaptive input while ensuring detection accuracy is a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0011] The purpose of this invention is to provide a lightweight target detection method based on dynamic weight pruning, in order to solve at least some of the problems existing in the prior art.
[0012] Technical solution: A lightweight target detection method based on dynamic weight pruning, comprising the following steps:
[0013] Obtain the training image dataset and the initial object detection model;
[0014] The training image dataset is input into the initial object detection model, dynamic weight importance evaluation is performed, and a comprehensive importance score is generated;
[0015] Based on the comprehensive importance score and the complexity index of the input image, a layer-by-layer dynamic pruning threshold is generated;
[0016] Based on the layer-by-layer dynamic pruning threshold and comprehensive importance score, structured pruning is performed in a layer-by-layer and channel-by-channel manner, and the input-output dimensions between adjacent network layers are adjusted to obtain the structured pruned model.
[0017] Pruning constraints are embedded into the target detection loss function, and end-to-end joint optimization is performed on the structured pruned model. Adaptive quantization is performed during the joint optimization process to generate a lightweight target detection model.
[0018] A lightweight object detection model is deployed to edge computing devices. During the inference stage, the number of activated network layers, the proportion of channels retained, or the quantization precision are dynamically adjusted according to the complexity of the input image to output object detection results.
[0019] Beneficial effects: This invention achieves real-time inference with adaptive input by optimizing dynamic weight pruning and structured pruning in a coordinated manner, thereby reducing model size and improving inference speed. Attached Figure Description
[0020] Figure 1 This is a flowchart of the overall solution of the present invention.
[0021] Figure 2 This is a flowchart of the process for generating a comprehensive importance score in this invention.
[0022] Figure 3 This is a flowchart illustrating the generation of layer-by-layer dynamic pruning thresholds in this invention.
[0023] Figure 4 This is a flowchart of the structured pruning model obtained by the present invention.
[0024] Figure 5 This is a flowchart of the target detection results output by the present invention. Detailed Implementation
[0025] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0026] like Figures 1-5 As shown, this embodiment describes in detail the data processing flow of a lightweight target detection method based on dynamic weight pruning, specifically including:
[0027] S1: Obtain the training image dataset and the initial object detection model.
[0028] In this application, the first step is to obtain an image dataset for training the object detection model and a pre-trained initial object detection model. Specifically, the acquired training image dataset contains a large number of image samples with real bounding boxes and category labels. These samples originate from real-world application scenarios of object detection tasks, such as drone aerial photography, road traffic monitoring, or industrial defect detection. For example, the training image dataset can use public datasets such as COCO or VOC, or custom scene data can be collected based on the specific deployment environment. Further, after obtaining the training image dataset, standardized preprocessing operations are performed. Preprocessing includes: uniformly scaling all images to a preset resolution, such as 640×640 pixels; normalizing each pixel value, for example, dividing by 255 to make its value range fall within the [0,1] interval; and performing random data augmentation operations, such as random horizontal flipping, color jittering, and Mosaic blending enhancement, to expand data diversity and improve the model's generalization ability. After preprocessing, the enhanced training image tensor and its corresponding annotation information are obtained.
[0029] On the other hand, the acquired initial object detection model is a detection architecture built on convolutional neural networks, such as the YOLO series, SSD, or Faster R-CNN. This model has been pre-trained on a large-scale dataset, and its network structure includes multiple convolutional layers, batch normalization layers, and detection heads (classification and regression branches). In an optional implementation, the weight parameters of the initial object detection model are stored with floating-point precision (e.g., FP32) and include structural information such as the number of input channels, the number of output channels, the kernel size, and the stride for each convolutional layer. The purpose of obtaining this information is to provide a basic structural reference for subsequent pruning operations.
[0030] S2: Input the training image dataset into the initial object detection model, perform dynamic weight importance evaluation, and generate a comprehensive importance score.
[0031] After preparing the data and model, the preprocessed training image tensors are input into the initial object detection model to perform dynamic weight importance evaluation, generating a comprehensive importance score for each channel in each convolutional layer. According to a further improvement in this embodiment, this evaluation process integrates the channel attention mechanism in forward propagation and the gradient sensitivity analysis in backpropagation, thereby achieving a multi-dimensional characterization of channel importance.
[0032] Specifically, during the forward propagation process, the feature map output from each convolutional layer is extracted and denoted as a tensor of shape C×H×W, where C is the number of channels, and H and W are the height and width, respectively. For each channel's feature map, global average pooling and global max pooling operations are performed simultaneously: global average pooling outputs the pixel mean across all spatial locations of that channel, and global max pooling outputs the maximum response value of that channel. These two pooling results are concatenated into a two-dimensional vector, which is then fed into a lightweight shared multilayer perceptron (consisting of two fully connected layers with a non-linear activation function in between). Finally, the vector is mapped to the 0-1 interval using the sigmoid function to obtain the attention weight coefficients for each channel. The attention weight coefficients indicate the relative importance of that channel for the object detection task in the current input image: the larger the value, the more key features that channel carries.
[0033] In parallel, during backpropagation, the gradient of the object detection loss function with respect to the output feature map of each channel is calculated. Specifically, the partial derivatives of the loss function with respect to each spatial location on the feature map are first calculated. Then, the absolute values of the gradients at all spatial locations within the same channel are summed and averaged to obtain a scalar value, which is the gradient sensitivity score for that channel. The gradient sensitivity score characterizes the degree to which changes in the output of that channel affect the final loss value: a higher score indicates a more significant contribution of that channel to the detection accuracy.
[0034] Next, the attention weight coefficients and gradient sensitivity scores for each channel are weighted and fused. In a preferred embodiment, the fusion method is a weighted sum: Overall Importance Score = α × Attention Weight Coefficient + β × Gradient Sensitivity Score, where α and β are preset balancing coefficients, for example, 0.5 and 0.5 respectively. Alternatively, a product form can be used, i.e., Overall Importance Score = Attention Weight Coefficient × Gradient Sensitivity Score. Finally, an overall importance score vector of the same length as the number of channels in each convolutional layer is output.
[0035] S3: Generate a layer-by-layer dynamic pruning threshold based on the comprehensive importance score and the complexity index of the input image.
[0036] After obtaining the comprehensive importance score for each channel, it is necessary to further combine it with the complexity index of the current input image to independently generate a dynamic pruning threshold for each convolutional layer. In this scheme, the dynamic pruning threshold is not a pre-set fixed value, but rather adapts to the content of the input image to achieve on-demand allocation of computing resources.
[0037] First, a complexity metric is extracted from the currently input training image. For example, the complexity metric could be image information entropy, which is the entropy value calculated after performing probability statistics on the image's gray-level histogram. A higher entropy value indicates richer image texture and a more complex scene. Alternatively, an edge density metric can be used: first, the Canny operator is used to detect image edges, and the proportion of edge pixels to total pixels is calculated; a higher proportion indicates a more complex image structure. In an optional implementation, a very lightweight auxiliary network (e.g., a small classifier containing only two depthwise separable convolutional layers) can be introduced to output scene complexity levels, such as three categories: "simple," "normal," and "complex."
[0038] Then, the complexity index of the current image, the distribution parameters of the comprehensive importance score of each channel in the current convolutional layer (e.g., mean μ and standard deviation σ), and the user-preset target compression ratio (e.g., expecting to reduce the floating-point operation of the model by 40%) are input into a dynamic threshold generation function. One implementation of this function is based on an adaptive calculation method using percentiles: First, the preset baseline percentile is linearly modulated according to the complexity index. For example, if the baseline percentile p0 = 50%, when the complexity index is low, the percentile is increased to 70% or even 80%, and when the complexity index is high, the percentile is decreased to 30%. Then, the p-th percentile of the comprehensive importance score vector of the current layer is calculated, and the calculated value is used as the pruning threshold for that layer.
[0039] In this embodiment, the dynamic threshold generation function outputs a layer-specific pruning threshold for each convolutional layer. The simpler the input image (lower complexity), the higher the output pruning threshold, allowing more redundant channels to be removed and reducing computational cost. Conversely, the more complex the input image, the lower the output pruning threshold, preserving more critical channels and ensuring no loss of detection accuracy. Finally, the pruning thresholds for all convolutional layers are compiled into a layer-by-layer dynamic pruning threshold list for use in subsequent structured pruning steps.
[0040] S4: Based on the layer-by-layer dynamic pruning threshold and comprehensive importance score, perform structured pruning with layer and channel coordination, and adjust the input and output dimensions between adjacent network layers to obtain the structured pruned model.
[0041] Based on the generated comprehensive importance score and layer-by-layer dynamic pruning threshold, a structured pruning operation is performed in coordination between layers and channels. During the pruning process, the input and output dimensions between adjacent network layers are adjusted synchronously, and finally a structured pruned model with a regular structure that can be directly used for hardware acceleration is output.
[0042] Specifically, for the current convolutional layer to be processed, all its channels are first sorted in descending order of their overall importance score. Then, channels with importance scores below the layer's dynamic pruning threshold are marked as "channels to be pruned." In a preferred embodiment, the proportion of channels to be pruned also needs to be evaluated: if the number of channels to be pruned in a layer exceeds a preset upper limit (e.g., 80% of the total number of channels in that layer), then the layer is considered to have a low overall contribution. In this case, instead of performing piecemeal channel pruning, hierarchical pruning is directly performed: the layer is marked as a layer to be pruned, and during subsequent inference, it is skipped using an identity mapping or replaced with a lightweight skip connection.
[0043] If the proportion of channels to be pruned does not exceed the upper limit, channel pruning is performed. Specifically, all convolutional kernels corresponding to the channels to be pruned are physically removed from the weight matrix of the current convolutional layer (for output channel pruning, the corresponding filter in the output channel dimension is removed; for input channel pruning, processing is combined with the output of the previous layer). After deletion, the pruned weight matrix is obtained, and the number of output channels in this layer is reduced accordingly.
[0044] To ensure proper forward propagation of the pruned network, the input channel dimensions of subsequent layers must be adjusted synchronously. To this end, this scheme generates a pruning map table based on the pruning operation records, which records the indices of the deleted output channels in each layer. Then, according to the pruning map table, all convolutional layers or batch normalized layers following the current layer are traversed, and the portions of their input channel dimensions corresponding to the deleted channels are also deleted. For example, if the current convolutional layer (layer L) originally had 128 output channels, and after pruning retains 96, with the 32 deleted channels having indices [5, 12, ...], then the subsequent (L+1)th convolutional layer, which originally expected to have 128 input channels, now needs to delete the channels with indices [5, 12, ...] in its input weight matrix, reducing its input channel count to 96. This dimension matching adjustment process ensures the integrity of the network structure and avoids inference errors caused by dimension mismatch.
[0045] After hierarchical and channel pruning, and dimensional matching between adjacent layers, the structured pruned model can be output. This model has significantly fewer parameters and lower computational cost compared to the initial model, and the weight matrix maintains a regular, dense structure, making it highly suitable for efficient operation on parallel computing hardware such as GPUs, TPUs, or NPUs.
[0046] S5: Embed the pruning constraints into the target detection loss function, perform end-to-end joint optimization on the structured pruned model, and perform adaptive quantization during the joint optimization process to generate a lightweight target detection model.
[0047] After obtaining the structured pruned model, this application further embeds the pruning constraints into the target detection loss function, performs end-to-end joint optimization on the model, and performs adaptive quantization during the optimization process, finally generating a lightweight target detection model that is both lightweight and maintains high detection accuracy.
[0048] First, construct the joint optimization loss function, which has the following form: L total =L detection +λ1·L sparsity +λ2·L quant_error ; among which, L detection This is the original object detection loss, including the classification cross-entropy loss and the Smooth L1 loss for bounding box regression, used to ensure the model's basic detection performance. sparsity This is the pruning sparsity regularization term, which can be the sum of the L1 norms of all channel selection gates, or the L0 approximation of all pruning masks. Its function is to drive the model to automatically learn a sparser and easier-to-prune weight structure. quant_error This is the quantization error estimation term, used to simulate the mean square error generated during the quantization of weights and activation values from floating-point to low-precision integers (such as INT8 or INT4), thereby compensating for precision loss in advance. λ1 and λ2 are balance coefficients.
[0049] The structured pruned model is trained end-to-end on the complete training image dataset. In each iteration, parameters are not physically deleted; instead, the pruning effect is simulated using masks: a mask value of 0 indicates that the channel has been pruned, and the outputs of these channels are set to zero during forward propagation; during backward propagation, the gradients corresponding to the masked channels do not participate in weight updates. Simultaneously, according to the joint loss function L... total The gradient is calculated, and the model's weight parameters are updated. At a predetermined number of iterations (e.g., every 5 epochs), S2 and S3 are re-executed based on the updated weight and gradient distributions. The overall importance score and layer-by-layer dynamic pruning threshold are recalculated, and the pruning mask is updated synchronously. This mechanism allows the pruning structure and model parameters to adapt to each other, achieving true joint optimization.
[0050] After the joint optimization reaches the preset convergence progress (e.g., 80% of the total training rounds are completed), the adaptive quantization module is activated. Specifically, the weight and activation value distributions of each convolutional layer are analyzed, and statistical characteristics such as dynamic range and outlier ratio are calculated. For layers with concentrated numerical distributions and sensitive to quantization errors (usually shallow layers and detectors of the network), INT8 quantization is selected; for layers with broad numerical distributions and less sensitive to precision (usually deep, high-channel layers of the network), INT4 or even INT2 quantization is selected, thus achieving mixed-precision quantization. An intermediate model is output, which includes mixed-precision integer weights, a pruning mask table, and quantization parameters (scaling factor and zero offset) for each layer.
[0051] To further recover the accuracy loss introduced by quantization, quantization-aware training (QAT) is performed after outputting the intermediate model: low-precision computation is simulated in the forward propagation (i.e., weights and activation values are quantized and then dequantized), while the backpropagation still uses floating-point gradients to update the weights. After several rounds of fine-tuning, the final lightweight object detection model fine-tuned by quantization-aware training is output. This model is small in size, computationally fast, and maintains detection accuracy close to that of the original model.
[0052] S6: Deploy the lightweight object detection model to edge computing devices. During the inference stage, dynamically adjust the number of activated network layers, the proportion of retained channels, or the quantization precision based on the complexity of the input image, and output the object detection results.
[0053] The generated lightweight object detection model is deployed to target edge computing devices, such as NVIDIA Jetson series, Raspberry Pi, mobile application processors, or embedded AI accelerator cards. During the real-time inference phase, the model dynamically adjusts the number of activated network layers, the proportion of channels retained, and the quantization precision based on the complexity of the input image, thereby achieving a dynamic balance between computational load and detection accuracy.
[0054] Specifically, for each input image frame, the image complexity is first rapidly evaluated using a very lightweight complexity prediction module. This module can be a miniature network containing only two depthwise separable convolutional layers, and its output is a scalar complexity score, ranging from 0 to 1, with a higher score indicating more complex image content. Alternatively, the complexity score can be calculated directly from the image information entropy or edge density to avoid additional computational overhead.
[0055] Based on the complexity score, a three-level scheduling strategy is implemented: When the complexity score is below the first threshold (e.g., 0.3), it is classified as a simple scene (e.g., an empty background, a single target). In this case, an aggressive pruning mask is forced to be applied: this mask retains fewer channels compared to the default pruning mask (e.g., only 30% of the original channels), and all layers of the model are forced to use INT4 quantization. This minimizes computation and energy consumption, suitable for rapid screening scenarios. When the complexity score is above the second threshold (e.g., 0.7), it is classified as a complex scene (e.g., dense crowds, mixed categories). In this case, a model structure retaining more channels is used (e.g., retaining 80% of the original channels), and all layers are forced to use INT8 quantization to ensure detection accuracy. When the complexity score is between the first and second thresholds, the default pruning mask (retaining approximately 60% of the channels) and default INT8 quantization are used to achieve a balance between accuracy and speed.
[0056] After complexity assessment and scheduling strategy selection, the input image tensor is fed into the lightweight object detection model for dynamic inference. During inference, based on pre-defined masks and quantization precision, efficient computation scheduling is achieved at the underlying level through the operator fusion function of the inference engine (such as TensorRT, TFLite, or OpenVINO). Finally, the model outputs object detection results, including the bounding box coordinates, class label, and confidence score for each detected object.
[0057] Furthermore, in an optional implementation, the changing trend of the overall importance score of each channel can be continuously monitored during the joint optimization or inference phase. If the importance score of a channel remains below a global dynamic threshold for multiple consecutive iterations (e.g., 10 consecutive epochs or 500 consecutive frames of inference), a permanent pruning tag is generated for that channel. In subsequent training or inference, the computation of all channels with permanently pruned tags is skipped, thereby further reducing runtime overhead.
[0058] According to another aspect of this application, the steps for generating a comprehensive importance score include:
[0059] S21: During the forward propagation process, the output feature map of the convolutional layer is extracted, global average pooling and global max pooling are performed, and the pooling results are activated by a shared multilayer perceptron and a sigmoid to obtain the channel attention weight coefficients.
[0060] In one specific embodiment of this application, dynamic weight importance evaluation first captures the feature response intensity of each channel to the current input image through a channel attention mechanism in forward propagation. Specifically, the preprocessed training image tensor is input into the initial object detection model. After the forward computation of each convolutional layer is completed, the feature map output by that layer is extracted. This feature map can be represented as a three-dimensional tensor with dimensions C×H×W, where C represents the number of channels, and H and W represent the height and width of the feature map, respectively. For each independent channel c (c ranges from 1 to C), two pooling operations are performed on its feature map: global average pooling and global max pooling. The global average pooling is calculated by summing the activation values at H×W spatial locations within the channel and dividing by the total area to obtain a scalar value, denoted as Avg. c Global max pooling directly takes the maximum value at all positions within the channel, denoted as Max. c . Avg c and Max c The input vectors are concatenated into a single vector of length 2, which is then fed into a lightweight shared multilayer perceptron. This perceptron consists of two fully connected layers. The first fully connected layer expands the input dimension from 2 to C / r, where r is the compression ratio (typically 16), using the ReLU non-linear activation function. The second fully connected layer restores the dimension from C / r back to 2, outputting two scalars. Finally, these two scalars are concatenated with the original Avg vector. c and Max c After multiplying and adding, the result is passed through a Sigmoid activation function and mapped to the 0-1 interval to obtain the attention weight coefficient for that channel, denoted as A. c In an alternative implementation, global average pooling or global max pooling alone can be used, but using both in combination can preserve both global semantic information and local saliency information, resulting in better performance. The attention weight coefficients of all channels form a vector of length C, which dynamically changes with the input image, reflecting the model's attention to each channel of the current input.
[0061] S22: During backpropagation, the gradient of the loss function relative to the output feature map is calculated, and the absolute values of the gradients are accumulated and averaged to obtain the channel gradient sensitivity score.
[0062] In parallel with the channel attention mechanism, this application evaluates the sensitivity of each channel to the final detection loss through gradient analysis during backpropagation. In each training iteration, forward propagation is first performed, and the object detection loss function L is calculated. detection(Including classification loss and regression loss). Then, backpropagation is performed to obtain the partial derivatives of the loss function with respect to each spatial location of the output feature map of each convolutional layer. Specifically, for the feature map of the c-th channel in the l-th layer, its gradient tensor size is also H×W, denoted as H×W. , where x and y are spatial coordinates. To obtain the overall sensitivity score for this channel, the absolute values at all spatial locations within the gradient tensor are summed and averaged, calculated using the following formula: The obtained S c This is the channel gradient sensitivity score: if a small change in the output feature map of a channel can cause a large change in the loss function, it indicates that the channel is crucial to the detection task, and its gradient sensitivity score is high; conversely, if a change in the output of a channel has almost no effect on the loss value, it indicates that the channel is redundant, and its gradient sensitivity score is low. In a preferred embodiment, to avoid instability caused by gradient vanishing or exploding, S can be... c Intra-layer normalization is performed, for example, by subtracting the mean of all channels in that layer and then dividing by the standard deviation, to make the scores between different layers comparable. Alternatively, the gradient sensitivity score can be updated using a cumulative moving average, i.e., S. c_new =γ·S c_old + (1-γ)·S c_current , where γ is the momentum coefficient (e.g., 0.9) to smooth noise fluctuations during training.
[0063] S23: The channel attention weight coefficient and the channel gradient sensitivity score are weighted and fused to generate a comprehensive importance score.
[0064] Obtain the attention weight coefficient A for each channel. c and gradient sensitivity score S c Next, the two need to be integrated into a unified comprehensive importance score for subsequent pruning decisions. A basic integration method uses linear weighted summation: I c = α·A c + β·S c , where α and β are preset balancing coefficients. For example, α and β can both be set to 0.5, making their contributions roughly equal; they can also be adjusted empirically, for example, increasing α when more emphasis is placed on feature response intensity, and increasing β when more emphasis is placed on loss sensitivity. In another alternative implementation, product fusion is used: I c = A c × S c At this point, A is required. c and S cAll have been normalized to similar dimensions. The advantage of the product form is that its overall score is higher only when the channel is important in both the attention mechanism and gradient analysis, thus reducing the probability of misclassification. Furthermore, nonlinear mappings, such as I, can be introduced. c = (A c ) p × (S c ) q Where p and q are exponential parameters used to adjust the sensitivity of different metrics. Regardless of the fusion method used, each convolutional layer ultimately outputs a comprehensive importance score vector I = [I1, I2, ..., I...] of equal length to the number of channels. C In an optional implementation, to eliminate differences in scoring dimensions between different layers, the overall importance score can be normalized within each layer, for example, by dividing it by the maximum value of all channel scores in that layer, so that the score range falls within the [0,1] interval, facilitating subsequent threshold comparison. This overall importance score reflects both the feature importance of input dependence (from the attention mechanism) and the loss sensitivity of task dependence (from gradient analysis), thereby achieving true dynamic weight evaluation.
[0065] According to another aspect, the steps for generating the layer-by-layer dynamic pruning threshold include:
[0066] S31: Extract the complexity metric of the current input image from the training image dataset. The complexity metric is selected from: image information entropy, edge density, or scene complexity level output by the auxiliary network.
[0067] To generate dynamic pruning thresholds that adapt to different input scenarios, it is first necessary to quantify the complexity of the current input image. This application provides multiple methods for extracting complexity metrics, which can be flexibly selected according to computing resources and usage scenarios. The first method uses image information entropy. The specific calculation steps are as follows: convert the input image from the RGB color space to a grayscale image, statistically analyze the pixel frequency distribution from grayscale level 0 to 255, and obtain the probability distribution p(i), where i is the grayscale level. Image information entropy H = -Σ i=0 255p(i)·log2(p(i)). A larger entropy value indicates richer image texture, more uniform grayscale distribution, and higher scene complexity; a smaller entropy value indicates simpler image content (such as a solid color background) and lower scene complexity. The second method uses edge density. The Canny edge detection operator is used to extract the binary edge map of the image, and the proportion of edge pixels to the total number of pixels is counted, denoted as E. Higher edge density indicates a large number of structural changes and contour details in the image, and a more complex scene; conversely, low edge density indicates a smooth image. The third method uses a lightweight auxiliary network. This network can be a pre-trained small classifier, for example, consisting of two depthwise separable convolutional layers and a global average pooling layer, outputting the probabilities of three categories: simple, ordinary, and complex. The number of parameters in this auxiliary network is usually controlled below 1M, with minimal computational cost, and it can run in parallel with the main model during the inference phase. In a preferred embodiment, to further reduce overhead, the complexity evaluation result can be shared across multiple consecutive frames. That is, the complexity index is recalculated every N frames (e.g., N=10), and the intermediate frames use the most recent evaluation value. Regardless of the method used, the final output complexity index is a scalar Cplx, with a value range normalized to [0,1], where 0 represents the simplest and 1 represents the most complex.
[0068] S32: Input the complexity index, the distribution parameters of the comprehensive importance score of each channel in the current layer, and the preset target compression ratio into the dynamic threshold generation function.
[0069] The obtained complexity index Cplx, the distribution parameters of the comprehensive importance score vector I of each channel in the current convolutional layer, and the user-preset target compression ratio R are used to calculate the compression ratio. target These, together, serve as the input to the dynamic threshold generation function. The distribution parameters include at least the mean μ and standard deviation σ of the overall importance score for all channels in this layer. Specifically, μ = (1 / C) × Σ c=1 C I c σ=sqrt((1 / C)×Σ c=1 C (I c -μ) 2 ). Target compression ratio R target It is a value between 0 and 1, such as R. target=0.4 indicates an expected reduction of 40% in the model's floating-point operations (FLOPs). This value is preset by the user based on the computing power of the edge device. In an alternative implementation, an inter-layer sensitivity factor can be introduced, where different layers have different tolerances to pruning: shallow feature extraction layers are generally more sensitive to pruning, while deeper semantic layers are more tolerant. Therefore, different target compression ratio weights can be assigned to different layers, for example, setting lower compression expectations for layers 1 to 3 and higher compression expectations for layers 4 and above. The dynamic threshold generation function can take the form of an adaptive gating network or a statistical percentile calculation formula. In a preferred percentile-based method, a preset baseline percentile p0 (e.g., 50%) is first dynamically adjusted according to the complexity index Cplx: p adj = p0 + k×(0.5 - Cplx), where k is an adjustment coefficient (e.g., 30). When Cplx = 0 (the simplest case), p adj = 50% + 30% × 0.5 = 65%; When Cplx = 1 (most complex), p adj = 50% + 30% × (-0.5) = 35%. Then, compare this adjusted percentile with the target compression ratio R. target Perform a weighted average to obtain the final percentile p. final = (1-λ)·p adj + λ·R target , where λ is the balance coefficient (e.g., 0.5). A higher compression ratio requires a higher pruning threshold; conversely, higher complexity requires a lower pruning threshold to preserve accuracy.
[0070] S33: The dynamic threshold generation function calculates a layer-specific pruning threshold for each convolutional layer based on the input parameters and outputs the dynamic pruning threshold layer by layer; where the lower the complexity index, the higher the output pruning threshold, and the higher the complexity index, the lower the output pruning threshold.
[0071] The dynamic threshold generation function calculates a layer-specific pruning threshold T for each convolutional layer independently based on the input parameters. layer In the percentile-based implementation, T layer Equal to the p-th digit of the current layer's overall importance score vector final Percentiles. In the specific calculation, the I vector is sorted in ascending order, and the index ceil(C×p) is found. final The value at ( / 100) is used as the threshold. For example, if C=64, p final If the percentage is 40%, then the 26th value after sorting (64 × 0.4 = 25.6, rounded up to 26) is taken as the pruning threshold. The pruning thresholds for all layers are summarized in a list [T1, T2, ..., T...]. L], where L is the total number of convolutional layers. In a key design of this application, the complexity metric is negatively correlated with the pruning threshold: when the input image complexity is low (simple scene), Cplx is small, p final The pruning threshold T is relatively large, therefore... layer A higher value for Cplx indicates that more channels will be deemed unimportant and pruned, thus reducing computational cost; conversely, when the input image is highly complex (complex scenes), a larger Cplx means more channels will be pruned. final Smaller, pruning threshold T layer The threshold is lower; only channels with very low overall importance scores are pruned, thus preserving more key features and ensuring detection accuracy. In an alternative implementation, upper and lower thresholds can be set for each layer, for example, T... min and T max This prevents the threshold from being too extreme, which could result in all channels being pruned or no channels being pruned at all. The final output of the layer-by-layer dynamic pruning threshold is directly used to guide subsequent structured pruning operations.
[0072] According to another aspect of this application, the steps for obtaining the structured pruned model include:
[0073] S41: Sort all channels in each convolutional layer from highest to lowest according to their overall importance score.
[0074] Before starting structured pruning, for the currently processed convolutional layer, all its channels need to be sorted according to their overall importance score. Specifically, obtain the overall importance score vector I = [I1, I2, ..., I...] for this layer. C [and the corresponding channel index]. A stable sorting algorithm (such as merge sort or quicksort) is used to sort the channels according to I. c The values are sorted in descending order to obtain the sorted list of channel indices, idx. sorted The time complexity of this sorting process is O(C log C), and since C is typically in the hundreds (e.g., 64, 128, 256), the computational overhead is negligible. In a preferred embodiment, multiple layers can be processed in parallel, utilizing GPU parallel sorting libraries for acceleration. The purpose of sorting is to efficiently mark channels to be pruned in subsequent threshold-based pruning operations, because once the threshold is determined, channels below the threshold naturally occupy the latter half of the sorted list. Furthermore, the sorting results can also be used to record the importance ranking of channels, facilitating the generation of pruning reports or visual analysis.
[0075] S42: Mark channels whose importance score is lower than the dynamic pruning threshold of this layer as channels to be pruned.
[0076] The sorted channels are sequentially compared with the generated dynamic pruning threshold T for this layer. layerCompare them. For each channel c, if its overall importance score I... c < T layer If the condition is met, the channel is marked as a channel to be pruned; otherwise, it is marked as a channel to be retained. The marking operation can use a binary mask vector M of length C, where M... c =0 indicates that pruning is needed, M c =1 indicates retention. In an alternative implementation, a soft thresholding mechanism can be introduced, where channels with scores slightly above the threshold are retained but given a decay factor to avoid accuracy loss due to hard decisions at the boundaries. However, in the structured pruning framework of this application, hard decisions are more conducive to achieving regular channel deletion, thereby obtaining a hardware-friendly dense model. After marking, the number C channels to be pruned is counted. pruned =Σ(1-M c ) and the proportion of branches to be pruned r pruned = C pruned / C.
[0077] S43: If the proportion of channels to be pruned in a certain layer exceeds the preset upper limit, then the layer is marked as a layer to be pruned, and hierarchical pruning is performed to skip the layer or replace the layer with an identity mapping.
[0078] After marking the channels to be pruned, check the proportion r of the channels to be pruned. pruned Does it exceed the preset upper limit? The preset upper limit is denoted as θ. layer For example, we can take 0.8 (i.e., 80%). This upper limit can be set empirically or adaptively adjusted according to the network depth; deeper networks can tolerate higher layer pruning ratios. If r pruned ≥θ layer This indicates that most channels in the current convolutional layer are considered unimportant. Retaining only a few channels in this case would lead to irregular computation patterns (e.g., retaining 8 channels with an original width of 64, and then pruning to 8, still dense but potentially disrupting information flow). Therefore, a hierarchical pruning strategy is adopted: the entire layer is marked as a layer to be pruned. Hierarchical pruning can be performed in two ways: the first is to skip the layer directly, i.e., during inference, the input of the layer is directly passed to the next layer (identity mapping), effectively removing the layer; the second is to replace the layer with a lightweight identity mapping layer, such as a 1×1 convolution with weights initialized to the identity matrix, or by using skip connections. In a preferred embodiment, for structures containing batch normalization layers, the scaling factor and offset of the batch normalization can be adjusted to identity mapping before removing the entire layer. Hierarchical pruning removes a complete computational block, achieving a more significant speedup compared to channel pruning, and is particularly suitable for redundant layers that contribute little to the overall task.
[0079] S44: If the preset upper limit is not exceeded, channel pruning is performed. The convolution kernel corresponding to the channel to be pruned is physically deleted from the weight matrix of the current convolutional layer to obtain the pruned weight matrix.
[0080] If the proportion of channels to be pruned is r pruned Not exceeding the preset upper limit θ layer If the output channel is not pruned, then channel pruning is performed. Channel pruning physically removes all convolutional kernels corresponding to the channels to be pruned from the weight matrix of the current convolutional layer. For a standard convolutional layer, its weight tensor is typically four-dimensional: the number of output channels C. out Number of input channels C in The convolution kernel height is Kh, and the convolution kernel width is Kw. In this application, pruning mainly targets the output channel dimension, that is, deleting the convolution kernel corresponding to the entire output channel. The specific operation is as follows: according to the index list of the channels to be pruned, delete the slices corresponding to these indices from the first dimension (output channel dimension) of the weight tensor to obtain a new weight tensor whose number of output channels becomes C. retained = C-C pruned Similarly, if a batch normalization layer follows the convolutional layer, the elements corresponding to the channel indices to be pruned in the scaling factor γ, offset β, mean μ, and variance σ of the batch normalization layer also need to be deleted synchronously. After the deletion operation, the pruned weight matrix is obtained. In an optional implementation, to maintain numerical stability, the retained weights can be fine-tuned before deletion, for example, by using knowledge distillation to make the pruned model mimic the output of the original model. However, this application prefers to achieve a smooth transition through a masking mechanism in the subsequent joint optimization stage, and only performs physical structural deletion here.
[0081] S45: Generate a pruning mapping table based on the pruning operation record, and based on the pruning mapping table, synchronously delete the part of the input channel dimension of the subsequent convolutional layer or batch normalized layer that corresponds to the channel to be pruned, to ensure that the input and output dimensions of adjacent layers match, and obtain the structured pruned model.
[0082] Channel pruning alters the number of output channels in the current convolutional layer, which can lead to a mismatch in the number of input channels in subsequent convolutional layers. To address this issue, this application generates a pruning map table that records the indices of the deleted output channels in each layer. Specifically, for the l-th layer, its pruning map table P... l It is a list containing the original indices of all pruned output channels. Then, iterate through all successor layers (usually the (l+1)th layer, but may also include target layers with skip connections) that take the output of the l-th layer as input. For each successor convolutional layer, its input channel dimension was originally equal to the number of output channels of the l-th layer. Now, it is necessary to determine P... l This involves removing slices with the corresponding indices from the input channel dimension of the weight tensor of the subsequent convolutional layer. For example, if the weight tensor of the subsequent convolutional layer has a shape of C...out_next × C in_next × Kh × Kw, where C in_next It should be equal to the number of original output channels C of the l-th layer. l After the deletion operation, C in_next Change to C l_retained Simultaneously, if the successor layer is a batch normalized layer, its input channel dimension also needs to be adjusted synchronously. This dimension matching process ensures that the forward propagation of the network can be executed correctly, without dimension incompatibility errors. After completing the pruning and dimension adjustment of all layers, the structured pruned model is output. All convolutional layers of this model have regular dense tensor shapes, suitable for efficient operation on parallel hardware such as GPUs and TPUs. In addition, the pruning map table is also saved for use in subsequent joint optimization mask updates and dynamic scheduling during the inference phase.
[0083] According to another aspect of this application, the steps of performing adaptive quantization include:
[0084] S51: After the joint optimization reaches the preset convergence progress, analyze the numerical distribution of weights and activations of each convolutional layer, and automatically select the quantization bit width for each layer. Sensitive layers select INT8 quantization, and non-sensitive layers select INT4 or INT2 quantization.
[0085] After the joint optimization reaches the preset convergence progress, for example, after completing 80% of the total training rounds, the model parameters are relatively stable, and the adaptive quantization module is activated. First, the weight distribution and activation value distribution of each convolutional layer are analyzed. The weight distribution can be obtained by statistically analyzing the histogram of the weight tensor after forward propagation; the activation value distribution requires forward inference on a small calibration dataset to collect statistical information from the output feature map of each layer. For each layer, the following metrics are calculated: the dynamic range of the weights (maximum minus minimum), the proportion of outliers (the proportion of weights whose absolute value exceeds 3 times the standard deviation), and the distribution entropy of the activation values. Based on these metrics, the sensitivity of the layer to quantization error is determined. Sensitive layers typically have the following characteristics: large dynamic range, many outliers, and non-uniform activation value distribution. For sensitive layers, INT8 quantization (8-bit integer) is selected, resulting in smaller quantization errors; for insensitive layers, INT4 or INT2 quantization can be selected. In an alternative implementation, a mixed-precision search strategy can be employed, such as using reinforcement learning or Bayesian optimization to automatically search for the optimal bit width for each layer. However, to reduce computational overhead, this application adopts a heuristic rule: if the maximum absolute value of the weights in a layer is less than 0.5 and the activation value range is less than 2, then INT4 is selected; if it is further less than 0.1 and the activation value distribution is highly concentrated around 0, then INT2 is selected; otherwise, INT8 is selected. After this step, each layer is assigned a quantization bit width b. l ∈ {2,4,8}.
[0086] S52: Outputs an intermediate model containing mixed-precision weights, a pruning mask table, and quantization parameters for each layer.
[0087] Based on the determined quantization bit width of each layer, the weights of the structured pruned model are quantized, and corresponding quantization parameters (scaling factor Δ and zero point Z) are generated. For each layer's weight tensor W, Δ = (max(W) - min(W)) / (2 b -1), Z = round(-min(W) / Δ). Then calculate the quantized integer weights W. q Simultaneously, for subsequent quantization-aware training, the inverse quantization parameters also need to be saved. Furthermore, the pruning mask table (recording the indexes of the channels to be retained in each layer) and the quantization parameters of each layer are packaged together to form an intermediate model. This intermediate model can be stored in a compressed format, for example, W... q The values are stored as int8 or int4 arrays, with Δ and Z stored as float32. In a preferred embodiment, the weights of INT4 or INT2 are stored in a packed manner, for example, two INT4 values are packed into one byte to reduce storage space. This intermediate model can be directly deployed to hardware that supports mixed-precision inference (such as a GPU with DP4A instructions), but to further restore accuracy, it is recommended to continue with quantization-aware training.
[0088] Furthermore, the steps for generating a lightweight object detection model include:
[0089] S53: After outputting the intermediate model, perform quantization-aware training to simulate low-precision forward and backward propagation, and fine-tune the model to restore accuracy.
[0090] After outputting the intermediate model, Quantization-Aware Training (QAT) is performed to compensate for the accuracy loss introduced by quantization. QAT simulates quantization during training, adapting the model parameters to the quantized numerical representation. Specifically, in the forward propagation, for each layer, the weights are first quantized and then dequantized: W fake = (clamp(round(W / Δ) + Z, 0, 2 b -1) - Z)·Δ. Activation values are also simulated quantization: a similar operation is performed on the output feature map after each convolutional layer. During backpropagation, a pass-through estimator (STE) is used, which ignores the non-differentiable part of the quantization function and directly applies the loss to the dequantized W. fakeThe gradient is passed to the original W. The training dataset can use a subset of the original training set (e.g., 10% of the samples), and the number of training epochs is typically small (e.g., 5-10 epochs). The learning rate is set to 0.1 times the final learning rate of the original training, primarily for fine-tuning. In an alternative implementation, quantization-aware training can be performed in stages: first, quantize the weights with fixed values and train only the activation values for a few epochs; then, enable both simultaneously. This step effectively recovers from the accuracy loss caused by low-precision quantization. Experiments have shown that it can bring the accuracy of the INT8 quantized model close to the FP32 baseline, while keeping the accuracy loss of INT4 quantization within 1%.
[0091] S54: Outputs a lightweight target detection model fine-tuned after quantization-based perceptual training.
[0092] After quantization-aware training, the weights of each layer are replaced with quantized integer values (rather than dequantized floating-point values), and the quantization parameters are fixed. Simultaneously, the pruning mask table is stored in a sparse index format. The final lightweight object detection model output includes the following components: a model structure description file (e.g., ONNX or TFLite format), integer weight arrays for each layer, quantization parameters (scaling factor, zeros) for each layer, and pruning masks for each layer (i.e., a list of indices for preserved channels). This model can be directly deployed to edge devices without dynamically calculating pruning masks at runtime. In an alternative implementation, the model can also be converted to a format specific to an inference engine, such as a TensorRT engine file or a TFLite FlatBuffer file. Compared to the initial model, this final model typically reduces the number of parameters by more than 60%, the computational cost by more than 50%, and the storage volume can be compressed to about one-quarter of the original due to mixed-precision quantization.
[0093] According to another aspect of this application, the steps for outputting the target detection results include:
[0094] S61: For each frame of input image, the image complexity is quickly evaluated by a lightweight complexity prediction module to obtain a complexity score.
[0095] During real-time inference, for each input image frame, a lightweight complexity prediction module is used to quickly assess the image complexity. This module is designed to have a computational cost far less than the main model, typically less than 1% of the main model's computation. In one implementation, the complexity prediction module employs two depthwise separable convolutional layers: the first layer downsamples the input image to 64×64, and the second layer outputs a scalar. This module is pre-trained on a large-scale image dataset, using image entropy or manually labeled complexity levels as supervision signals. During inference, the input image is scaled to 64×64 and fed into this module; forward propagation yields the complexity score Cplx. scoreThe value ranges from 0 to 1. In another alternative implementation, to further reduce overhead, a statistical method is directly employed: the image is downsampled to 32×32, its pixel value variance and gradient magnitude mean are calculated, and mapped to the 0-1 interval using a simple linear regressor. Regardless of the method used, a complexity score is ultimately obtained. In an optional implementation, for temporal continuity, the complexity score can be shared across multiple consecutive frames, for example, calculated every 10 frames, with intermediate frames reusing the most recent result.
[0096] S62: When the complexity score is below the first threshold, force the application of an aggressive pruning mask to block more channels and force all layers to use INT4 quantization.
[0097] When the complexity score is below the first threshold (e.g., Cplx) score If the value is less than 0.3, the current frame is determined to be a simple scene (e.g., empty background, single target, low texture). In this case, to maximize energy saving and reduce computational latency, an aggressive scheduling strategy is executed: a predefined aggressive pruning mask is forced to be applied. This aggressive pruning mask is more stringent than the default pruning mask, retaining a lower percentage of channels (e.g., only 30% of the original channels). This mask can be generated and fixed offline by setting a higher target compression ratio (e.g., R_target=0.7). Simultaneously, all convolutional layers are forced to use the lowest precision quantization, i.e., INT4 quantization. For hardware that supports dynamic quantization, the quantization parameters can be switched at runtime. In a preferred implementation, symmetric quantization can be used for INT4 quantization to simplify computation. Through this aggressive scheduling, the model's inference speed and energy consumption are significantly optimized, making it suitable for scenarios with limited drone battery life or edge device heat limitations.
[0098] S63: When the complexity score is higher than the second threshold, use a model structure that retains more channels and force all layers to use INT8 quantization.
[0099] When the complexity score is higher than the second threshold (e.g., Cplx) score > 0.7), indicating the current frame is a complex scene (e.g., dense crowds, multiple categories, high texture). In this case, to ensure detection accuracy, a high-precision scheduling strategy is executed: a model structure retaining more channels is used, typically a further relaxation of the default pruning mask (retaining 60% of channels), for example, retaining 80% (this can be achieved by setting a lower R0.7). target =0.2 (generated). Simultaneously, all layers are forced to use INT8 quantization. If the hardware supports FP16 and energy consumption allows, mixed-precision INT8 can also be used. Although this strategy involves significant computational cost, it ensures that critical targets are not lost in complex scenarios.
[0100] S64: When the complexity score is between the first and second thresholds, use the default pruning mask and INT8 quantization.
[0101] When the complexity score is between the first threshold and the second threshold (0.3 ≤ Cplx) score If the complexity score is ≤0.7, it is considered a normal scenario. In this case, the default pruning mask (typically retaining 60% of the channels) and default INT8 quantization are used. This strategy provides a good balance between accuracy and speed and is suitable for most situations. In an optional implementation, the pruning masks and quantization configurations corresponding to the three scheduling strategies can be pre-stored in the device's configuration file and loaded and switched in real time during inference based on the complexity score. The switching process needs to ensure the consistency of the model's internal state; for example, the historical statistics of the batch normalization layer need to be recalibrated based on the currently active subset of channels.
[0102] S65: Input the image tensor into the model, perform dynamic inference, and output the object detection results.
[0103] After selecting the appropriate scheduling strategy based on complexity, the input image tensor is fed into the lightweight object detection model to perform a complete dynamic inference. During inference, the model achieves efficient computation through operator fusion functionality of the inference engine, based on pre-set masks and quantization precision. For example, TensorRT supports skipping the computation of certain channels at runtime based on the mask. Finally, the model outputs object detection results, including the bounding box coordinates of each detected object (typically normalized center point coordinates, width, and height), class labels (e.g., "person," "car," etc.), and confidence scores (floating-point numbers between 0 and 1). In the post-processing stage, redundant detection boxes are filtered based on a confidence threshold (e.g., 0.5) and non-maximum suppression (NMS) to obtain the final visualization results. These results can be used for subsequent decision control, such as autonomous obstacle avoidance in drones and alarm systems in security systems.
[0104] Compared with existing technologies, this invention has the following significant advantages: First, in terms of model compression, through the synergistic effect of the dynamic weight evaluation module and the structured pruning module, redundant channels, hierarchical connections, and low-importance network layers can be systematically removed while retaining key feature channels. Combined with INT8 or INT4 adaptive quantization, the model size can be compressed to about one-quarter of the original model, significantly reducing both the number of parameters and computational load, thus adapting to edge platforms with limited storage and computing power, such as drones and mobile robots. Second, in terms of inference speed, due to the structured pruning strategy that combines hierarchical and channel-based pruning, the pruned model maintains a regular dense tensor format, avoiding the memory access and parallel efficiency degradation caused by the sparse matrix generated by unstructured pruning. Therefore, it can fully utilize the parallel acceleration capabilities of hardware and inference frameworks such as GPUs, TPUs, TensorRT, and OpenVINO. Actual measurements show an approximately 2.5x speed improvement in inference on the NVIDIA Jetson Nano platform, meeting real-time detection requirements. Third, regarding the preservation of detection accuracy, this invention integrates channel attention mechanism and gradient sensitivity analysis to dynamically evaluate the importance of each channel to the current detection task and generate layer-by-layer adaptive pruning thresholds accordingly. This reduces the risk of key feature channels being mistakenly pruned. Taking the COCO dataset as an example, the original model's mAP was 45.3%, and after lightweight processing, it still reached 44.8%, with an accuracy loss of only about 0.5%, far superior to traditional static pruning methods. Fourth, regarding the training and deployment process, this invention directly embeds pruning constraints into the target detection loss function, achieving end-to-end joint optimization of pruning and detection tasks. This avoids the error accumulation and cumbersome hyperparameter adjustments caused by the traditional multi-stage process of "pruning-fine-tuning-quantization-re-fine-tuning," shortening the training cycle and reducing the cost of manual intervention. Fifth, regarding adaptive resource scheduling, this invention can dynamically adjust the number of activated network layers, the channel retention ratio, and the quantization accuracy based on the complexity of the input image (such as information entropy and edge density). In simple scenarios, aggressive pruning and low-precision computation are used to maximize energy efficiency, while in complex scenarios, more computational resources are reserved to ensure detection accuracy. This achieves a dynamic balance between detection accuracy, inference speed, and power consumption, making it particularly suitable for edge computing environments with high real-time requirements and diverse scenarios. In summary, this invention has achieved substantial progress in five dimensions: model lightweighting, hardware acceleration friendliness, accuracy preservation, training convenience, and adaptive resource scheduling.
[0105] The preferred embodiments of the present invention have been described in detail above. However, the present invention is not limited to the specific details in the above embodiments. Within the scope of the technical concept of the present invention, various equivalent transformations can be made to the technical solutions of the present invention, and these equivalent transformations all fall within the protection scope of the present invention.
Claims
1. A lightweight target detection method based on dynamic weight pruning, characterized in that, include: Obtain the training image dataset and the initial object detection model; The training image dataset is input into the initial object detection model, dynamic weight importance evaluation is performed, and a comprehensive importance score is generated; Based on the comprehensive importance score and the complexity index of the input image, a layer-by-layer dynamic pruning threshold is generated; Based on the layer-by-layer dynamic pruning threshold and comprehensive importance score, structured pruning is performed in a layer-by-layer and channel-by-channel manner, and the input-output dimensions between adjacent network layers are adjusted to obtain the structured pruned model. Pruning constraints are embedded into the target detection loss function, and end-to-end joint optimization is performed on the structured pruned model. Adaptive quantization is performed during the joint optimization process to generate a lightweight target detection model. A lightweight object detection model is deployed to edge computing devices. During the inference stage, the number of activated network layers, the proportion of channels retained, or the quantization precision are dynamically adjusted according to the complexity of the input image to output object detection results.
2. The method according to claim 1, characterized in that, The steps to generate a comprehensive importance score include: During the forward propagation process, the output feature maps of the convolutional layers are extracted, global average pooling and global max pooling are performed, and the pooling results are activated by a shared multilayer perceptron and a sigmoid to obtain the channel attention weight coefficients. During backpropagation, the gradient of the loss function with respect to the output feature map is calculated, and the absolute values of the gradients are accumulated and averaged to obtain the channel gradient sensitivity score. The channel attention weight coefficient and the channel gradient sensitivity score are weighted and fused to generate a comprehensive importance score.
3. The method according to claim 1, characterized in that, The steps for generating the layer-by-layer dynamic pruning threshold include: Extract the complexity metric of the current input image from the training image dataset. The complexity metric is selected from: image information entropy, edge density, or scene complexity level output by the auxiliary network. Input the complexity index, the distribution parameters of the comprehensive importance score of each channel in the current layer, and the preset target compression ratio into the dynamic threshold generation function; The dynamic threshold generation function calculates a layer-specific pruning threshold for each convolutional layer based on the input parameters and outputs a layer-by-layer dynamic pruning threshold. The lower the complexity index, the higher the output pruning threshold, and the higher the complexity index, the lower the output pruning threshold.
4. The method according to claim 1, characterized in that, The steps to obtain the structured, pruned model include: Sort all channels in each convolutional layer from highest to lowest according to their overall importance score; Channels with importance scores below the dynamic pruning threshold of that layer are marked as channels to be pruned; If the proportion of channels to be pruned in a certain layer exceeds the preset upper limit, then the layer is marked as a layer to be pruned, and hierarchical pruning is performed to skip the layer or replace the layer with an identity mapping. If the preset upper limit is not exceeded, channel pruning is performed, and the convolution kernel corresponding to the channel to be pruned is physically deleted from the weight matrix of the current convolutional layer to obtain the pruned weight matrix. A pruning mapping table is generated based on the pruning operation record. Then, based on the pruning mapping table, the part of the input channel dimension of the subsequent convolutional layer or batch normalized layer that corresponds to the channel to be pruned is deleted synchronously to ensure that the input and output dimensions of adjacent layers match, thus obtaining the structured pruned model.
5. The method according to claim 1, characterized in that, The steps for embedding pruning constraints into the target detection loss function and performing end-to-end joint optimization of the structured pruned model include: Construct a joint optimization loss function L total =L detection +λ1·L sparsity +λ2·L quant_error , wherein L detection is the original target detection loss, L sparsity is the pruning sparse regularization term, L quant_error is the quantization error estimation term, and λ1 and λ2 are balance coefficients; The structured pruned model is trained end-to-end on the training image dataset. In each iteration, dynamic pruning is simulated using a mask, and based on L... total Update the weights; After each preset number of iterations, the comprehensive importance score and the layer-by-layer dynamic pruning threshold are regenerated based on the current weights and gradient distribution, and the mask is updated synchronously.
6. The method according to claim 5, characterized in that, The steps for performing adaptive quantization include: After the joint optimization reaches the preset convergence progress, the numerical distribution of weights and activations in each convolutional layer is analyzed, and the quantization bit width is automatically selected for each layer. INT8 quantization is selected for sensitive layers, and INT4 or INT2 quantization is selected for non-sensitive layers. The output includes an intermediate model containing mixed precision weights, a pruning mask table, and quantization parameters for each layer.
7. The method according to claim 6, characterized in that, The steps to generate a lightweight object detection model include: After outputting the intermediate model, perform quantization-aware training to simulate low-precision forward and backward propagation, and fine-tune the model to restore accuracy. Output a lightweight target detection model after quantization perception training and fine-tuning.
8. The method according to claim 1, characterized in that, The steps for outputting target detection results include: For each frame of input image, the image complexity is quickly evaluated by a lightweight complexity prediction module to obtain a complexity score; When the complexity score is below the first threshold, aggressive pruning masking is forced to block more channels, and all layers are forced to use INT4 quantization. When the complexity score is higher than the second threshold, use a model structure that retains more channels and force all layers to use INT8 quantization; When the complexity score is between the first and second thresholds, the default pruning mask and INT8 quantization are used. The image tensor is input into the model, dynamic inference is performed, and the object detection result is output.
9. The method according to claim 1, characterized in that, The method further includes: During the joint optimization or inference phase, the distribution changes of the comprehensive importance score of each channel are monitored. When the importance score of a certain channel is lower than the global dynamic threshold for multiple consecutive iterations, a permanent pruning mark for that channel is generated. In subsequent training or inference, skip the computation of channels that have already generated permanent pruning tags.
10. The method according to claim 1, characterized in that, After obtaining the training image dataset and the initial object detection model, the process also includes performing a standardization preprocessing step on the training images: the standardization preprocessing includes uniform scaling, pixel value normalization, and random data augmentation; the initial object detection model is an object detection model based on a convolutional neural network, and the training image dataset contains ground truth bounding boxes and class labels.