Lightweight target detection method and device

Through the attention mechanism backbone network and the channel attention mechanism feature fusion network, feature enhancement extraction and multi-scale feature fusion are performed on the image to be detected, which solves the problem of the transformer being insensitive to position information during detection, improves the target detection effect, and achieves Lightweighting of the model.

CN118762162APending Publication Date: 2024-10-11GUANGDONG UNIV OF TECH
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202410760667.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

In the existing lightweight target detection technology, the transformer can only extract the global features of the image during feature extraction, and the image blocks need to be divided before entering the transformer encoder. As a result, the model cannot effectively retain the position information of the image, resulting in poor detection results.

Method used

The attention mechanism backbone network and the channel attention mechanism feature fusion network are used to perform feature enhancement extraction and multi-scale feature fusion on the image to be detected, to generate multiple enhanced feature maps and fusion feature maps, and target detection is performed through these feature maps.

Benefits of technology

By effectively retaining the position information of the image, the detection effect of the model is improved, and the model size and calculation amount are reduced while maintaining performance, making it suitable for mobile terminal deployment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118762162A_ABST
    Figure CN118762162A_ABST
Patent Text Reader

Abstract

The invention discloses a lightweight target detection method and device, and the method comprises the steps: obtaining a to-be-detected image, and inputting the to-be-detected image to a preset lightweight target detection model which comprises an attention mechanism backbone network and a channel attention mechanism feature fusion network; performing feature enhancement extraction on the to-be-detected image by adopting the attention mechanism backbone network to generate a plurality of enhanced feature maps; performing multi-scale feature fusion on each enhanced feature map through a channel attention mechanism feature fusion network to generate a plurality of fusion feature maps; performing target detection on each fusion feature map, and outputting a lightweight target detection result; according to the present invention, by improving the existing Yolov8 model, the preset lightweight target detection model is obtained, and the model is adopted to carry out corresponding lightweight target detection, so that the technical problem of poor model detection effect caused by the existing lightweight target detection technology is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer vision detection, and in particular to a lightweight target detection method and device. Background Art

[0002] At present, computer vision is a classic research field that is dedicated to using computers to complete human visual tasks. Among them, object detection is a basic research direction in this field. The main problem solved in this direction is to enable computers to locate and identify objects of interest in images by designing corresponding algorithms.

[0003] In the field of target detection, lightweighting is an important research direction with high research value. It is usually the starting point for many practical applications, such as intelligent robots and self-driving cars, satellite and aerial image analysis, as well as medical diagnosis and product defect detection. At the same time, lightweighting can reduce the size of the model and reduce the amount of model calculation while trying to maintain the performance of the model.

[0004] Most of the existing lightweight object detection technologies introduce the attention mechanism (transformer) into the network structure of the lightweight model. However, the transformer can only extract the global features of the image when performing feature extraction, and the image must be divided into patches before entering the transformer's encoder, making it impossible for the model to effectively retain the image's location information, resulting in poor model detection effect. Summary of the invention

[0005] The present invention provides a lightweight target detection method and device, which are used to solve the technical problem that the existing lightweight target detection technology leads to poor model detection effect.

[0006] A first aspect of the present invention provides a lightweight target detection method, comprising:

[0007] Acquire an image to be detected, and input the image to be detected into a preset lightweight target detection model, wherein the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network;

[0008] Using the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected, and generate multiple enhanced feature maps;

[0009] Perform multi-scale feature fusion on each of the enhanced feature maps through a channel attention mechanism feature fusion network to generate multiple fused feature maps;

[0010] Perform target detection on each of the fused feature maps and output a lightweight target detection result.

[0011] Optionally, the attention mechanism backbone network includes a 3×3 convolution layer, a partial fast convolution module and a partial convolution attention mechanism module; the multiple enhanced feature maps include a first enhanced feature map, a second enhanced feature map, a third enhanced feature map and a fourth enhanced feature map; the step of using the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected to generate multiple enhanced feature maps includes:

[0012] Using a 3×3 convolution layer to perform a 3×3 convolution operation on the image to be detected, and output a first convolution feature map;

[0013] Performing partial channel operations on the first convolution feature map through a partial fast convolution module, and outputting a first enhanced feature map;

[0014] Outputting the first enhanced feature map to a partial fast convolution module for partial channel operation to generate a second enhanced feature map;

[0015] Using a partial convolutional attention mechanism module to perform feature superposition on the second enhanced feature map, and output a third enhanced feature map;

[0016] The third enhanced feature map is feature superimposed through a partial convolutional attention mechanism module to output a fourth enhanced feature map.

[0017] Optionally, the partial fast convolution module includes a 3×3 convolution layer, a partial convolution layer, a 1×1 convolution layer, a batch normalization layer and a ReLU activation function layer; the image processing step of the partial fast convolution module includes:

[0018] The convolution feature input map of the fast convolution module of the input part is convolved through a 3×3 convolution layer to generate a first intermediate convolution feature map;

[0019] Using a partial convolutional layer to extract local features from the intermediate convolutional feature map to generate a first local feature map;

[0020] Performing a 1×1 convolution operation on the first local feature map through a 1×1 convolution layer, and outputting a second intermediate convolution feature map;

[0021] Inputting the second intermediate convolutional feature map into a batch normalization layer for normalization to generate a first normalized feature map;

[0022] Using a ReLU activation function layer to perform nonlinear mapping on the first normalized feature map, and output a first nonlinear feature map;

[0023] Performing a 1×1 convolution operation on the first nonlinear feature map through a 1×1 convolution layer to generate a third intermediate convolution feature map;

[0024] The third intermediate convolutional feature map and the convolutional feature input map are superimposed to generate a convolutional feature output map.

[0025] Optionally, the partial convolutional attention mechanism module includes a series of 3×3 convolutional layers, 1×1 convolutional layers, partial convolutional layers, attention mechanism layers, batch normalization layers, and SiLU activation function layers; the image processing steps of the partial convolutional attention mechanism module include:

[0026] The enhanced feature input map of the input partial convolutional attention mechanism module is subjected to a 3×3 convolution operation through a series of 3×3 convolutional layers to generate a fourth intermediate convolutional feature map;

[0027] Using a 1×1 convolution layer to perform a 1×1 convolution operation on the fourth intermediate convolution feature map, and output a fifth intermediate convolution feature map;

[0028] Performing image block division on the fifth intermediate convolution feature map to generate a plurality of feature image blocks, and performing a flattening operation on each of the feature image blocks to determine an initial feature vector corresponding to each of the feature image blocks;

[0029] Perform feature extraction on each of the initial feature vectors through an attention mechanism layer, generate a target feature vector corresponding to each of the initial feature vectors, perform feature map restoration, and output a restored vector feature map;

[0030] Using a 1×1 convolution layer and a batch normalization layer to perform a 1×1 convolution operation and normalization on the restored vector feature map to generate a second normalized feature map;

[0031] Inputting the second normalized feature map into the SiLU activation function layer for nonlinear mapping, outputting the second nonlinear feature map and splicing it with the fifth intermediate convolution feature map to determine a spliced ​​feature map;

[0032] Using a 1×1 convolution layer and a batch normalization layer to perform a 1×1 convolution operation and normalization on the concatenated feature map to generate a third normalized feature map;

[0033] Performing nonlinear mapping on the third normalized feature map through a SiLU activation function layer, and outputting a global feature map;

[0034] Using a partial convolutional layer to extract local features from the enhanced feature input map to generate a second local feature map;

[0035] The global feature map and the second local feature map are superimposed to output an enhanced feature output map.

[0036] Optionally, the channel attention mechanism feature fusion network includes a channel attention mechanism module and a 3×3 convolutional layer; the step of performing multi-scale feature fusion on each of the enhanced feature maps through the channel attention mechanism feature fusion network to generate multiple fused feature maps includes:

[0037] Input each of the enhanced feature maps into a channel attention mechanism module for feature selection, and generate a plurality of weight feature maps, wherein the plurality of weight feature maps include a first weight feature map, a second weight feature map, a third weight feature map, and a fourth weight feature map;

[0038] Upsampling the first weight feature map to generate a first upsampled feature map, performing feature selection on the first upsampled feature map through a channel attention mechanism module, and outputting a first intermediate feature map;

[0039] Concatenate the first intermediate feature map and the second weighted feature map to generate a first weighted intermediate feature map, and perform a 3×3 convolution operation on the first weighted intermediate feature map through a 3×3 convolution layer to generate a first fused feature map;

[0040] Upsampling the first fused feature map to generate a second upsampled feature map, performing feature selection on the second upsampled feature map through a channel attention mechanism module, and outputting a second intermediate feature map;

[0041] Concatenate the second intermediate feature map and the third weighted feature map to generate a second weighted intermediate feature map, and perform a 3×3 convolution operation on the second weighted intermediate feature map through a 3×3 convolution layer to generate a second fused feature map;

[0042] Upsampling the second fused feature map to generate a third upsampled feature map, performing feature selection on the third upsampled feature map through a channel attention mechanism module, and outputting a third intermediate feature map;

[0043] The third intermediate feature map and the fourth weighted feature map are concatenated to generate a third weighted intermediate feature map, and a 3×3 convolution operation is performed on the third weighted intermediate feature map through a 3×3 convolution layer to generate a third fused feature map.

[0044] Optionally, the channel attention mechanism module includes a maximum pooling layer, an average pooling layer, a 1×1 convolution layer, a ReLU activation function layer, and a Sigmod activation function layer; the image processing step of the channel attention mechanism module includes:

[0045] The upsampled feature input map of the input channel attention mechanism module is average pooled through the average pooling layer to generate an average pooling feature map;

[0046] Using a 1×1 convolution layer and a ReLU activation function layer to perform a 1×1 convolution operation and nonlinear mapping on the average pooling feature map, and output a third nonlinear feature map;

[0047] Inputting the third nonlinear feature map into a 1×1 convolution layer to perform a 1×1 convolution operation to generate a first feature weight;

[0048] Performing global pooling on the upsampled feature input map through a maximum pooling layer to generate a global pooling feature map;

[0049] Using a 1×1 convolution layer and a ReLU activation function layer to perform a 1×1 convolution operation and nonlinear mapping on the global pooling feature map, and output a fourth nonlinear feature map;

[0050] Inputting the fourth nonlinear feature map into a 1×1 convolution layer to perform a 1×1 convolution operation to generate a second feature weight;

[0051] The first feature weight and the second feature weight are superimposed to determine an initial feature weight, and the initial feature weight is nonlinearly mapped through a Sigmod activation function layer to output a target feature weight;

[0052] Performing element-by-element multiplication on the target feature weight and the upsampled feature input map to determine a multiplied feature map;

[0053] A 1×1 convolution layer is used to perform a 1×1 convolution operation on the multiplied feature map to generate an upsampled feature output map.

[0054] Optionally, before the step of acquiring the image to be detected and inputting the image to be detected into a preset lightweight object detection model, the step includes:

[0055] Obtain a dataset of images to be trained, and use the dataset of images to be trained to perform model training on an initial detection model based on a stochastic gradient descent method to determine a target detection model;

[0056] Performing data type mapping on multiple initial weight activation values ​​of the target detection model to determine an intermediate weight activation value corresponding to each of the initial weight activation values;

[0057] Taking the intermediate weight activation value in the preset quantization threshold interval as the target weight activation value, and taking the initial weight activation value corresponding to the target weight activation value as the weight activation value before quantization;

[0058] Calculating an initial scaling factor and an initial quantization offset according to the pre-quantization weight activation value and the target weight activation value;

[0059] Calculating a plurality of post-quantization weight activation values ​​and a relative entropy according to the plurality of pre-quantization weight activation values, the initial scaling factor, and the initial quantization offset, and determining whether the relative entropy converges;

[0060] If the relative entropy converges, the initial scaling factor is used as the target scaling factor, and the initial quantization offset is used as the target quantization offset;

[0061] Dequantizing the quantized weight activation value of the last layer of the network among the plurality of quantized weight activation values ​​by using the target scaling factor and the target quantization offset to determine a dequantized weight activation value;

[0062] The target detection model is linearly quantized using the inverse quantized weight activation value and each quantized weight activation value to determine the preset lightweight target detection model.

[0063] A second aspect of the present invention provides a lightweight target detection device, comprising:

[0064] An acquisition module is used to acquire an image to be detected and input the image to be detected into a preset lightweight target detection model, wherein the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network;

[0065] An adopting module is used to use the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected to generate multiple enhanced feature maps;

[0066] A generation module, used for performing multi-scale feature fusion on each of the enhanced feature maps through a channel attention mechanism feature fusion network to generate multiple fused feature maps;

[0067] The output module is used to perform target detection on each of the fused feature maps and output lightweight target detection results.

[0068] A third aspect of the present invention provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the lightweight target detection method as described in any one of the above items.

[0069] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program / instruction stored thereon, wherein the computer program / instruction, when executed by a processor, implements the steps of the lightweight target detection method as described in any one of the above items.

[0070] It can be seen from the above technical solutions that the present invention has the following advantages:

[0071] The above technical scheme of the present invention provides a lightweight target detection method, firstly, obtaining an image to be detected, and inputting the image to be detected into a preset lightweight target detection model, wherein the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network; then, the attention mechanism backbone network is used to perform feature enhancement extraction on the image to be detected, and a plurality of enhanced feature maps are generated; multi-scale feature fusion is performed on each enhanced feature map through the channel attention mechanism feature fusion network, and a plurality of fused feature maps are generated; finally, target detection is performed on each fused feature map, and a lightweight target detection result is output; based on the above scheme, after feature enhancement extraction and multi-scale feature fusion are performed on the image to be detected through the attention mechanism backbone network and the channel attention mechanism feature fusion network, target detection is performed on the obtained fused feature map, and the process of outputting the lightweight target detection result can enable the model to effectively retain the position information of the image, and further improve the model detection effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0073] Figure 1 A flowchart of a lightweight target detection method provided by an embodiment of the present invention;

[0074] Figure 2 A schematic diagram of the structure of a preset lightweight target detection model provided by an embodiment of the present invention;

[0075] Figure 3 A flowchart of another lightweight target detection method provided by an embodiment of the present invention;

[0076] Figure 4 A schematic diagram of a process flow for quantizing model parameters of a target detection model provided by an embodiment of the present invention;

[0077] Figure 5 A schematic diagram of the structure of a partial fast convolution module provided by an embodiment of the present invention;

[0078] Figure 6 A schematic diagram of the structure of a partial convolutional attention mechanism module provided by an embodiment of the present invention;

[0079] Figure 7 A schematic diagram of the structure of a channel attention mechanism module provided in an embodiment of the present invention;

[0080] Figure 8 A structural block diagram of a lightweight target detection device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0081] The embodiments of the present invention provide a lightweight target detection method and device, which are used to solve the technical problem that the existing lightweight target detection technology leads to poor model detection effect.

[0082] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0083] See also Figure 1 , Figure 1 A flowchart of the steps of a lightweight target detection method provided by an embodiment of the present invention.

[0084] The present invention provides a lightweight target detection method, comprising:

[0085] Step 101: obtain an image to be detected, and input the image to be detected into a preset lightweight target detection model, where the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network.

[0086] See also Figure 2The preset lightweight target detection model proposed in the present invention is an improvement on the existing Yolov8 (You Only Look Once version 8) model, which is composed of an attention mechanism backbone network (backbone backbone network) and a channel attention mechanism feature fusion network. The improvement of the backbone network is to replace the first two C2f modules (Convolution to Feature) of the backbone network with a partial fast convolution module (FasterNetBlock module) composed of a partial convolution as the core; replace the last two C2f modules of the backbone network with an attention mechanism module (MobileViTBlock module) composed of an attention mechanism layer (transformer) as the core. The module adopts a series structure and is divided into two branches. Finally, the feature maps of the two branches are fused; the channel attention mechanism feature fusion network is composed of a channel attention mechanism module and a feature fusion sub-network. The feature fusion sub-network is composed of a channel attention mechanism module and a 3×3 convolution layer. The SPPF module of the original backbone network is deleted. , replace it with a module consisting of four channel attention mechanisms, namely the channel attention mechanism module, which accepts the feature maps from the four stages of the backbone network (namely the first enhanced feature map, the second enhanced feature map, the third enhanced feature map and the fourth enhanced feature map) respectively, and performs feature selection on these feature maps; replace the original feature fusion part with a feature fusion subnetwork (HS-FPN) consisting of a channel attention mechanism module and a 3×3 convolutional layer, which receives the four feature maps output by the channel attention mechanism module and adopts a top-down structure for feature fusion. In the top-down process, the channel attention mechanism is used for feature selection to complete multi-scale feature fusion.

[0087] In this embodiment, an image to be detected is obtained and input into a preset lightweight target detection model. The preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network.

[0088] Step 102: Use the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected and generate multiple enhanced feature maps.

[0089] The attention mechanism backbone network consists of 3×3 convolutional layers, some fast convolutional modules and some convolutional attention mechanism modules.

[0090] The plurality of enhancement feature maps include a first enhancement feature map, a second enhancement feature map, a third enhancement feature map, and a fourth enhancement feature map.

[0091] Specifically, a 3×3 convolution layer is used to perform a 3×3 convolution operation on the image to be detected, and a first convolution feature map is output; a partial channel operation is performed on the first convolution feature map through a partial fast convolution module, and a first enhanced feature map is output; the first enhanced feature map is output to the partial fast convolution module for partial channel operation to generate a second enhanced feature map; a partial convolution attention mechanism module is used to perform feature superposition on the second enhanced feature map, and a third enhanced feature map is output; a partial convolution attention mechanism module is used to perform feature superposition on the third enhanced feature map, and a fourth enhanced feature map is output.

[0092] In this embodiment, an attention mechanism backbone network is used to perform feature enhancement extraction on the image to be detected to generate multiple enhanced feature maps.

[0093] Step 103: Perform multi-scale feature fusion on each enhanced feature map through the channel attention mechanism feature fusion network to generate multiple fused feature maps.

[0094] The channel attention mechanism feature fusion network consists of a channel attention mechanism module and a 3×3 convolutional layer.

[0095] The multiple fused feature maps include a first fused feature map, a second fused feature map, a third fused feature map, and a fourth fused feature map.

[0096] Specifically, each enhanced feature map is input into the channel attention mechanism module for feature selection to generate multiple weight feature maps, including a first weight feature map, a second weight feature map, a third weight feature map and a fourth weight feature map; the first weight feature map is upsampled to generate a first upsampled feature map, and feature selection is performed on the first upsampled feature map through the channel attention mechanism module to output a first intermediate feature map; the first intermediate feature map and the second weight feature map are concatenated to generate a first weighted intermediate feature map, and a 3×3 convolution operation is performed on the first weighted intermediate feature map through a 3×3 convolution layer to generate a first fused feature map; the first fused feature map is upsampled to generate a second upsampled feature map, and The second upsampled feature map is selected through the channel attention mechanism module to output the second intermediate feature map; the second intermediate feature map and the third weighted feature map are concatenated to generate a second weighted intermediate feature map, and a 3×3 convolution operation is performed on the second weighted intermediate feature map through a 3×3 convolution layer to generate a second fused feature map; the second fused feature map is upsampled to generate a third upsampled feature map, and feature selection is performed on the third upsampled feature map through the channel attention mechanism module to output the third intermediate feature map; the third intermediate feature map and the fourth weighted feature map are concatenated to generate a third weighted intermediate feature map, and a 3×3 convolution operation is performed on the third weighted intermediate feature map through a 3×3 convolution layer to generate a third fused feature map.

[0097] In this embodiment, multi-scale feature fusion is performed on each enhanced feature map through a channel attention mechanism feature fusion network to generate multiple fused feature maps.

[0098] Step 104: perform target detection on each fused feature map and output a lightweight target detection result.

[0099] In this embodiment, target detection is performed on each fused feature map, and a lightweight target detection result is output.

[0100] In an embodiment of the present invention, the present invention provides a lightweight target detection method, firstly, obtaining an image to be detected, and inputting the image to be detected into a preset lightweight target detection model, wherein the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network; then, the attention mechanism backbone network is used to perform feature enhancement extraction on the image to be detected, and a plurality of enhanced feature maps are generated; multi-scale feature fusion is performed on each enhanced feature map through the channel attention mechanism feature fusion network, and a plurality of fused feature maps are generated; finally, target detection is performed on each fused feature map, and a lightweight target detection result is output; based on the above scheme, after feature enhancement extraction and multi-scale feature fusion are performed on the image to be detected through the attention mechanism backbone network and the channel attention mechanism feature fusion network, target detection is performed on the obtained fused feature map, and the process of outputting the lightweight target detection result can enable the model to effectively retain the position information of the image, and further improve the model detection effect.

[0101] See also Figure 3 , Figure 3 A flowchart of another lightweight target detection method provided by an embodiment of the present invention.

[0102] The present invention provides a lightweight target detection method, comprising:

[0103] Step 301: Obtain a dataset of images to be trained, and based on a stochastic gradient descent method, use the dataset of images to be trained to perform model training on an initial detection model to determine a target detection model.

[0104] The image dataset to be trained is the COCO dataset (Common Objects in Context).

[0105] It should be noted that the training parameters are set to a learning rate of 0.01, a momentum of 0.9, and a model training batch number threshold of epochs of 300. Based on the stochastic gradient descent method, the initial detection model is trained using the image data set to be trained. When the current training batch number reaches the model training batch number threshold, the model training is stopped to obtain a trained target detection model.

[0106] In this embodiment, a dataset of images to be trained is obtained, and based on the stochastic gradient descent method, the dataset of images to be trained is used to perform model training on an initial detection model to determine a target detection model.

[0107] Step 302: Perform data type mapping on multiple initial weight activation values ​​of the target detection model to determine the intermediate weight activation value corresponding to each initial weight activation value.

[0108] The initial weight activation values ​​are weights and activation values ​​of float32 data type.

[0109] The intermediate weight activation values ​​are weights and activation values ​​of int8 data type.

[0110] It should be noted that the lightweight method for the model is symmetric linear quantization. The present invention first maps the weights and activation values ​​in the target detection model from float32 to int8, so that the model achieves preliminary lightweight.

[0111] In this embodiment, data type mapping is performed on multiple initial weight activation values ​​of the target detection model to determine the intermediate weight activation values ​​corresponding to each initial weight activation value.

[0112] Step 303: Taking the intermediate weight activation value in the preset quantization threshold interval as the target weight activation value, and taking the initial weight activation value corresponding to the target weight activation value as the weight activation value before quantization.

[0113] It is worth mentioning that see Figure 4 When quantizing the weight activation value, due to the uncertainty of the input, the quantization calibration method is adopted. First, the weight activation value of the float32 data type is inferred once, that is, the original float32 precision model is inferred to obtain the data distribution of each layer, and a threshold T (preset quantization threshold interval) is assumed. The data in the data distribution is selected according to the threshold. The appropriate quantization level (-128-127) for a total of 256 levels is generated, and the quantized distribution is generated. The cross entropy calibration is used to measure the difference between the current distribution and the quantized distribution. After the measurement is completed, the threshold size increases, and this process is repeated continuously to obtain a smaller KL divergence (that is, relative entropy convergence). The parameters are derived, that is, after the threshold T is obtained, the final Rmax-Rmin is obtained, and the final scale is obtained.

[0114] Specifically, the intermediate weight activation value in the preset quantization threshold interval is used as the target weight activation value, each target weight activation value corresponds to an initial weight activation value, and the initial weight activation value corresponding to each target weight activation value is used as the weight activation value before quantization.

[0115] In this embodiment, the intermediate weight activation value in the preset quantization threshold interval is used as the target weight activation value, and the initial weight activation value corresponding to the target weight activation value is used as the weight activation value before quantization.

[0116] Step 304: Calculate an initial scaling factor and an initial quantization offset according to the pre-quantization weight activation value and the target weight activation value.

[0117] It should be noted that the maximum pre-quantization weight activation value and the minimum pre-quantization weight activation value are selected from all pre-quantization weight activation values, and the maximum target weight activation value and the minimum target weight activation value are selected from all target weight activation values. The maximum pre-quantization weight activation value, the minimum pre-quantization weight activation value, the maximum target weight activation value and the minimum target weight activation value are used to calculate the initial scaling factor and the initial quantization offset, wherein the calculation process of the initial scaling factor and the initial quantization offset is specifically as follows:

[0118]

[0119] Where scale is the initial scaling factor; R max is the maximum weight activation value before quantization; R min is the minimum weight activation value before quantization; Q max is the maximum target weight activation value; Q min is the minimum target weight activation value; z is the initial quantization offset.

[0120] In this embodiment, the initial scaling factor and the initial quantization offset are calculated according to the pre-quantization weight activation value and the target weight activation value.

[0121] Step 305: Calculate multiple post-quantization weight activation values ​​and relative entropy based on multiple pre-quantization weight activation values, initial scaling factors, and initial quantization offsets, and determine whether the relative entropy converges.

[0122] Specifically, each pre-quantization weight activation value is quantized by using an initial scaling factor and an initial quantization offset, and a quantized weight activation value corresponding to each pre-quantization weight activation value is output, and then a relative entropy (KL divergence, Kullback Leibler) is calculated based on multiple post-quantization weight activation values ​​and multiple pre-quantization weight activation values; wherein, the quantization process of the pre-quantization weight activation value is specifically as follows:

[0123]

[0124] Among them, Q i is the i-th quantized weight activation value; R i is the i-th weight activation value before quantization; scale is the initial scaling factor; z is the initial quantization offset.

[0125] Furthermore, the calculation process of relative entropy is as follows:

[0126]

[0127] Among them, D KL (R||Q) is the relative entropy; Q i is the i-th quantized weight activation value; R i is the i-th weight activation value before quantization.

[0128] In this embodiment, multiple post-quantization weight activation values ​​and relative entropy are calculated based on multiple pre-quantization weight activation values, initial scaling factors, and initial quantization offsets, and it is determined whether the relative entropy converges.

[0129] Step 306: If the relative entropy converges, the initial scaling factor is used as the target scaling factor, and the initial quantization offset is used as the target quantization offset.

[0130] It should be noted that if the relative entropy converges, the initial scaling factor is used as the target scaling factor and the initial quantization offset is used as the target quantization offset; if the relative entropy does not converge, that is, the KL divergence has not become small enough, the preset quantization threshold interval is updated so that its interval range is increased to obtain a new preset quantization threshold interval, and the target weight activation value is re-screened, that is, the intermediate weight activation value in the new preset quantization threshold interval is used as the new target weight activation value, and the initial weight activation value corresponding to each new target weight activation value is used as the new pre-quantization weight activation value, and then according to the new pre-quantization weight activation value and the new target weight activation value, a new initial scaling factor and a new initial quantization offset are calculated, and according to multiple new pre-quantization weight activation values, new initial scaling factors and new initial quantization offsets, multiple new post-quantization weight activation values ​​and relative entropy are calculated, and the initial scaling factor determined when the relative entropy converges is used as the target scaling factor, and the initial quantization offset determined when the relative entropy converges is used as the target quantization offset, and the update of the preset quantization threshold interval is stopped.

[0131] In this embodiment, if the relative entropy converges, the initial scaling factor is used as the target scaling factor, and the initial quantization offset is used as the target quantization offset.

[0132] Step 307: Dequantize the quantized weight activation value of the last layer of the network among the multiple quantized weight activation values ​​using the target scaling factor and the target quantization offset to determine the dequantized weight activation value.

[0133] The weight activation value of the last layer of the network after quantization is the weight and activation value of the last layer of the target detection model.

[0134] It should be noted that after obtaining a smaller KL divergence, the preset quantization threshold interval T at this time is a suitable preset quantization threshold interval. After determining the target scaling factor and the target quantization offset, the pre-quantization weight activation value corresponding to the target weight activation value in the preset quantization threshold interval is obtained according to the target scaling factor and the target quantization offset. The quantized weight activation value of the last layer of the network in the obtained quantized weight activation value is dequantized to determine the dequantized weight activation value; wherein, the dequantization processing process of the quantized weight activation value of the last layer of the network is specifically as follows:

[0135] R′ i =(Q′ i -z')scale';

[0136] Among them, R′ i is the i-th inverse quantized weight activation value; Q′ i is the weight activation value after quantization of the i-th network last layer; z' is the target quantization offset; scale' is the target scaling factor.

[0137] In this embodiment, the target scaling factor and the target quantization offset are used to dequantize the quantized weight activation values ​​of the last layer of the network among the multiple quantized weight activation values ​​to determine the dequantized weight activation values.

[0138] Step 308: linearly quantize the target detection model using the inverse quantized weight activation value and each quantized weight activation value to determine a preset lightweight target detection model.

[0139] It should be noted that the weights and activation values ​​of the target detection model are updated accordingly based on the dequantized weight activation values ​​and each quantized weight activation value obtained in the above steps, so as to obtain a quantized preset lightweight target detection model. The quantized model is subjected to model inference, and the images of the verification set are input to obtain the model inference prediction output result.

[0140] In this embodiment, the target detection model is linearly quantized using the inverse quantized weight activation value and each quantized weight activation value to determine a preset lightweight target detection model.

[0141] Step 309: Acquire the image to be detected, and input the image to be detected into a preset lightweight target detection model, where the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network.

[0142] In this embodiment, an image to be detected is obtained and input into a preset lightweight target detection model. The preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network.

[0143] Step 310: Use the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected and generate multiple enhanced feature maps.

[0144] The attention mechanism backbone network consists of 3×3 convolutional layers, some fast convolutional modules and some convolutional attention mechanism modules.

[0145] Further, step 310 may include the following sub-steps:

[0146] S3101, using a 3×3 convolution layer to perform a 3×3 convolution operation on the image to be detected, and outputting a first convolution feature map;

[0147] S3102, performing partial channel operations on the first convolution feature map through a partial fast convolution module, and outputting a first enhanced feature map;

[0148] S3103, outputting the first enhanced feature map to a partial fast convolution module for partial channel operation to generate a second enhanced feature map;

[0149] S3104, using a partial convolutional attention mechanism module to perform feature superposition on the second enhanced feature map, and output a third enhanced feature map;

[0150] S3105. Perform feature superposition on the third enhanced feature map through a partial convolutional attention mechanism module, and output a fourth enhanced feature map.

[0151] It should be noted that the attention mechanism backbone network (backbone backbone network) is composed of 3×3 convolutional layers, partial fast convolutional modules and partial convolutional attention mechanism modules, among which the partial fast convolutional modules are composed of 3×3 convolutional layers, partial convolutional layers, 1×1 convolutional layers, batch normalization layers and ReLU activation function layers; the partial convolutional attention mechanism module is composed of 3×3 convolutional layers, 1×1 convolutional layers, partial convolutional layers, attention mechanism layers, batch normalization layers and SiLU activation function layers connected in series, and 3×3 convolutional layers, 1×1 convolutional layers, partial convolutional layers, attention mechanism layers, batch normalization layers and SiLU activation function layers constitute the attention mechanism module (MobileViTBlock module).

[0152] Optionally, the partial fast convolution module includes a 3×3 convolution layer, a partial convolution layer, a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function layer; and the image processing steps of the partial fast convolution module include:

[0153] The convolution feature input map of the input partial fast convolution module is convolved through a 3×3 convolution layer to generate a first intermediate convolution feature map; the partial convolution layer is used to extract local features of the intermediate convolution feature map to generate a first local feature map; a 1×1 convolution operation is performed on the first local feature map through a 1×1 convolution layer to output a second intermediate convolution feature map; the second intermediate convolution feature map is input into a batch normalization layer for normalization to generate a first normalized feature map; a ReLU activation function layer is used to perform nonlinear mapping on the first normalized feature map to output a first nonlinear feature map; a 1×1 convolution operation is performed on the first nonlinear feature map through a 1×1 convolution layer to generate a third intermediate convolution feature map; the third intermediate convolution feature map and the convolution feature input map are superimposed to generate a convolution feature output map.

[0154] The convolution feature input map is a feature map of the input part of the fast convolution module. It can be understood that the convolution feature input map can correspond to any feature map of the input part of the fast convolution module for image processing during model training or detection.

[0155] The first intermediate convolution feature map, the first local feature map, the second intermediate convolution feature map, the first normalized feature map, the first nonlinear feature map, and the third intermediate convolution feature map are all intermediate maps generated in the partial fast convolution module.

[0156] The convolution feature output map is a feature map output by a partial fast convolution module. It can be understood that it can correspond to any feature map output after a partial fast convolution module performs image processing during model training or detection.

[0157] It should be noted that the first two C2f modules of the attention mechanism backbone network are replaced by partial fast convolution modules composed of partial convolution as the core; the partial fast convolution module calculates some channels of the input feature map, thereby reducing the redundant calculation of the convolution kernel. The block composed of it as the core first uses partial convolution to extract its features, then uses 1*1 convolution kernel to expand its number of channels and performs batch normalization and ReLU activation function nonlinearization, and finally uses 1*1 convolution kernel to restore the number of channels, and superimposes the feature map output by the last 1*1 convolution kernel with the original input feature map through splicing to output the final feature map; in this block, the residual connection structure is introduced to slow down the gradient vanishing phenomenon generated by the training process. At the same time, some channels of the input feature map are calculated to reduce the redundant calculation of the convolution kernel.

[0158] Optionally, the partial convolutional attention mechanism module includes a series of 3×3 convolutional layers, 1×1 convolutional layers, partial convolutional layers, attention mechanism layers, batch normalization layers, and SiLU activation function layers; the image processing steps of the partial convolutional attention mechanism module include:

[0159] The enhanced feature input map of the input part of the convolution attention mechanism module is subjected to a 3×3 convolution operation through a series of 3×3 convolution layers to generate a fourth intermediate convolution feature map; a 1×1 convolution layer is used to perform a 1×1 convolution operation on the fourth intermediate convolution feature map, and a fifth intermediate convolution feature map is output; the fifth intermediate convolution feature map is divided into image blocks to generate multiple feature image blocks, and each feature image block is flattened to determine the initial feature vector corresponding to each feature image block; each initial feature vector is extracted through the attention mechanism layer to generate a target feature vector corresponding to each initial feature vector and restore the feature map, and the restored vector feature map is output; a 1×1 convolution layer and a batch normalization layer are used to restore the target feature vector corresponding to each initial feature vector. The vector feature map is subjected to 1×1 convolution operation and normalization to generate a second normalized feature map; the second normalized feature map is input into the SiLU activation function layer for nonlinear mapping, and the second nonlinear feature map is output and concatenated with the fifth intermediate convolution feature map to determine the concatenated feature map; the concatenated feature map is subjected to 1×1 convolution operation and normalization by a 1×1 convolution layer and a batch normalization layer to generate a third normalized feature map; the third normalized feature map is subjected to nonlinear mapping by the SiLU activation function layer to output a global feature map; the partial convolution layer is used to extract local features from the enhanced feature input map to generate a second local feature map; the global feature map and the second local feature map are superimposed to output an enhanced feature output map.

[0160] The enhanced feature input map is a feature map of the input partial convolutional attention mechanism module. It can be understood that the enhanced feature input map can correspond to any feature map of the input partial convolutional attention mechanism module for image processing during model training or detection.

[0161] The fourth intermediate convolution feature map, the fifth intermediate convolution feature map, the restored vector feature map, the second normalized feature map, the second nonlinear feature map, the concatenated feature map, the third normalized feature map, the global feature map, and the second local feature map are all intermediate maps generated in the partial convolution attention mechanism module.

[0162] The enhanced feature output map is a feature map output by the partial convolutional attention mechanism module. It can be understood that it can correspond to any feature map output after the partial convolutional attention mechanism module performs image processing during model training or detection.

[0163] It should be noted that the last two C2f modules of the backbone network are replaced by an attention mechanism module (MobileViTBlock module) with transformer as the core, which is a series structure composed of partial convolution and transformer. In the first branch, partial convolution is used to extract features from the feature map to extract local features of the feature map. In the second branch, the depth-separable convolution is first used instead of the fully connected layer for position encoding, and then two branches are derived, one for storing the value of the current feature map, which is used for splicing with the feature map that has passed the transformer at the end; the other branch divides the feature map into 5*5 patches (image blocks), flattens the patches into vectors, and sends them to the transformer. The number of transformers here depends on the depth of the network, here stage3 is 2 and stage4 is 4. After the Transformer processes the vector, it restores the vector group to a feature map and uses a 1*1 convolution kernel to change its number of channels. After batch normalization and SiLU activation function nonlinearization, it is spliced ​​with the previously derived branch. After splicing, the 1*1 convolution kernel is used again to adjust the number of channels, remove redundant features, and obtain the output of the second branch. This branch uses the transformer as the core to process the feature map and obtain the global features of the feature map. Finally, the outputs of the first branch and the second branch are superimposed to obtain a feature map that combines global features and local features.

[0164] In this embodiment, an attention mechanism backbone network is used to perform feature enhancement extraction on the image to be detected to generate multiple enhanced feature maps.

[0165] Step 311: Perform multi-scale feature fusion on each enhanced feature map through the channel attention mechanism feature fusion network to generate multiple fused feature maps.

[0166] The channel attention mechanism feature fusion network consists of a channel attention mechanism module and a 3×3 convolutional layer.

[0167] Further, step 311 may include the following sub-steps:

[0168] S3111, input each enhanced feature map into the channel attention mechanism module for feature selection, and generate multiple weight feature maps, wherein the multiple weight feature maps include a first weight feature map, a second weight feature map, a third weight feature map, and a fourth weight feature map;

[0169] S3112, upsampling the first weight feature map to generate a first upsampled feature map, performing feature selection on the first upsampled feature map through a channel attention mechanism module, and outputting a first intermediate feature map;

[0170] S3113, concatenating the first intermediate feature map and the second weighted feature map to generate a first weighted intermediate feature map, and performing a 3×3 convolution operation on the first weighted intermediate feature map through a 3×3 convolution layer to generate a first fused feature map;

[0171] S3114, upsampling the first fused feature map to generate a second upsampled feature map, performing feature selection on the second upsampled feature map through a channel attention mechanism module, and outputting a second intermediate feature map;

[0172] S3115, concatenating the second intermediate feature map and the third weighted feature map to generate a second weighted intermediate feature map, and performing a 3×3 convolution operation on the second weighted intermediate feature map through a 3×3 convolution layer to generate a second fused feature map;

[0173] S3116, upsampling the second fused feature map to generate a third upsampled feature map, performing feature selection on the third upsampled feature map through a channel attention mechanism module, and outputting a third intermediate feature map;

[0174] S3117. Concatenate the third intermediate feature map and the fourth weighted feature map to generate a third weighted intermediate feature map, and perform a 3×3 convolution operation on the third weighted intermediate feature map through a 3×3 convolution layer to generate a third fused feature map.

[0175] It should be noted that the channel attention mechanism feature fusion network first processes the input feature map through four channel attention mechanism modules, and then inputs the feature map output after processing by the four channel attention mechanism modules into the feature fusion sub-network. The feature fusion sub-network first upsamples the input feature map, and then processes it through the channel attention mechanism module and the 3×3 convolution layer to output the fused feature map.

[0176] Furthermore, the original feature fusion part is replaced by a feature fusion subnetwork (HS-FPN) consisting of a channel attention mechanism module and a 3×3 convolutional layer, which receives four feature maps from the channel attention mechanism module and adopts a top-down structure for feature fusion. In the top-down process, the channel attention mechanism is also used for feature selection to complete multi-scale feature fusion. The feature map of the upper stage is fused with the map of the current stage to form a top-down pyramid structure. First, the upper feature map is upsampled so that its resolution is equal to the feature map of the current stage, and then the CA module is used to select features. After the feature selection, the two feature maps are spliced, and finally a 3*3 convolution is used to extract features to extract the fused feature map; the processing process of the feature fusion subnetwork can be expressed as:

[0177] α=Conv3×3 (Concat(CA(upsample(β1)),β2));

[0178] Among them, α is the fusion feature map; Conv 3×3 (·) is a 3*3 convolution operation; Concat(·) is a concatenation operation; CA(·) is a feature selection operation of the CA module; upsample(·) is an upsampling operation; β1 is the upper layer feature map; β2 is the current layer feature map.

[0179] Optionally, the channel attention mechanism module includes a maximum pooling layer, an average pooling layer, a 1×1 convolution layer, a ReLU activation function layer, and a Sigmod activation function layer; the image processing step of the channel attention mechanism module includes:

[0180] The upsampled feature input map of the input channel attention mechanism module is average pooled through the average pooling layer to generate an average pooling feature map; a 1×1 convolution layer and a ReLU activation function layer are used to perform a 1×1 convolution operation and nonlinear mapping on the average pooling feature map to output a third nonlinear feature map; the third nonlinear feature map is input into a 1×1 convolution layer for a 1×1 convolution operation to generate a first feature weight; the upsampled feature input map is globally pooled through a maximum pooling layer to generate a global pooling feature map; a 1×1 convolution layer and a ReLU activation function layer are used to perform a 1×1 convolution operation on the global pooling feature map. Perform 1×1 convolution operation and nonlinear mapping to output the fourth nonlinear feature map; input the fourth nonlinear feature map to the 1×1 convolution layer for 1×1 convolution operation to generate the second feature weight; superimpose the first feature weight and the second feature weight to determine the initial feature weight, and perform nonlinear mapping on the initial feature weight through the Sigmod activation function layer to output the target feature weight; perform element-by-element multiplication of the target feature weight and the upsampled feature input map to determine the multiplied feature map; use the 1×1 convolution layer to perform 1×1 convolution operation on the multiplied feature map to generate the upsampled feature output map.

[0181] The upsampled feature input map is a feature map of the input channel attention mechanism module (CA). It can be understood that the upsampled feature input map can correspond to any feature map of the input channel attention mechanism module for image processing during model training or detection.

[0182] The average pooling feature map, the third non-linear feature map, the global pooling feature map, the fourth non-linear feature map, and the multiplication feature map are all intermediate maps generated in the channel attention mechanism module.

[0183] The upsampled feature output map is a feature map output by the channel attention mechanism module. It can be understood that it can correspond to any feature map output after the channel attention mechanism module performs image processing during model training or detection.

[0184] It should be noted that the SPPF module of the backbone network is deleted and replaced by a module consisting of four channel attention mechanisms, which accept feature maps from the four stages of the backbone network respectively and perform feature selection on these feature maps. The channel attention mechanism (CA) module is characterized in that it is divided into two branches. One branch passes through the maximum pooling layer, then passes through a 1*1 convolution kernel to adjust the number of channels, and finally is nonlinearized by the ReLU activation function; the other branch structure is the same as the previous branch, except that the maximum pooling layer is changed to an average pooling layer. Both pooling layers pool the feature map to a size of 1*1 for generating feature selection weights. Finally, the results of the two branches are added to obtain the initial weight of feature selection. This weight is compressed to between -1 and 1 through the sigmoid function to obtain a weight that can be used for feature selection. Finally, this weight is multiplied by the original input feature map to obtain the feature map after feature selection. After obtaining this feature map, the number of channels is adjusted using a 1*1 convolution, and the number of channels is uniformly adjusted to 256. Among them, the calculation formula of the CA module can be expressed as:

[0185] out = x × sigmoid (Conv 1×1 (ReLU(Conv 1×1 (Avgpool(x))))

[0186] +Conv 1×1 (ReLU(Conv 1×1 (Maxpool(x)))));

[0187] Among them, out is the multiplication feature map; x is the up-sampled feature input map; sigmod(·) is the sigmod activation function; Conv 1×1 (·) is a 1*1 convolution operation; ReLU(·) is a ReLU activation function; Avgpool(·) is an average pooling operation; Maxpool(·) is a maximum pooling operation.

[0188] In this embodiment, multi-scale feature fusion is performed on each enhanced feature map through a channel attention mechanism feature fusion network to generate multiple fused feature maps.

[0189] Step 312: perform target detection on each fused feature map and output a lightweight target detection result.

[0190] In this embodiment, target detection is performed on each fused feature map, and a lightweight target detection result is output.

[0191] As a comparison of technical effects, we can refer to existing technologies. In the field of target detection, lightweight is an important research direction, which aims to reduce the size of the model, reduce the amount of model calculation, and try to maintain the performance of the model. With the development of lightweight models, transformers are introduced into the network structure of lightweight models. Under the premise of having a large enough data set for training, the detection effect of transformers is better than that of traditional CNNs. However, transformers can only extract global features of images when performing feature extraction, and the image must be divided into patches before entering the transformer encoder, which makes transformers insensitive to the position information of the image. How to solve the problem of transformers being insensitive to local features and position information is an important research topic. At the same time, due to the large number of transformer parameters, how to quantize the training model to reduce model parameters has also become a topic to be studied.

[0192] In view of the above problems, the present invention proposes a lightweight target detection method, which integrates MobileViT and FasterNet, improves the backbone network; adds a channel attention mechanism for feature selection; replaces the Neck feature fusion part with HS-FPN; and performs int8 quantization on the generated model parameters. Based on the original model, the present invention improves the network structure of the model so that the model can extract more semantic information while retaining the position information of the image, and improves the detection speed and parameter amount of the model through a lightweight method, thereby solving the problem that the transformer is difficult to grasp the local features of the image during detection. While introducing the lightweight transformer structure MobileVIT, the present invention improves its structure, adds a partial convolution module to extract the local features of the feature map, thereby solving the problem that the transformer is insensitive to position information, introduces a multi-scale fusion structure, replaces the original MobileViT front backbone network with a faster FasterNet module, and under the support of its partial convolution, can effectively retain the position information of the image. On the multi-scale feature fusion structure introduced by the present invention, a feature selection module is also added to remove the redundant information of the feature map. Finally, the model quantization method was used to reduce the number of original model parameters, making it more suitable for model deployment on mobile terminals.

[0193] In summary, while introducing the lightweight transformer structure MobileVIT, the present invention improves its structure and adds a partial convolution module to extract local features of the feature map; solves the problem of transformer insensitivity to position information, introduces a multi-scale fusion structure, replaces the original MobileViT front backbone network with a faster FasterNet module, and with the support of its partial convolution, can effectively retain the position information of the image; the present invention also adds a feature selection module to the introduced multi-scale feature fusion structure, which can remove redundant information of the feature map. In addition, the model quantization method is used to reduce the original model parameters, which is more suitable for model deployment on the mobile terminal.

[0194] In an embodiment of the present invention, the present invention provides a lightweight target detection method, firstly, obtaining an image to be detected, and inputting the image to be detected into a preset lightweight target detection model, wherein the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network; then, the attention mechanism backbone network is used to perform feature enhancement extraction on the image to be detected, and a plurality of enhanced feature maps are generated; multi-scale feature fusion is performed on each enhanced feature map through the channel attention mechanism feature fusion network, and a plurality of fused feature maps are generated; finally, target detection is performed on each fused feature map, and a lightweight target detection result is output; based on the above scheme, after feature enhancement extraction and multi-scale feature fusion are performed on the image to be detected through the attention mechanism backbone network and the channel attention mechanism feature fusion network, target detection is performed on the obtained fused feature map, and the process of outputting the lightweight target detection result can enable the model to effectively retain the position information of the image, and further improve the model detection effect.

[0195] See also Figure 8 , Figure 8 A structural block diagram of a lightweight target detection device provided by an embodiment of the present invention.

[0196] The present invention provides a lightweight target detection device, comprising:

[0197] An acquisition module 801 is used to acquire an image to be detected and input the image to be detected into a preset lightweight target detection model, where the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network;

[0198] Using module 802, for using the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected, and generating multiple enhanced feature maps;

[0199] A generation module 803 is used to perform multi-scale feature fusion on each enhanced feature map through a channel attention mechanism feature fusion network to generate multiple fused feature maps;

[0200] The output module 804 is used to perform target detection on each fused feature map and output a lightweight target detection result.

[0201] Further, the attention mechanism backbone network includes a 3×3 convolution layer, a partial fast convolution module and a partial convolution attention mechanism module; the multiple enhanced feature maps include a first enhanced feature map, a second enhanced feature map, a third enhanced feature map and a fourth enhanced feature map; the module 802 is used to:

[0202] Use a 3×3 convolution layer to perform a 3×3 convolution operation on the image to be detected and output the first convolution feature map;

[0203] Performing partial channel operations on the first convolution feature map through a partial fast convolution module, and outputting a first enhanced feature map;

[0204] Outputting the first enhanced feature map to a partial fast convolution module for partial channel operation to generate a second enhanced feature map;

[0205] A partial convolutional attention mechanism module is used to perform feature superposition on the second enhanced feature map, and a third enhanced feature map is output;

[0206] The third enhanced feature map is superimposed on features through a partial convolutional attention mechanism module to output the fourth enhanced feature map.

[0207] Optionally, the partial fast convolution module includes a 3×3 convolution layer, a partial convolution layer, a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function layer; and the image processing steps of the partial fast convolution module include:

[0208] The convolution feature input map of the fast convolution module of the input part is convolved through a 3×3 convolution layer to generate a first intermediate convolution feature map;

[0209] Using a partial convolutional layer to extract local features from the intermediate convolutional feature map to generate a first local feature map;

[0210] Perform a 1×1 convolution operation on the first local feature map through a 1×1 convolution layer, and output a second intermediate convolution feature map;

[0211] Input the second intermediate convolutional feature map into the batch normalization layer for normalization to generate a first normalized feature map;

[0212] A ReLU activation function layer is used to perform nonlinear mapping on the first normalized feature map, and a first nonlinear feature map is output;

[0213] Performing a 1×1 convolution operation on the first nonlinear feature map through a 1×1 convolution layer to generate a third intermediate convolution feature map;

[0214] The third intermediate convolutional feature map and the convolutional feature input map are superimposed to generate a convolutional feature output map.

[0215] Optionally, the partial convolutional attention mechanism module includes a series of 3×3 convolutional layers, 1×1 convolutional layers, partial convolutional layers, attention mechanism layers, batch normalization layers, and SiLU activation function layers; the image processing steps of the partial convolutional attention mechanism module include:

[0216] The enhanced feature input map of the input partial convolutional attention mechanism module is subjected to a 3×3 convolution operation through a series of 3×3 convolutional layers to generate a fourth intermediate convolutional feature map;

[0217] A 1×1 convolution layer is used to perform a 1×1 convolution operation on the fourth intermediate convolution feature map, and a fifth intermediate convolution feature map is output;

[0218] Performing image block division on the fifth intermediate convolution feature map to generate a plurality of feature image blocks, and performing a flattening operation on each feature image block to determine an initial feature vector corresponding to each feature image block;

[0219] The attention mechanism layer is used to extract features from each initial feature vector, generate target feature vectors corresponding to each initial feature vector, restore the feature map, and output the restored vector feature map;

[0220] A 1×1 convolution layer and a batch normalization layer are used to perform a 1×1 convolution operation and normalization on the restored vector feature map to generate a second normalized feature map;

[0221] Input the second normalized feature map to the SiLU activation function layer for nonlinear mapping, output the second nonlinear feature map and splice it with the fifth intermediate convolution feature map to determine the spliced ​​feature map;

[0222] Use a 1×1 convolution layer and a batch normalization layer to perform a 1×1 convolution operation and normalization on the concatenated feature map to generate a third normalized feature map;

[0223] The third normalized feature map is nonlinearly mapped through the SiLU activation function layer to output a global feature map;

[0224] A partial convolutional layer is used to extract local features from the enhanced feature input map to generate a second local feature map;

[0225] The global feature map and the second local feature map are superimposed to output an enhanced feature output map.

[0226] Furthermore, the channel attention mechanism feature fusion network includes a channel attention mechanism module and a 3×3 convolution layer; the generation module 803 is specifically used for:

[0227] Input each enhanced feature map into the channel attention mechanism module for feature selection, and generate multiple weight feature maps, wherein the multiple weight feature maps include a first weight feature map, a second weight feature map, a third weight feature map, and a fourth weight feature map;

[0228] Upsampling the first weight feature map to generate a first upsampled feature map, performing feature selection on the first upsampled feature map through a channel attention mechanism module, and outputting a first intermediate feature map;

[0229] The first intermediate feature map and the second weighted feature map are concatenated to generate a first weighted intermediate feature map, and a 3×3 convolution operation is performed on the first weighted intermediate feature map through a 3×3 convolution layer to generate a first fused feature map;

[0230] Upsampling the first fused feature map to generate a second upsampled feature map, performing feature selection on the second upsampled feature map through a channel attention mechanism module, and outputting a second intermediate feature map;

[0231] The second intermediate feature map and the third weighted feature map are concatenated to generate a second weighted intermediate feature map, and a 3×3 convolution operation is performed on the second weighted intermediate feature map through a 3×3 convolution layer to generate a second fused feature map;

[0232] Upsampling the second fused feature map to generate a third upsampled feature map, performing feature selection on the third upsampled feature map through a channel attention mechanism module, and outputting a third intermediate feature map;

[0233] The third intermediate feature map and the fourth weighted feature map are concatenated to generate a third weighted intermediate feature map, and a 3×3 convolution operation is performed on the third weighted intermediate feature map through a 3×3 convolution layer to generate a third fused feature map.

[0234] Optionally, the channel attention mechanism module includes a maximum pooling layer, an average pooling layer, a 1×1 convolution layer, a ReLU activation function layer, and a Sigmod activation function layer; the image processing step of the channel attention mechanism module includes:

[0235] The upsampled feature input map of the input channel attention mechanism module is average pooled through the average pooling layer to generate an average pooling feature map;

[0236] A 1×1 convolution layer and a ReLU activation function layer are used to perform a 1×1 convolution operation and nonlinear mapping on the average pooling feature map, and a third nonlinear feature map is output;

[0237] Input the third nonlinear feature map into the 1×1 convolution layer to perform a 1×1 convolution operation to generate a first feature weight;

[0238] Perform global pooling on the upsampled feature input map through the maximum pooling layer to generate a global pooling feature map;

[0239] A 1×1 convolution layer and a ReLU activation function layer are used to perform a 1×1 convolution operation and nonlinear mapping on the global pooling feature map, and a fourth nonlinear feature map is output;

[0240] Input the fourth nonlinear feature map into the 1×1 convolution layer to perform a 1×1 convolution operation to generate a second feature weight;

[0241] The first feature weight and the second feature weight are superimposed to determine the initial feature weight, and the initial feature weight is nonlinearly mapped through the Sigmod activation function layer to output the target feature weight;

[0242] Perform element-by-element multiplication of the target feature weight and the upsampled feature input map to determine the multiplied feature map;

[0243] A 1×1 convolution layer is used to perform a 1×1 convolution operation on the multiplied feature map to generate an upsampled feature output map.

[0244] In an optional embodiment, the device further comprises:

[0245] The first module is used to obtain a dataset of images to be trained, and based on the stochastic gradient descent method, use the dataset of images to be trained to train the initial detection model, so as to determine the target detection model;

[0246] The second module is used to perform data type mapping on multiple initial weight activation values ​​of the target detection model and determine the intermediate weight activation value corresponding to each initial weight activation value;

[0247] The third module is used to use the intermediate weight activation value in the preset quantization threshold interval as the target weight activation value and the initial weight activation value corresponding to the target weight activation value as the weight activation value before quantization;

[0248] The fourth module is used to calculate the initial scaling factor and the initial quantization offset according to the pre-quantization weight activation value and the target weight activation value;

[0249] The fifth module is used to calculate multiple post-quantization weight activation values ​​and relative entropy according to multiple pre-quantization weight activation values, initial scaling factors and initial quantization offsets, and determine whether the relative entropy converges;

[0250] A sixth module is used for taking the initial scaling factor as the target scaling factor and the initial quantization offset as the target quantization offset if the relative entropy converges;

[0251] The seventh module is used to dequantize the quantized weight activation value of the last layer of the network among the multiple quantized weight activation values ​​by using the target scaling factor and the target quantization offset to determine the dequantized weight activation value;

[0252] The eighth module is used to linearly quantize the target detection model using the inverse quantized weight activation value and each quantized weight activation value to determine a preset lightweight target detection model.

[0253] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0254] An embodiment of the present invention further provides a computer device, including a memory and a processor, wherein a computer program is stored in the memory; when the computer program is executed by the processor, the processor executes the steps of the lightweight target detection method as described in any of the above embodiments.

[0255] An embodiment of the present invention further provides a computer-readable storage medium having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, the steps of the lightweight target detection method as in any of the above embodiments are implemented.

[0256] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0257] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0258] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A lightweight target detection method, characterized in that: include: Acquire an image to be detected, and input the image to be detected into a preset lightweight target detection model, wherein the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network; Using the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected, and generate multiple enhanced feature maps; Perform multi-scale feature fusion on each of the enhanced feature maps through a channel attention mechanism feature fusion network to generate multiple fused feature maps; Perform target detection on each of the fused feature maps and output a lightweight target detection result.

2. The lightweight target detection method according to claim 1, characterized in that: The attention mechanism backbone network includes a 3×3 convolution layer, a partial fast convolution module and a partial convolution attention mechanism module; the multiple enhanced feature maps include a first enhanced feature map, a second enhanced feature map, a third enhanced feature map and a fourth enhanced feature map; the step of using the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected and generate multiple enhanced feature maps includes: Using a 3×3 convolution layer to perform a 3×3 convolution operation on the image to be detected, and output a first convolution feature map; Performing partial channel operations on the first convolution feature map through a partial fast convolution module, and outputting a first enhanced feature map; Outputting the first enhanced feature map to a partial fast convolution module for partial channel operation to generate a second enhanced feature map; Using a partial convolutional attention mechanism module to perform feature superposition on the second enhanced feature map, and output a third enhanced feature map; The third enhanced feature map is feature superimposed through a partial convolutional attention mechanism module to output a fourth enhanced feature map.

3. The lightweight target detection method according to claim 2, characterized in that: The partial fast convolution module includes a 3×3 convolution layer, a partial convolution layer, a 1×1 convolution layer, a batch normalization layer and a ReLU activation function layer; the image processing steps of the partial fast convolution module include: The convolution feature input map of the fast convolution module of the input part is convolved through a 3×3 convolution layer to generate a first intermediate convolution feature map; Using a partial convolutional layer to extract local features from the intermediate convolutional feature map to generate a first local feature map; Performing a 1×1 convolution operation on the first local feature map through a 1×1 convolution layer, and outputting a second intermediate convolution feature map; Inputting the second intermediate convolutional feature map into a batch normalization layer for normalization to generate a first normalized feature map; Using a ReLU activation function layer to perform nonlinear mapping on the first normalized feature map, and output a first nonlinear feature map; Performing a 1×1 convolution operation on the first nonlinear feature map through a 1×1 convolution layer to generate a third intermediate convolution feature map; The third intermediate convolutional feature map and the convolutional feature input map are superimposed to generate a convolutional feature output map.

4. The lightweight target detection method according to claim 2, characterized in that: The partial convolutional attention mechanism module includes a series of 3×3 convolutional layers, 1×1 convolutional layers, partial convolutional layers, attention mechanism layers, batch normalization layers, and SiLU activation function layers; the image processing steps of the partial convolutional attention mechanism module include: The enhanced feature input map of the input partial convolutional attention mechanism module is subjected to a 3×3 convolution operation through a series of 3×3 convolutional layers to generate a fourth intermediate convolutional feature map; Using a 1×1 convolution layer to perform a 1×1 convolution operation on the fourth intermediate convolution feature map, and output a fifth intermediate convolution feature map; Performing image block division on the fifth intermediate convolution feature map to generate a plurality of feature image blocks, and performing a flattening operation on each of the feature image blocks to determine an initial feature vector corresponding to each of the feature image blocks; Perform feature extraction on each of the initial feature vectors through an attention mechanism layer, generate a target feature vector corresponding to each of the initial feature vectors, perform feature map restoration, and output a restored vector feature map; Using a 1×1 convolution layer and a batch normalization layer to perform a 1×1 convolution operation and normalization on the restored vector feature map to generate a second normalized feature map; Inputting the second normalized feature map into the SiLU activation function layer for nonlinear mapping, outputting the second nonlinear feature map and splicing it with the fifth intermediate convolution feature map to determine a spliced ​​feature map; Using a 1×1 convolution layer and a batch normalization layer to perform a 1×1 convolution operation and normalization on the concatenated feature map to generate a third normalized feature map; Performing nonlinear mapping on the third normalized feature map through a SiLU activation function layer, and outputting a global feature map; Using a partial convolutional layer to extract local features from the enhanced feature input map to generate a second local feature map; The global feature map and the second local feature map are superimposed to output an enhanced feature output map.

5. The lightweight target detection method according to claim 1, characterized in that: The channel attention mechanism feature fusion network includes a channel attention mechanism module and a 3×3 convolution layer; the step of performing multi-scale feature fusion on each of the enhanced feature maps through the channel attention mechanism feature fusion network to generate multiple fused feature maps includes: Input each of the enhanced feature maps into a channel attention mechanism module for feature selection, and generate a plurality of weight feature maps, wherein the plurality of weight feature maps include a first weight feature map, a second weight feature map, a third weight feature map, and a fourth weight feature map; Upsampling the first weight feature map to generate a first upsampled feature map, performing feature selection on the first upsampled feature map through a channel attention mechanism module, and outputting a first intermediate feature map; Concatenate the first intermediate feature map and the second weighted feature map to generate a first weighted intermediate feature map, and perform a 3×3 convolution operation on the first weighted intermediate feature map through a 3×3 convolution layer to generate a first fused feature map; Upsampling the first fused feature map to generate a second upsampled feature map, performing feature selection on the second upsampled feature map through a channel attention mechanism module, and outputting a second intermediate feature map; Concatenate the second intermediate feature map and the third weighted feature map to generate a second weighted intermediate feature map, and perform a 3×3 convolution operation on the second weighted intermediate feature map through a 3×3 convolution layer to generate a second fused feature map; Upsampling the second fused feature map to generate a third upsampled feature map, performing feature selection on the third upsampled feature map through a channel attention mechanism module, and outputting a third intermediate feature map; The third intermediate feature map and the fourth weighted feature map are concatenated to generate a third weighted intermediate feature map, and a 3×3 convolution operation is performed on the third weighted intermediate feature map through a 3×3 convolution layer to generate a third fused feature map.

6. The lightweight target detection method according to claim 5, characterized in that: The channel attention mechanism module includes a maximum pooling layer, an average pooling layer, a 1×1 convolution layer, a ReLU activation function layer, and a Sigmod activation function layer; the image processing steps of the channel attention mechanism module include: The upsampled feature input map of the input channel attention mechanism module is average pooled through the average pooling layer to generate an average pooling feature map; Using a 1×1 convolution layer and a ReLU activation function layer to perform a 1×1 convolution operation and nonlinear mapping on the average pooling feature map, and output a third nonlinear feature map; Inputting the third nonlinear feature map into a 1×1 convolution layer to perform a 1×1 convolution operation to generate a first feature weight; Performing global pooling on the upsampled feature input map through a maximum pooling layer to generate a global pooling feature map; Using a 1×1 convolution layer and a ReLU activation function layer to perform a 1×1 convolution operation and nonlinear mapping on the global pooling feature map, and output a fourth nonlinear feature map; Inputting the fourth nonlinear feature map into a 1×1 convolution layer to perform a 1×1 convolution operation to generate a second feature weight; The first feature weight and the second feature weight are superimposed to determine an initial feature weight, and the initial feature weight is nonlinearly mapped through a Sigmod activation function layer to output a target feature weight; Performing element-by-element multiplication on the target feature weight and the upsampled feature input map to determine a multiplied feature map; A 1×1 convolution layer is used to perform a 1×1 convolution operation on the multiplied feature map to generate an upsampled feature output map.

7. The lightweight target detection method according to claim 1, characterized in that: Before the step of acquiring the image to be detected and inputting the image to be detected into the preset lightweight target detection model, the method includes: Obtain a dataset of images to be trained, and use the dataset of images to be trained to perform model training on an initial detection model based on a stochastic gradient descent method to determine a target detection model; Performing data type mapping on multiple initial weight activation values ​​of the target detection model to determine an intermediate weight activation value corresponding to each of the initial weight activation values; Taking the intermediate weight activation value in the preset quantization threshold interval as the target weight activation value, and taking the initial weight activation value corresponding to the target weight activation value as the weight activation value before quantization; Calculating an initial scaling factor and an initial quantization offset according to the pre-quantization weight activation value and the target weight activation value; Calculating a plurality of post-quantization weight activation values ​​and a relative entropy according to the plurality of pre-quantization weight activation values, the initial scaling factor, and the initial quantization offset, and determining whether the relative entropy converges; If the relative entropy converges, the initial scaling factor is used as the target scaling factor, and the initial quantization offset is used as the target quantization offset; Dequantizing the quantized weight activation value of the last layer of the network among the plurality of quantized weight activation values ​​by using the target scaling factor and the target quantization offset to determine a dequantized weight activation value; The target detection model is linearly quantized using the inverse quantized weight activation value and each quantized weight activation value to determine the preset lightweight target detection model.

8. A lightweight target detection device, characterized in that: include: An acquisition module is used to acquire an image to be detected and input the image to be detected into a preset lightweight target detection model, wherein the preset lightweight target detection model includes an attention mechanism backbone network and a channel attention mechanism feature fusion network; An adopting module is used to use the attention mechanism backbone network to perform feature enhancement extraction on the image to be detected to generate multiple enhanced feature maps; A generation module, used for performing multi-scale feature fusion on each of the enhanced feature maps through a channel attention mechanism feature fusion network to generate multiple fused feature maps; The output module is used to perform target detection on each of the fused feature maps and output lightweight target detection results.

9. A computer device, characterized in that: It includes a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the steps of the lightweight target detection method according to any one of claims 1 to 6.

10. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the lightweight target detection method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Marine small target detection method and system based on dynamic task alignment

    CN119399444A

  • Lightweight fire hazard multi-target detection method in electric power environment

    CN119600265A

  • A multi-target detection method for lightweight fire hazards in power environments

    CN119600265B

  • Target lightweight detection method and system based on attention feature enhancement

    CN121147496A

  • Target lightweight detection method and system based on attention feature enhancement

    CN121147496B