Improved target detection method based on YOLOv5s

By improving the backbone network and feature fusion network of the YOLOv5 algorithm, using the DGLayer layer and ESE attention mechanism, combined with data enhancement and CIoU loss function, the YOLOv5 algorithm's shortcomings in detection accuracy are solved and the detection accuracy is improved under real-time performance. .

CN118762271APending Publication Date: 2024-10-11HUAIHUA UNIV
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202310302519.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-27
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

When the YOLOv5 algorithm pursues real-time performance, it abandons detection accuracy, resulting in inaccurate target frame positioning and low detection accuracy for small targets. It is necessary to improve detection accuracy while maintaining real-time performance.

Method used

Improve the backbone network and feature fusion network model of the YOLOv5 algorithm by replacing the C3 layer with the DGLayer layer, adopting the CSP structure and ESE attention mechanism, and introducing the channel cleaning mechanism, combining data enhancement and Kmeans algorithm to generate anchor boxes, and using the CIoU loss function. Backpropagation improves detection accuracy.

Benefits of technology

While ensuring that the complexity of the network algorithm does not change significantly, the detection accuracy has been significantly improved, and the calculation amount index has increased by 7%. On the COCO2017 data set, mAP0.5 and mAP0.5-0.95 have increased by 1.1% and 1.3 respectively. %.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118762271A_ABST
    Figure CN118762271A_ABST
Patent Text Reader

Abstract

The invention discloses an improved target detection method based on YOLOv5s, and relates to the technical field of general target detection, and the method comprises the steps: carrying out the data enhancement of a COCO2017 data set; constructing an improved backbone network model based on a YOLOv5s algorithm; inputting the enhanced data set into an improved backbone network model based on a YOLOv5s algorithm to obtain three feature maps with different channel numbers and widths and heights; constructing a feature fusion network model based on YOLOv5s; inputting three feature maps with different channel numbers and widths and heights output by the improved backbone network model into a feature fusion network model to obtain three feature maps with different widths and heights and the same channel number; and based on three feature maps with different widths, heights and sizes and the same number of channels output by the feature fusion network, predicting a COCO2017 data set picture, calculating a target prediction probability and a target positioning frame, and determining a corresponding category prediction result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of general target detection, and in particular to an improved target detection method based on YOLOv5s. Background Art

[0002] Object detection technology is one of the core issues of computer vision and is widely used in security, autonomous driving, manufacturing, road monitoring and other fields. This technology involves detecting instances of specific categories of visual objects (such as people, sofas and cars) in digital images. Its purpose is to locate the position of the target in the image and know what the target is, solving the problems of "where?" and "what?".

[0003] The YOLOv5 algorithm is widely used in academia and industry because it takes into account both real-time and detection accuracy, and has strong generalization and excellent deployment capabilities. However, because the algorithm sacrifices a lot of accuracy while pursuing real-time performance, there are some problems in detection performance, such as inaccurate target frame positioning, low detection accuracy for small targets in pictures or video sequences (the accuracy is about half of that for large targets), etc. Therefore, how to improve the detection accuracy of the YOLOv5 algorithm while maintaining real-time performance is a problem that needs to be studied at present. Summary of the invention

[0004] In view of the above problems, the present invention proposes an improved target detection method based on YOLOv5s, comprising the following steps:

[0005] An improved backbone network model based on the YOLOv5s algorithm is constructed. The improved backbone network model replaces the C3 layer in the original YOLOv5s algorithm with the DGLayer layer, and the DGLayer layer adopts the CSP structure and introduces the ESE attention mechanism layer.

[0006] Input the image to be detected into the trained improved backbone network model to obtain three feature maps with different numbers of channels and different widths and heights;

[0007] A feature fusion network model based on YOLOv5s is constructed. The feature fusion network model replaces the C3 layer in the original YOLOv5s algorithm with the DGLayer layer and introduces a channel cleaning mechanism.

[0008] Input three feature maps with different numbers of channels and different widths and heights into the trained feature fusion network model to obtain three feature maps with different widths and heights but the same number of channels;

[0009] Based on the calculation and prediction of three feature maps with different width and height but the same number of channels, the target prediction probability and target positioning box are obtained to determine the corresponding category prediction results.

[0010] Furthermore, the improved target detection method based on YOLOv5s provided by the present invention also includes training the improved backbone network model and the feature fusion network model, specifically including the following steps:

[0011] Obtain the COCO 2017 dataset, perform data enhancement on the dataset, and obtain the enhanced dataset;

[0012] Using the enhanced dataset, the improved backbone network model and feature fusion network model based on the YOLOv5s algorithm are trained, and the computational complexity and accuracy indicators are trained and tested on the COCO 2017 dataset.

[0013] Furthermore, the data enhancement of the data set to obtain the enhanced data set specifically includes:

[0014] The COCO 2017 dataset is subjected to left-right flipping, image translation, HSV hue transformation, Mosaic data enhancement, image resizing, and adaptive anchor box calculation to obtain an enhanced dataset. Mosaic data enhancement randomly extracts 4 images from the current batchsize dataset to form one image.

[0015] The dataset labels are used to count the sizes of the positioning boxes of all targets and divide them into three categories: large, medium and small targets.

[0016] The Kmeans algorithm is used to cluster the target box sizes and generate a total of 9 anchor boxes.

[0017] Furthermore, the enhanced data set is used to train the improved backbone network model and feature fusion network model based on the YOLOv5s algorithm, specifically including:

[0018] According to the feature map generated by the feature fusion network model, the category loss and confidence loss are back-propagated using the cross entropy loss function, and the prediction result is combined with the anchor box size to generate the final prediction box size;

[0019] The CIoU loss function is used for back propagation of the target box.

[0020] Furthermore, the construction of an improved backbone network model based on the YOLOv5s algorithm specifically includes:

[0021] Using the YOLOv5s algorithm as the original model, the C3 module of the backbone network is replaced with the DGLayer module, the CSP structure is used to reduce the amount of calculation, and the ESE attention mechanism layer is introduced;

[0022] Among them, the DGBlock module in the DGLayer module adopts a dual-branch structure. The main branch uses a 9×9 large convolution kernel connected in series with a 3×3 convolution kernel to increase the receptive field of the model. At the same time, group convolution is used, and the residual branch uses a small convolution kernel connected in series.

[0023] Furthermore, the construction of a feature fusion network based on YOLOv5s specifically includes:

[0024] Based on the YOLOv5s algorithm, the DGLayer module is used to replace the C3 module of the original algorithm, and the PANet structure is adopted. The three prediction feature layers output by the backbone network are used to fuse features from top to bottom and then from bottom to top, and three feature maps rich in semantic information are output;

[0025] According to the three output feature maps, three 1×1 convolutional layers are used to output the final predicted feature map, whose number of channels is k+5, k is the number of detection categories, 5 is the center point coordinates and height and width of the target box, plus a confidence probability of whether it contains an object;

[0026] Wherein, the CIoU function is used as the loss function during the feature fusion network training.

[0027] Furthermore, the image to be detected is input into the trained improved backbone network model to obtain three feature maps with different numbers of channels and widths and heights, specifically including:

[0028] The data-enhanced image is input into the CBS layer, which consists of a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 32, the size is 6×6, the step size is 2, and the input image size is 640×640×3. After passing through the CBS layer, a feature map A of 320×320×32 is output.

[0029] Input feature map A into the CBS layer, which consists of a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 64, the convolution kernel size is 3×3, and the step size is 2. After passing through the CBS layer, a feature map B of size 160×160×64 is output.

[0030] Input feature map B into DGLayer and output feature map C of size 160×160×64, where DGLayer includes a main branch and a residual branch;

[0031] Input the feature map C into the CBS downsampling layer, which includes a convolution layer, a BN layer and a SiLU activation function layer, where the number of convolution kernels in the convolution layer is 128, the convolution kernel size is 3×3, and the step size is 2. This layer outputs a feature map D with a size of 80×80×128;

[0032] Input feature map D into the DGLayer layer, which has 6 DGBlocks and outputs feature map E of size 80×80×128;

[0033] The feature map E is input into the CBS downsampling layer, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 3×3, and the step size is 2. The layer outputs a feature map F of size 40×40×256;

[0034] Input the feature map F into the DGLayer layer, the number of DGBlocks in this layer is 9, and output the feature map G of size 40×40×256;

[0035] The feature map G is input into the CBS downsampling layer, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 512, the convolution kernel size is 3×3, and the step size is 2. The layer outputs a feature map H of size 20×20×512;

[0036] Input the feature map H into the DGLayer layer, the number of DGBlocks in this layer is 3, and output the feature map I of size 20×20×512;

[0037] The feature map I is input into the SPPF layer, which includes two CBS layers, three maximum pooling layers and one splicing layer, and outputs a feature map J with a size of 20×20×512.

[0038] Furthermore, the three feature maps with different numbers of channels and different widths and heights are input into the trained feature fusion network model to obtain three feature maps with different widths and heights but the same number of channels, specifically including:

[0039] The feature map J is input into the first CBS layer of FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 512, the convolution kernel size is 1×1, and the step size is 1, and the output size of the feature map K is 20×20×512.

[0040] The feature map K is input into the first upsampling layer of the FPN, and the height and width of the feature map are doubled by linear interpolation, and the feature map L with a size of 40×40×512 is output;

[0041] Concatenate the feature map L and the feature map G along the channel direction, and output a feature map M with a size of 40×40×1024;

[0042] The feature map L is input into the first DGLayer layer of the FPN. The difference between this layer and the above DGLayer layer is that the number of DGBlocks is 3 and the output size is a feature map N of 40×40×512;

[0043] Input the feature map N into the second CBS layer of the FPN, the CBS layer includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 1×1, and the step size is 1, and the feature map O with an output size of 40×40×256 is obtained;

[0044] The feature map O is input into the second upsampling layer of the FPN, and the height and width of the feature map are doubled by linear interpolation, and the feature map P with a size of 80×80×256 is output;

[0045] Concatenate the feature map P and the feature map E along the channel direction, and output a feature map Q of size 80×80×512;

[0046] The feature map Q is input into the second DGLayer layer of the FPN, the number of DGBlocks of this layer is 3, and the feature map R with an output size of 80×80×256 is output;

[0047] The feature map R is input into the third CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 1×1, and the step size is 1, and the feature map S with an output size of 40×40×256 is obtained;

[0048] Concatenate the feature map S and the feature map O along the channel direction, and output a feature map T of size 40×40×512;

[0049] The feature map T is input into the third DGLayer layer of the FPN. The number of DGBlocks in this layer is 3, and the feature map U with a size of 40×40×512 is output;

[0050] Input the feature map U into the fourth CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 512, the convolution kernel size is 1×1, and the step size is 1, and the feature map V with an output size of 20×20×512 is obtained;

[0051] Concatenate the feature map V and the feature map K along the channel direction, and output a feature map W of size 20×20×1024;

[0052] The feature map W is input into the fourth DGLayer layer of the FPN. The number of DGBlocks in this layer is 3, and the output feature map X has a size of 20×20×1024.

[0053] Furthermore, the calculation and prediction based on the three feature maps with different widths and heights but the same number of channels to obtain the target prediction probability and the target positioning frame and determine the corresponding category prediction results specifically include:

[0054] The feature maps R, U and X output by the feature fusion layer are used for final prediction. The sizes of the three feature maps are 80×80×256, 40×40×512 and 20×20×1024 respectively. The predicted feature maps are output by three convolution layers with three convolution kernels of k+5, size of 1×1 and stride of 1, and three predicted feature maps of sizes of 80×80×(k+5), 40×40×(k+5) and 20×20×(k+5) are obtained respectively; where k is the number of predicted categories;

[0055] According to the predicted feature map, the target prediction probability and target positioning box are obtained to determine the corresponding category prediction result.

[0056] Compared with the prior art, the improved target detection method based on YOLOv5s provided by the present invention has the following beneficial effects:

[0057] The improved target detection method based on YOLOv5s proposed in this invention achieves a significant improvement in accuracy while ensuring that the complexity of the network algorithm does not change much. The improved method improves the computational load index by 7% compared with the original method. After training the two methods for 300 rounds on the COCO2017 dataset, the improved method improves mAP0.5 and mAP0.5-0.95 by 1.1% and 1.3% respectively, which provides a new idea for realizing high-precision YOLO algorithm. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 A flowchart of an improved target detection method based on YOLOv5s provided by the present invention;

[0059] Figure 2 An overall diagram of the improved YOLOv5s provided in an embodiment of the present invention;

[0060] Figure 3 A diagram of the backbone network structure provided by an embodiment of the present invention;

[0061] Figure 4A DGLayer structure diagram provided for an embodiment of the present invention;

[0062] Figure 5 A structural diagram of DGBlock provided in an embodiment of the present invention;

[0063] Figure 6 A feature fusion network diagram provided for an embodiment of the present invention. DETAILED DESCRIPTION

[0064] The following is combined with Figures 1 to 6 The following examples are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the protection scope of the present invention.

[0065] Example 1: Figure 1-6 As shown, the present invention provides an improved target detection method based on YOLOv5s, including an improved target detection algorithm based on YOLOv5s;

[0066] Among them, the improved target detection algorithm based on YOLOv5s includes a data preprocessing module, a backbone network, a feature fusion network and a prediction result post-processing module;

[0067] The data preprocessing module includes data enhancement and anchor frame calculation. The data enhancement divides the data set into several batch sizes, performs left-right flipping, image translation, HSV hue conversion, Mosaic data enhancement and image size scaling before inputting into the backbone network, which can enhance the accuracy and robustness of the algorithm; the anchor frame calculation uses the Kmeans algorithm to cluster the sizes of all target frames in the data set, and finally generates 9 anchor frames of different sizes, so that the target frame positioning is more accurate;

[0068] Among them, backbone networks, such as Figure 3 As shown in the figure, based on the YOLOv5s network, the DGLayer layer is used to replace the C3 layer of the original algorithm. The DGLayer layer adopts the CSP structure to reduce the amount of calculation, and the ESE attention mechanism layer is introduced to enhance the feature extraction ability of the network model. The DGBlock module adopts the double-branch large convolution kernel group convolution form, which greatly improves the receptive field of the network model and significantly reduces the amount of calculation. Under the condition that the amount of calculation of the network model is slightly increased, the accuracy of the improved YOLOv5s algorithm is greatly improved.

[0069] Among them, the feature fusion network is as follows Figure 6 As shown in the figure, based on the three feature maps output by the backbone network, the feature map information is fully utilized through top-down and bottom-up feature fusion methods. At the same time, the DGLayer layer is used to replace the C3 layer of the original module, and the channel cleaning mechanism is introduced to further fuse the features.

[0070] Among them, during training, the prediction result post-processing module uses the cross entropy loss function for category loss and confidence loss, and uses the CIoU loss function regression for the target box positioning loss; during prediction, the predicted category probability = predicted category probability × confidence probability, and then the predicted category probability is predicted through NMS screening, and the predicted target box size is obtained by the predicted target box result and the anchor box size.

[0071] Example 2: Figure 1-6 As shown, the improved target detection method based on YOLOv5s provided by the present invention comprises the following steps:

[0072] Step 1: Data preprocessing module processing, including data enhancement and anchor box calculation.

[0073] Step 2: Input the data-enhanced dataset into the backbone network to obtain three feature maps of different sizes;

[0074] Step 3: Based on the three feature maps obtained in step 2, input FPN to obtain three feature maps with different widths and heights. Finally, through the 1×1 convolution layer, output three feature maps with different widths and heights but the same number of channels.

[0075] Step 4: The three predicted feature maps generated by FPN are further processed, where the category loss and confidence loss use the cross entropy loss function, and the anchor box and predicted feature map generated in step 1 are combined to generate the final target prediction box, and the CIoU loss function is used for regression.

[0076] In this embodiment, step one includes the following steps:

[0077] (1) Data enhancement: The input image is flipped left and right, image translation, HSV hue conversion, mosaic data enhancement, and image size scaling, with probabilities of 0.5, 0.1, (H: 0.015, S: 0.7, V: 0.4), and 1, respectively, in the form of online data enhancement. Mosaic enhancement randomly selects 4 images of the current batch size to form 1 image, which can expand the batch size to 4 times the original; with the input image size of 640×640×3, the image scaling size range is [320, 992].

[0078] (2) Anchor box calculation: For each predicted feature layer, the Kmeans algorithm is used to cluster the width and height dimensions of the target boxes of all images in the dataset. A total of 9 anchor boxes are generated, 3 of which are assigned to each predicted feature layer. Together with the prediction results of step 4, the final predicted target box is generated.

[0079] In this embodiment, step 2 includes the following steps:

[0080] The data-enhanced image is input into the backbone network, which includes 10 layers in total, such as Figure 3 As shown, it consists of CBS layer, DGLayer layer and SPPF layer;

[0081] First, the data-enhanced image is input into the CBS layer, which consists of a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 32, the size is 6×6, the step size is 2, and the input image size is 640×640×3. After passing through the CBS layer, the feature map A of size 320×320×32 is output;

[0082] Next, feature map A is input into the CBS layer, which consists of a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 64, the convolution kernel size is 3×3, and the step size is 2. After passing through the CBS layer, a feature map B of size 160×160×64 is output;

[0083] Next, the feature map B is input into DGLayer, and the feature map C of size 160×160×64 is output, as shown in Figure 4 As shown, the DGLayer includes a main branch and a residual branch;

[0084] (1) In this embodiment, the DGLayer adopts the CSP structure to reduce the amount of calculation, and the number of input channels of the main branch and the residual branch is 32. The main branch includes a CBS layer, three repeated DGBlock layers, a Concat layer, an ESE attention mechanism layer and a CBS layer; the residual branch includes a CBS layer. The feature map B is input into the DGLayer layer to obtain a feature map C of size 160×160×64.

[0085] (2) In this embodiment, the first CBS layer of the main branch of the DGLayer layer includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 32, the size is 1×1, and the step size is 1. After the feature map B is input to the CBS layer, a feature map B1 with a size of 160×160×32 is output;

[0086] (3) In this embodiment, the second, third, and fourth layers of the main branch of the DGLayer layer are all DGBlock layers. Figure 5As shown, the DGBlock layer includes two branches. Branch 1 includes a GConvBN layer, a residual connection layer, two Add layers, a CBS layer, and a channel cleaning layer; Branch 2 includes a GConvBN layer and a CBS layer. After the feature map B1 is input into the DGBlock layer, a feature map B2 of size 160×160×32 is output;

[0087] (3.1) In this embodiment, the GConvBN layer of the DGBlock layer branch 1 includes a group convolution layer and a BN layer, wherein the number of convolution kernels of the group convolution layer is 32, the convolution kernel size is 9×9, the step size is 1, and the number of groups is the number of input channels. After the feature map B1 is input into the DGBlock layer, a feature map B11 of size 160×160×32 is output;

[0088] (3.2) In this embodiment, the residual connection layer of the DGBlock layer branch 1 adds the feature map B1 and the output feature map B11 of the GConvBN layer through the Add layer, and outputs a feature map B12 of size 160×160×32;

[0089] (3.3) In this embodiment, the CBS layer of the DGBlock layer branch 1 includes a convolution layer, a BN layer and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 32, the convolution kernel size is 3×3, the step size is 1, and the feature map B12 is input into the CBS layer to obtain a feature map B13 of size 160×160×32;

[0090] (3.4) In this embodiment, the GConvBN layer of the second branch of the DGBlock layer includes a group convolution layer and a BN layer, wherein the number of convolution kernels of the group convolution layer is 32, the convolution kernel size is 3×3, the step size is 1, and the number of groups is the number of input channels. After the feature map B1 is input into the DGBlock layer, a feature map B14 of size 160×160×32 is output;

[0091] (3.5) In this embodiment, the CBS layer of the DGBlock layer branch 2 includes a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 32, the convolution kernel size is 1×1, the step size is 1, and the feature map B14 is input into the CBS layer to obtain a feature map B15 of size 160×160×32;

[0092] (3.6) In this embodiment, the Add layer of the DGBlock layer branch 1 adds the feature map B13 and the feature map B15 to obtain a feature map B16 with a size of 160×160×32;

[0093] (3.7) In this embodiment, since the group convolution groups the different channel feature maps of the input feature map, and then convolves each group separately, this will reduce the feature extraction ability of the network. In order to allow information to flow between different groups, a channel cleaning layer is introduced. The channel cleaning layer of the DGBlock layer branch 1 shuffles and reorders the channels of the feature map B16, realizes information exchange between different groups, enhances the feature extraction ability of the backbone network, and finally outputs a feature map B2 with a size of 160×160×32;

[0094] (3.8) In this embodiment, the residual branch of the DGLayer consists of a convolution layer, a BN layer, and an activation function layer. The number of convolution kernels in the convolution layer is 32, the convolution kernel size is 1×1, and the step size is 1. The feature map B is input into the branch to obtain a feature map B3 with a size of 160×160×32;

[0095] (4) In this embodiment, the Concat layer of the DGLayer concatenates the feature map B2 and the feature map B3 along the channel direction, and outputs a feature map B4 with a size of 160×160×64;

[0096] (5) In this embodiment, the ESE attention mechanism layer of the DGLayer consists of a global average pooling layer, a convolution layer, a h_sigmoid activation function layer and a weight mapping layer. The feature map B4 is input into this layer, and the feature map B5 with a size of 160×160×64 is output. The global average pooling layer calculates the average value along the width and height of the feature map; the number of convolution kernels in the convolution layer is 64, the number of input channels, the convolution kernel size is 1, and the step size is 1; the definition of the h_sigmoid activation function is as follows:

[0097] Where x is the output feature vector of the convolutional layer, and the definition of ReLU6 is as follows:

[0098] Where x is the output feature vector of the convolutional layer;

[0099] The output of the weight mapping layer is obtained by multiplying the feature vector output by the h_sigmoid activation function layer and the input feature map of the ESE attention mechanism layer. The difference from the SE attention mechanism is that the SE attention mechanism will squeeze the number of channels, and the number of channels will become 1 / r of the original, causing some channel information to be lost, while the ESE attention mechanism avoids this problem;

[0100] (6) In this embodiment, the CBS layer of the DGLayer consists of a convolution layer, a BN layer, and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 64, the convolution kernel size is 1×1, and the step size is 1. The feature map B5 is input into this layer, and the output feature map C of size 160×160×64 is output;

[0101] Next, the feature map C is input into the CBS downsampling layer, which includes a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 128, the convolution kernel size is 3×3, and the step size is 2. This layer outputs a feature map D of size 80×80×128.

[0102] Next, the feature map D is input into the DGLayer layer. Unlike the above DGLayer layer, this layer has 6 DGBlocks and outputs a feature map E of size 80×80×128.

[0103] Next, the feature map E is input into the CBS downsampling layer, which includes a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 256, the convolution kernel size is 3×3, and the step size is 2. This layer outputs a feature map F of size 40×40×256.

[0104] Next, the feature map F is input into the DGLayer layer. Unlike the above DGLayer layer, this layer has 9 DGBlocks and outputs a feature map G of size 40×40×256.

[0105] Next, the feature map G is input into the CBS downsampling layer, which includes a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 512, the convolution kernel size is 3×3, and the step size is 2. This layer outputs a feature map H of size 20×20×512.

[0106] Next, the feature map H is input into the DGLayer layer. Unlike the above DGLayer layer, this layer has 3 DGBlocks and outputs a feature map I of size 20×20×512.

[0107] Next, the feature map I is input into the SPPF layer, which includes two CBS layers, three maximum pooling layers and a concatenation layer. The output feature map J is 20×20×512 in size.

[0108] (1) In this embodiment, the first CBS layer of the SPPF layer consists of a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 1×1, and the step size is 1. The feature map I is input into this layer, and the feature map I1 with a size of 20×20×256 is output;

[0109] (2) In this embodiment, the three maximum pooling layers of the SPPF layer are composed of a maximum pooling layer with 256 convolution kernels, a size of 5×5, and a step size of 1. The feature map I1 is input into the three maximum pooling layers at one time to obtain feature maps I2, I3, and I4 with a size of 20×20×256 respectively;

[0110] (3) In this embodiment, the splicing layer of the SPPF layer splices the feature maps I1, I2, I3, and I4 along the channel direction, and outputs a feature map I5 with a size of 20×20×1024;

[0111] (4) In this embodiment, the second CBS layer of the SPPF layer consists of a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 512, the convolution kernel size is 1×1, and the step size is 1. The feature map I5 is input into this layer, and the feature map J with a size of 20×20×512 is output;

[0112] In this embodiment, step three includes the following steps:

[0113] Input the three feature maps obtained in step 2 into FPN, such as Figure 6 As shown in the figure, FPN consists of four CBS layers, two upsampling layers, four concatenation layers, and four DGLayer layers. First, top-down fusion is performed, then bottom-up fusion is performed, and finally three predicted feature maps are output through the prediction head. The number of channels of this feature map is k+4+1, where k is the predicted category probability, 4 is the center point coordinate xy and width and height wh of the predicted target box, and 1 is the confidence probability;

[0114] First, the feature map J output by the SPPF layer in step 2 is input into the first CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels in the convolution layer is 512, the convolution kernel size is 1×1, and the step size is 1, and the feature map K with an output size of 20×20×512 is obtained;

[0115] Next, the feature map K is input into the first upsampling layer of the FPN, and the height and width of the feature map are doubled by linear interpolation, and the feature map L with a size of 40×40×512 is output;

[0116] Next, the feature map L and the feature map G are concatenated along the channel direction to output a feature map M with a size of 40×40×1024.

[0117] Next, the feature map L is input into the first DGLayer layer of the FPN. The difference between this layer and the above DGLayer layer is that the number of DGBlocks is 3 and the output size is a feature map N of 40×40×512.

[0118] Next, the feature map N is input into the second CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 1×1, and the step size is 1, and the feature map O with an output size of 40×40×256 is obtained;

[0119] Next, the feature map O is input into the second upsampling layer of the FPN, and the height and width of the feature map are doubled by linear interpolation, and the feature map P with a size of 80×80×256 is output;

[0120] Next, the feature map P and the feature map E are concatenated along the channel direction to output a feature map Q of size 80×80×512;

[0121] Next, the feature map Q is input into the second DGLayer layer of the FPN. The number of DGBlocks in this layer is 3, and the feature map R with a size of 80×80×256 is output.

[0122] Next, the feature map R is input into the third CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 1×1, and the step size is 1, and the feature map S with an output size of 40×40×256 is obtained;

[0123] Next, the feature map S and the feature map O are concatenated along the channel direction to output a feature map T of size 40×40×512;

[0124] Next, the feature map T is input into the third DGLayer layer of the FPN. The number of DGBlocks in this layer is 3, and the feature map U with a size of 40×40×512 is output.

[0125] Next, the feature map U is input into the fourth CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 512, the convolution kernel size is 1×1, and the step size is 1, and the feature map V with an output size of 20×20×512 is obtained;

[0126] Next, the feature map V and the feature map K are concatenated along the channel direction to output a feature map W of size 20×20×1024;

[0127] Next, the feature map W is input into the fourth DGLayer layer of the FPN, the number of DGBlocks of this layer is 3, and the output feature map X of size 20×20×1024 is obtained;

[0128] Finally, the feature maps R, U and X output by the above feature fusion layer are used for final prediction, and the sizes of the three feature maps are 80×80×256, 40×40×512 and 20×20×1024 respectively. The predicted feature maps are output by three convolution layers with k+5 convolution kernels (k is the number of prediction categories), 1×1 size and stride 1, and three predicted feature maps of sizes 80×80×(k+5), 40×40×(k+5) and 20×20×(k+5) are obtained respectively.

[0129] In this embodiment, step 4 includes the following steps:

[0130] (1) During training, based on the three predicted feature maps output in step 3, the target probability loss is calculated using the cross entropy loss function, where the probability of each category is the conditional probability, calculated as follows:

[0131] Each category probability = predicted category probability × confidence probability

[0132] The specific calculation formula of the cross entropy loss function is as follows:

[0133]

[0134] Where H(p, q) is the probability loss of all categories; p(xi) is the label value when category is i, which is a one-hot vector; q(xi) is the predicted value when category is i, and n is the total number of categories;

[0135] In this embodiment, the target positioning box loss is a CIoU function, which takes into account the center point distance, overlapping area and aspect ratio between the target box and the anchor box, and the positioning is more accurate. The calculation formula is as follows:

[0136]

[0137] Where IoU is the intersection over union ratio of the real box and the predicted box, ρ2(b, bgt) is the Euclidean distance between the center points of the real box and the predicted box, and c is the diagonal distance of the minimum closure area that can contain both the real box and the predicted box.

[0138]

[0139]

[0140] Among them, wgt, hgt, w and h represent the width and height of the real box and the predicted box respectively;

[0141] The final LOSSCIoU function formula is as follows:

[0142]

[0143] (2) During prediction, the target prediction probability and target positioning box are directly calculated through the three feature maps output by FPN. The improved YOLOv5s algorithm is tested on the COCO 2017 dataset. The test conditions are: training for 100 epochs without loading pre-trained weights, and the learning rate strategy uses cosine annealing.

[0144] The embodiments described above are only preferred specific implementation modes of the present invention, and the protection scope of the present invention is not limited thereto. Any simple changes or equivalent replacements of the technical solutions that can be obviously obtained by any technician familiar with the field within the technical scope disclosed in the present invention belong to the protection scope of the present invention.

Claims

1. An improved target detection method based on YOLOv5s, characterized in that: The following steps are involved: An improved backbone network model based on the YOLOv5s algorithm is constructed. The improved backbone network model replaces the C3 layer in the original YOLOv5s algorithm with the DGLayer layer, and the DGLayer layer adopts the CSP structure and introduces the ESE attention mechanism layer. Input the image to be detected into the trained improved backbone network model to obtain three feature maps with different numbers of channels and different widths and heights; A feature fusion network model based on YOLOv5s is constructed. The feature fusion network model replaces the C3 layer in the original YOLOv5s algorithm with the DGLayer layer and introduces a channel cleaning mechanism. Input the three feature maps with different numbers of channels and different widths and heights into the trained feature fusion network model to obtain three feature maps with different widths and heights but the same number of channels; Based on the calculation and prediction of three feature maps with different width and height but the same number of channels, the target prediction probability and target positioning box are obtained to determine the corresponding category prediction results.

2. An improved target detection method based on YOLOv5s as claimed in claim 1, characterized in that: It also includes training the improved backbone network model and the feature fusion network model, which specifically includes the following steps: Get the COCO2017 dataset, perform data enhancement on the dataset, and obtain the enhanced dataset; Using the enhanced dataset, the improved backbone network model and feature fusion network model based on the YOLOv5s algorithm are trained, and the computational complexity and accuracy indicators are trained and tested on the COCO2017 dataset.

3. An improved target detection method based on YOLOv5s as claimed in claim 2, characterized in that: The data enhancement of the data set to obtain the enhanced data set specifically includes: The COCO2017 dataset is subjected to left-right flipping, image translation, HSV hue transformation, Mosaic data enhancement, image resizing, and adaptive anchor box calculation to obtain an enhanced dataset. Mosaic data enhancement randomly extracts 4 images from the current batch size dataset to form one image. The dataset labels are used to count the sizes of the positioning boxes of all targets and divide them into three categories: large, medium and small targets. The Kmeans algorithm is used to cluster the target box sizes and generate a total of 9 anchor boxes.

4. An improved target detection method based on YOLOv5s as claimed in claim 2, characterized in that: The enhanced data set is used to train the improved backbone network model and feature fusion network model based on the YOLOv5s algorithm, specifically including: According to the feature map generated by the feature fusion network model, the category loss and confidence loss are back-propagated using the cross entropy loss function, and the prediction result is combined with the anchor box size to generate the final prediction box size; The CIoU loss function is used for back propagation of the target box.

5. An improved target detection method based on YOLOv5s as claimed in claim 1, characterized in that: The improved backbone network model based on the YOLOv5s algorithm is constructed, specifically including: Using the YOLOv5s algorithm as the original model, the C3 module of the backbone network is replaced with the DGLayer module, the CSP structure is used to reduce the amount of calculation, and the ESE attention mechanism layer is introduced; Among them, the DGBlock module in the DGLayer module adopts a dual-branch structure. The main branch uses a 9×9 large convolution kernel connected in series with a 3×3 convolution kernel to increase the receptive field of the model. At the same time, group convolution is used, and the residual branch uses a small convolution kernel connected in series.

6. An improved target detection method based on YOLOv5s as claimed in claim 1, characterized in that: The construction of the feature fusion network based on YOLOv5s specifically includes: Based on the YOLOv5s algorithm, the DGLayer module is used to replace the C3 module of the original algorithm, and the PANet structure is adopted. The three prediction feature layers output by the backbone network are used to fuse features from top to bottom and then from bottom to top, and three feature maps rich in semantic information are output; According to the three output feature maps, three 1×1 convolutional layers are used to output the final predicted feature map, whose number of channels is k+5, k is the number of detection categories, 5 is the center point coordinates and height and width of the target box, plus a confidence probability of whether it contains an object; Wherein, the CIoU function is used as the loss function during the feature fusion network training.

7. An improved target detection method based on YOLOv5s as claimed in claim 2, characterized in that: The image to be detected is input into the trained improved backbone network model to obtain three feature maps with different numbers of channels and widths and heights, specifically including: The data-enhanced image is input into the CBS layer, which consists of a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 32, the size is 6×6, the step size is 2, and the input image size is 640×640×3. After passing through the CBS layer, a feature map A of 320×320×32 is output. Input feature map A into the CBS layer, which consists of a convolution layer, a BN layer, and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 64, the convolution kernel size is 3×3, and the step size is 2. After passing through the CBS layer, a feature map B of size 160×160×64 is output. Input feature map B into DGLayer and output feature map C of size 160×160×64, where DGLayer includes a main branch and a residual branch; Input the feature map C into the CBS downsampling layer, which includes a convolution layer, a BN layer and a SiLU activation function layer, where the number of convolution kernels in the convolution layer is 128, the convolution kernel size is 3×3, and the step size is 2. This layer outputs a feature map D with a size of 80×80×128; Input feature map D into the DGLayer layer, which has 6 DGBlocks and outputs feature map E of size 80×80×128; The feature map E is input into the CBS downsampling layer, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 3×3, and the step size is 2. The layer outputs a feature map F of size 40×40×256; Input the feature map F into the DGLayer layer, the number of DGBlocks in this layer is 9, and output the feature map G of size 40×40×256; The feature map G is input into the CBS downsampling layer, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 512, the convolution kernel size is 3×3, and the step size is 2. The layer outputs a feature map H of size 20×20×512; Input the feature map H into the DGLayer layer, the number of DGBlocks in this layer is 3, and output the feature map I of size 20×20×512; The feature map I is input into the SPPF layer, which includes two CBS layers, three maximum pooling layers and one splicing layer, and outputs a feature map J with a size of 20×20×512.

8. An improved target detection method based on YOLOv5s as claimed in claim 7, characterized in that: The method of inputting three feature maps with different numbers of channels and different widths and heights into the trained feature fusion network model to obtain three feature maps with different widths and heights but the same number of channels specifically includes: The feature map J is input into the first CBS layer of FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer. The number of convolution kernels in the convolution layer is 512, the convolution kernel size is 1×1, and the step size is 1, and the output size of the feature map K is 20×20×512. The feature map K is input into the first upsampling layer of the FPN, and the height and width of the feature map are doubled by linear interpolation, and the feature map L with a size of 40×40×512 is output; Concatenate the feature map L and the feature map G along the channel direction, and output a feature map M with a size of 40×40×1024; The feature map L is input into the first DGLayer layer of the FPN. The difference between this layer and the above DGLayer layer is that the number of DGBlocks is 3 and the output size is a feature map N of 40×40×512; Input the feature map N into the second CBS layer of the FPN, the CBS layer includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 1×1, and the step size is 1, and the feature map O with an output size of 40×40×256 is obtained; The feature map O is input into the second upsampling layer of the FPN, and the height and width of the feature map are doubled by linear interpolation, and the feature map P with a size of 80×80×256 is output; Concatenate the feature map P and the feature map E along the channel direction, and output a feature map Q of size 80×80×512; The feature map Q is input into the second DGLayer layer of the FPN, the number of DGBlocks of this layer is 3, and the feature map R with an output size of 80×80×256 is output; The feature map R is input into the third CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 256, the convolution kernel size is 1×1, and the step size is 1, and the feature map S with an output size of 40×40×256 is obtained; Concatenate the feature map S and the feature map O along the channel direction, and output a feature map T of size 40×40×512; The feature map T is input into the third DGLayer layer of the FPN. The number of DGBlocks in this layer is 3, and the feature map U with a size of 40×40×512 is output; Input the feature map U into the fourth CBS layer of the FPN, which includes a convolution layer, a BN layer and a SiLU activation function layer, wherein the number of convolution kernels of the convolution layer is 512, the convolution kernel size is 1×1, and the step size is 1, and the feature map V with an output size of 20×20×512 is obtained; Concatenate the feature map V and the feature map K along the channel direction, and output a feature map W of size 20×20×1024; The feature map W is input into the fourth DGLayer layer of the FPN. The number of DGBlocks in this layer is 3, and the output feature map X has a size of 20×20×1024.

9. An improved target detection method based on YOLOv5s as claimed in claim 8, characterized in that: The calculation and prediction based on three feature maps with different width and height but the same number of channels obtains the target prediction probability and target positioning frame, and determines the corresponding category prediction result, specifically including: The feature maps R, U and X output by the feature fusion layer are used for final prediction. The sizes of the three feature maps are 80×80×256, 40×40×512 and 20×20×1024 respectively. The predicted feature maps are output by three convolution layers with three convolution kernels of k+5, size of 1×1 and stride of 1, and three predicted feature maps of sizes of 80×80×(k+5), 40×40×(k+5) and 20×20×(k+5) are obtained respectively; where k is the number of predicted categories; According to the predicted feature map, the target prediction probability and target positioning box are obtained to determine the corresponding category prediction result.

Citation Information

Patent Citations

  • Small target detection method based on improved YOLOv3

    CN112529090A

  • Infrared target detection method based on feature fusion and attention mechanism

    CN114694002A

  • Safety equipment detection method based on improved YOLOv5s

    CN115496951A

  • General target detection method for adaptive attention guidance mechanism

    WO2021139069A1