Detection method for enhancing multi-size target
Through the improved YOLO model and feature fusion technology, the problem of large detection errors of multi-sized targets has been solved, and the detection accuracy and generalization ability have been improved. In particular, the accuracy of small target detection has been significantly improved.
Patent Information
- Application Number
- CN202410898217.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-10-11
AI Technical Summary
The existing technology has large errors and low accuracy when detecting multi-sized target images, especially the detection of small targets, resulting in low detection accuracy and poor generalization ability.
Using the improved YOLO model, the feature map is sampled through the dynamic upsampling method of point sampling, and spliced and fused in a weighted manner. Feature fusion is performed by combining the backbone network and the neck network to obtain feature maps from shallow to deep layers, and in Multiple predictions are performed in the detection head to improve detection accuracy.
It improves the detection ability of multi-sized targets, reduces redundant feature interference, enhances edge detection clarity and bounding box prediction accuracy, and improves the model's ability to recognize targets of different sizes.
Smart Images

Figure CN118762165A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image detection technology, and in particular to a detection method for enhancing multi-size targets. Background Art
[0002] With the rapid growth in the number of travelers and express delivery items, security inspection plays an increasingly important role in ensuring public safety. Security inspections usually rely on X-rays for perspective scanning, and after imaging, security inspectors determine whether there are prohibited items. When working, security inspectors need to stay focused to avoid missing prohibited items, which would cause irreparable harm to public safety. However, this state of concentration cannot be maintained for a long time, and frequent shift changes will also lead to a large consumption of human resources. Therefore, people are in urgent need of accurate, automatic and efficient prohibited item detection technology to improve the work efficiency of security inspectors and ensure public safety.
[0003] The success of machine learning methods in various fields has encouraged researchers to apply them to the task of detecting contraband in security inspection images. Currently, existing technologies mainly focus on the detection of large objects, especially knives and sticks, but ignore the detection of multi-sized objects, especially small objects such as lighters. As a result, existing technologies cannot simultaneously take into account multi-sized objects when detecting image objects, and generally have problems such as low detection accuracy and poor generalization ability.
[0004] Therefore, there is a need for a technical solution that can image detection on multi-size targets. Summary of the invention
[0005] In view of the above analysis, an embodiment of the present invention aims to provide a method for enhancing detection of multi-size targets, so as to solve the problems of large error and low accuracy in detecting multi-size target images in the prior art.
[0006] Embodiments of the present invention provide a detection method for enhancing a multi-size target, the detection method comprising:
[0007] Preprocess the image to be detected to obtain the image to be detected in a predetermined format;
[0008] Input the image to be detected into a pre-trained image detection model to obtain a first prediction result, a second prediction result, a third prediction result and a fourth prediction result output by the image detection model; wherein the image detection model is an improved YOLO model, in which the neck network of the improved YOLO model samples the input feature map by a point sampling dynamic upsampling method, and simultaneously splices and fuses the input feature map by a weighted method;
[0009] The repeated targets in the first prediction result, the second prediction result, the third prediction result and the fourth prediction result are eliminated to obtain the final prediction result corresponding to the image to be detected.
[0010] Based on further improvements to the above-mentioned method, the image detection model includes:
[0011] The backbone network is used to receive the image to be detected, extract and enhance the features of the image to be detected, and continuously reduce the size of the feature map to obtain the first feature map, the second feature map, the third feature map and the fourth feature map from the shallow layer to the deep layer;
[0012] The neck network combines and enhances features based on the input first feature map, second feature map, third feature map and fourth feature map to obtain the first to fourth fusion feature maps;
[0013] The detection head is used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the image to be detected according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map respectively.
[0014] Based on a further improvement of the above-mentioned method, the neck network includes:
[0015] A first sampling and fusion layer is used to perform a point sampling operation on the fourth feature map, concatenate and fuse the sampled feature map with the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first intermediate feature map;
[0016] The second sampling and fusion layer is used to perform a point sampling operation on the first intermediate feature map, concatenate and fuse the sampled feature map with the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second intermediate feature map;
[0017] The third sampling and fusion layer is used to perform a point sampling operation on the second intermediate feature map, concatenate and fuse the sampled feature map with the first feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first fused feature map;
[0018] The first convolution fusion layer is used to perform a convolution operation on the first fused feature map, concatenate and fuse the feature map after the convolution, the second intermediate feature map, and the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second fused feature map;
[0019] The second convolution fusion layer is used to perform a convolution operation on the second fused feature map, concatenate and fuse the feature map after the convolution, the first intermediate feature map, and the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a third fused feature map;
[0020] The third convolution fusion layer is used to perform a convolution operation on the third fused feature map, concatenate and fuse the feature map after the convolution operation with the fourth feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a fourth fused feature map.
[0021] Based on the further improvement of the above method, the first sampling fusion layer, the second sampling fusion layer and the third sampling fusion layer all include a point sampling layer, a first splicing fusion layer and a residual convolution layer connected in sequence;
[0022] The first convolutional fusion layer, the second convolutional fusion layer, and the third convolutional fusion layer all include a convolutional layer, a second splicing fusion layer, and a residual convolutional layer that are successively connected.
[0023] Based on further improvements to the above method, the point sampling layer is used to change the size of the input feature map according to the scaling factor of the feature, including:
[0024] According to the number of channels of the input feature map, the input feature map is divided into g groups. The number of channels included in each group of input feature maps is the same, and the coordinates of each group of input feature maps are normalized;
[0025] Perform convolution operation on the input feature map H*W*C to change the number of channels of the input feature map to obtain the feature map H*W*(2*s*s*g), further deform the feature map H*W*(2*s*s*g) to obtain the feature map sH*sW*2g, and normalize the elements of the feature map sH*sW*2g. The normalized feature map sH*sW*2g is used as the offset coordinate map of the output feature map; where s is the scaling factor of the feature;
[0026] According to the input feature map normalized by each set of coordinates and the corresponding offset coordinate map, the corresponding output feature maps for each set are determined, and the output feature maps corresponding to the g group are combined to obtain the sampled feature map.
[0027] Based on the further improvement of the above method, the corresponding output feature map for each group is determined according to the input feature map normalized by each group of coordinates and the corresponding offset coordinate map, including:
[0028] Determine the first coordinate of each channel feature map in the output feature map, and determine the corresponding second coordinate from the coordinate map after offset from the corresponding channel according to the first coordinate;
[0029] The second coordinate in the input feature map and the eigenvalues of the surrounding eight neighborhoods are determined, and the average value is used as the eigenvalue of the first coordinate in the output feature map.
[0030] Based on further improvements of the above method, the first splicing and fusion layer splices and fuses two feature maps with different numbers and same sizes input through the following formula:
[0031]
[0032] in, Represents the concatenated and fused feature map, They represent the two feature maps input, w1 and w2 represent the weights corresponding to the two feature maps input, ε1 represents the first smoothing parameter, ε1≠0, and Cat represents the splicing operation.
[0033] Based on further improvements of the above method, the second splicing and fusion layer splices and fuses three feature maps with different numbers of channels and the same size through the following formula:
[0034]
[0035] in, Represents the concatenated and fused feature map, and The three feature maps of the input are respectively represented, w1′, w2′ and w3′ represent the weights corresponding to the three feature maps of the input are respectively, ε2 represents the second smoothing parameter, ε2≠0.
[0036] Based on the further improvement of the above method, the detection head includes a first detection head, a second detection head, a third detection head and a fourth detection head, which are respectively used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the image to be detected according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map;
[0037] The first prediction result, the second prediction result, the third prediction result and the fourth prediction result respectively include a plurality of bounding box prediction results and corresponding category prediction results;
[0038] The prediction results of the enclosure box include the center coordinates, length, width of the enclosure box, and confidence in the target.
[0039] Based on further improvements of the above method, the repeated target screening of the first prediction result, the second prediction result, the third prediction result and the fourth prediction result are eliminated, including:
[0040] traverse all the enclosure boxes in the first prediction result, the second prediction result, the third prediction result and the fourth prediction result, and judge the overlap of the enclosure boxes of any two targets;
[0041] If the overlap of the bounding boxes of the two targets meets the overlap threshold, the confidence of the two targets is further determined, and the target bounding box with a smaller confidence of the target is eliminated;
[0042] Otherwise, both targets are retained and the next filter is removed until all target enclosures are traversed.
[0043] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects:
[0044] 1. Image targets are detected based on the improved YOLO model. The input feature map is sampled by the dynamic upsampling method of point sampling in the improved YOLO model. At the same time, the input feature map is spliced and fused in a weighted manner, achieving clearer edges and high-quality upsampling, reducing the interference of redundant features, and improving the detection of the position and bounding box of multi-size targets;
[0045] 2. The improved YOLO model obtains four layers of feature maps from shallow to deep layers in the backbone network, and obtains four prediction results in the detection head, which effectively improves the detection ability of multi-size objects;
[0046] 3. When performing feature fusion in the neck network, the jump connection of the features directly output from the backbone network is added, and the fusion weight is increased, so that the network can perform specific fusion of features of different sizes. The feature map enhanced by the neck network fusion obtains stronger expression ability, and improves the model's ability to recognize targets of different sizes.
[0047] In the present invention, the above-mentioned technical solutions can also be combined with each other to achieve more preferred combination solutions. Other features and advantages of the present invention will be described in the subsequent description, and some advantages can become obvious from the description, or can be understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained through the contents particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings are for the purpose of showing specific embodiments only and are not considered to be limiting to the invention, and throughout the drawings, like reference numerals denote like components.
[0049] Figure 1 A flow diagram of a detection method for enhancing multi-size targets provided for an embodiment of the present invention;
[0050] Figure 2 A structural diagram of the image detection model provided for an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.
[0052] A specific embodiment of the present invention discloses a detection method for enhancing a multi-size target, such as Figure 1 As shown, the detection method comprises:
[0053] Step S1: Preprocess the image to be detected to obtain the image to be detected in a predetermined format;
[0054] Step S2: inputting the image to be detected into a pre-trained image detection model to obtain a first prediction result, a second prediction result, a third prediction result and a fourth prediction result output by the image detection model; wherein the image detection model is an improved YOLO model, in which the neck network of the improved YOLO model samples the input feature map by a point sampling dynamic upsampling method, and simultaneously splices and fuses the input feature map by a weighted method;
[0055] Step S3: The repeated target screening and removal of the first prediction result, the second prediction result, the third prediction result and the fourth prediction result are obtained to obtain the final prediction result corresponding to the image to be detected.
[0056] Specifically, Figure 1 As shown, in step S1, the image to be detected may include large-sized targets or small-sized targets, such as large-sized targets such as steel knives or baseball bats, etc., and small-sized targets such as lighters or keys, etc. Each image to be detected may include one or more targets.
[0057] Specifically, the image to be detected is preprocessed by expanding the edge of the image to be detected or deforming the image so that the format of the image to be detected meets the predetermined format, which is determined according to the image detection model pre-trained in step S2. Figure 2 As shown, in the image detection model, the predetermined format of the required image to be detected is 640*640*3, that is, the required image size is 640*640 and the number of channels is 3.
[0058] Specifically, Figure 1 As shown, in step S2, the image to be detected is input into a pre-trained image detection model to obtain the first prediction result, the second prediction result, the third prediction result and the fourth prediction result output by the image detection model, such as Figure 2 It is shown that the first prediction result is obtained from the SODH layer, and the second prediction result, the third prediction result and the fourth prediction result are obtained from the other three Detect1 layers, Detect2 layers and Detect3 layers, respectively.
[0059] Specifically, the image detection model is an improved YOLO model. In the improved YOLO model, a point sampling dynamic upsampling method is used to sample the input feature map, and a weighted method is used to splice and fuse the input feature map.
[0060] The image detection model is trained in the following way:
[0061] Acquire a data set, acquire historical image data stored in a security inspection machine, pre-process the historical image data to obtain historical image data in a predetermined format, annotate each historical image using an image annotation tool, and the historical image data and annotation information form a data set;
[0062] Constructing an image detection model, wherein the image detection model is an improved YOLO model, in which the neck network uses a point sampling dynamic upsampling method to sample the input feature map, and simultaneously uses a weighted method to splice and fuse the input feature map;
[0063] Model training: divide the data set into training set, validation set and test set, and determine the training rounds; use the training set to train the image detection model in each training round, and use the validation set to verify the training effect to obtain the optimal image detection model; use the test set to test the optimal image detection model to obtain a trained image detection model.
[0064] Specifically, in the step of acquiring the data set, the historical image data saved by the security inspection machine may include large-sized targets or small-sized targets, such as large-sized targets such as steel knives or baseball bats, etc., and small-sized targets such as lighters or keys, etc. Each historical image data may include one or more targets.
[0065] Specifically, the historical image data is preprocessed by expanding the image edge or deforming the image data so that the format of the historical image data meets the predetermined format, and the predetermined format is determined by the image detection model in the step of constructing the image detection model. Figure 2 As shown, exemplarily, in this image detection model, the predetermined format of the required historical image data is 640*640*3, that is, the required image size is 640*640 and the number of channels is 3.
[0066] Preferably, preprocessing includes one or more of the following operations:
[0067] Image enhancement operations;
[0068] Image denoising operation;
[0069] Image augmentation operations.
[0070] Specifically, the image enhancement operation is used to improve the quality of historical image data to make it more suitable for further graphic detection, including contrast enhancement, brightness adjustment, sharpening or filtering; the image denoising operation is used to reduce the noise of historical image data, including mean filtering, median filtering, Gaussian filtering or non-local mean filtering; specifically, the image augmentation operation is used to expand the historical image data, including image rotation, image scaling, image translation, image flipping or image cropping.
[0071] It is worth noting that, by preprocessing the historical image data, the preprocessed historical image data can be more suitable for the training of the image detection model, making the trained image detection model more generalized.
[0072] Specifically, after preprocessing the historical image data, the historical image data is further labeled to label the target category and the corresponding target bounding box included in each historical image.
[0073] Preferably, the step of annotating each historical image by using an image annotation tool includes:
[0074] Use the image annotation tool LabelImg to mark the location of the target in the image using a standard bounding box and mark the target category;
[0075] The annotation information includes the center coordinates, length, width and category of the bounding box.
[0076] Specifically, the target bounding box information includes the center coordinates, length, and width of the bounding box, and the target category information includes the category of the target, which are combined to obtain the annotation information.
[0077] Specifically, in the step of obtaining a data set, the historical image data and the corresponding annotation information are combined to obtain a data set.
[0078] Specifically, in the step of constructing an image detection model, the image detection model adopts an improved YOLO model. In the improved YOLO model, the neck network uses a point sampling dynamic upsampling method to sample the input feature map, and at the same time uses a weighted method to splice and fuse the input feature map.
[0079] Specifically, in the model training step, the labeled data set is divided into a training set, a validation set, and a test set, and training rounds are set. In each training round, each historical training image in the training set is used to train the image detection model. During each training, the corresponding category loss value and regression loss value are solved according to the prediction results output by the image detection model and the annotation information, and then the loss function of the model is obtained, and back propagation is performed based on the loss function to optimize the model parameters.
[0080] Preferably, the loss function of the image detection model includes a category loss function and a regression loss function, and the category loss function adopts a cross entropy loss function;
[0081] The regression loss function is:
[0082] L Shape-IoU =1-IoU+distance shape +0.5×Ω shape ;
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090] Among them, L Shape-IoU represents the bounding box loss, B represents the predicted area of the bounding box, and B gt represents the real area of the bounding box, x c ,y c Represents the predicted center coordinates of the bounding box, represents the true center coordinates of the bounding box, w and h represent the predicted length and width of the bounding box, w gt 、h gt represents the actual length and width of the bounding box, scale represents the scale factor, θ represents the shape factor, and C represents the diagonal length of the minimum bounding box that can simultaneously enclose the predicted area and the real area of the bounding box.
[0091] Specifically, the category cross entropy loss function is used to quickly calculate the category of the target included in each historical image in the historical image data to obtain the category loss value, so that it can converge quickly and improve the training speed of the image detection model. At the same time, the regression loss function is used to calculate the loss of the bounding box of each historical image, so that the model can predict the position of the bounding box more accurately.
[0092] Specifically, at the end of each training round, the image detection model is verified using the historical image data in the validation set, and the category loss value and regression loss value of each historical image data in the validation set are calculated to determine the training effect of the image detection model at the end of the training round. The training effect of the image detection model at the end of the training round is compared with the training effect of the optimal image detection model saved at the end of the previous training round, and the image detection model with the better training effect is saved as the image detection model for the next training round until the set training round is completed and the optimal image detection model is determined.
[0093] Specifically, in the model training step, the optimal image detection model is tested using the test set, and the tested image detection model is used as the trained image detection model.
[0094] Specifically, if the test fails, the model needs to be retrained using the training set until the model test passes, thereby obtaining a trained image detection model.
[0095] Preferably, the image detection model includes:
[0096] The backbone network is used to receive the image to be detected, extract and enhance the features of the image to be detected, and continuously reduce the size of the feature map to obtain the first feature map, the second feature map, the third feature map and the fourth feature map from the shallow layer to the deep layer;
[0097] The neck network fuses and enhances features according to the input first feature map, second feature map, third feature map and fourth feature map to obtain first to fourth fused feature maps;
[0098] The detection head is used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the image to be detected according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map respectively.
[0099] Specifically, Figure 2 As shown, the image detection model includes a backbone network, a neck network and a detection head.
[0100] The backbone network receives the image to be detected, extracts and enhances the features of the image to be detected, and obtains the first feature map, the second feature map, the third feature map, and the fourth feature map from the shallow layer to the deep layer. Figure 2As shown in the figure, after the image to be detected enters the image detection model, it first passes through the first convolution layer Conv0 in the backbone network to change the number of channels of the image to be detected. The feature map after passing through the first convolution layer is 320*320*64, and then passes through the second convolution layer Conv1, the third multi-convolution module with residual C2f_2, the fourth convolution layer Conv3, the fifth multi-convolution module with residual C2f_4, the sixth convolution layer Conv5, the seventh multi-convolution module with residual C2f_6, the eighth convolution layer Conv7, and the ninth convolution layer Conv8. The multi-convolution module C2f_8 with residual and the tenth-layer spatial pyramid fast pooling layer module SPPF; the output feature maps 160*160*128, 80*80*256, 40*40*512, and 20*20*512 of the multi-convolution module C2f_2 with residual on the third layer, the multi-convolution module C2f_4 with residual on the fifth layer, the multi-convolution module C2f_6 with residual on the seventh layer, and the spatial pyramid fast pooling layer module SPPF on the tenth layer are used as the first feature map, the second feature map, the third feature map, and the fourth feature map from the shallow layer to the deep layer, respectively. It is worth noting that in the backbone network, the first convolution layer Conv0, the second convolution layer Conv1, the fourth convolution layer Conv3, the sixth convolution layer Conv5 and the eighth convolution layer Conv7 are used to reduce the size of the feature map, and the third layer of the multi-convolution module C2f_2 with residual, the fifth layer of the multi-convolution module C2f_4 with residual and the seventh layer of the multi-convolution module C2f_6 with residual are used for feature enhancement of the feature map without changing the size and number of channels of the feature map.
[0101] It is worth mentioning that, through the third-layer multi-convolution module C2f_2 with residual, the fifth-layer multi-convolution module C2f_4 with residual, and the seventh-layer multi-convolution module C2f_6 with residual, the image detection model obtains richer gradient flow while being lightweight, generates more representative features, and can improve the performance and representation ability of the image detection model, making the image detection model suitable for more complex data tasks.
[0102] Specifically, Figure 2 As shown, in the neck network, features are fused and enhanced according to the first feature map 160*160*128, the second feature map 80*80*256, the third feature map 40*40*512 and the fourth feature map 20*20*512 input by the backbone network to obtain the first fused feature map 160*160*128, the second fused feature map 80*80*256, the third fused feature map 40*40*512 and the fourth fused feature map 20*20*512, which are respectively input into the detection head for result prediction to obtain the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the image to be detected.
[0103] Preferably, if Figure 2 As shown, the neck network includes:
[0104] A first sampling and fusion layer is used to perform a point sampling operation on the fourth feature map, concatenate and fuse the sampled feature map with the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first intermediate feature map;
[0105] The second sampling and fusion layer is used to perform a point sampling operation on the first intermediate feature map, concatenate and fuse the sampled feature map with the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second intermediate feature map;
[0106] The third sampling and fusion layer is used to perform a point sampling operation on the second intermediate feature map, concatenate and fuse the sampled feature map with the first feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first fused feature map;
[0107] The first convolution fusion layer is used to perform a convolution operation on the first fused feature map, concatenate and fuse the feature map after the convolution, the second intermediate feature map, and the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second fused feature map;
[0108] The second convolution fusion layer is used to perform a convolution operation on the second fused feature map, concatenate and fuse the feature map after the convolution, the first intermediate feature map, and the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a third fused feature map;
[0109] The third convolution fusion layer is used to perform a convolution operation on the third fused feature map, concatenate and fuse the feature map after the convolution operation with the fourth feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a fourth fused feature map.
[0110] Preferably, the first sampling fusion layer, the second sampling fusion layer and the third sampling fusion layer each include a point sampling layer, a first splicing fusion layer and a residual convolution layer connected in sequence;
[0111] The first convolutional fusion layer, the second convolutional fusion layer and the third convolutional fusion layer all include a convolutional layer, a second splicing fusion layer and a residual convolutional layer connected in sequence.
[0112] Specifically, Figure 2As shown, the first sampling fusion layer includes a point sampling layer DySample10, a first splicing fusion layer BiFPN Concat11 and a residual convolution layer C2f_12 connected in sequence, the second sampling fusion layer includes a point sampling layer DySample13, a first splicing fusion layer BiFPN Concat14 and a residual convolution layer C2f_15 connected in sequence, and the third sampling fusion layer includes a point sampling layer DySample16, a first splicing fusion layer BiFPN Concat17 and a residual convolution layer C2f_18 connected in sequence; the first convolution fusion layer includes a convolution layer Conv19, a second splicing fusion layer BiFPN Concat20 and a residual convolution layer C2f_21 connected in sequence, the second convolution fusion layer includes a convolution layer Conv22, a second splicing fusion layer BiFPNConcat23 and a residual convolution layer C2f_24 connected in sequence, and the third convolution fusion layer includes a convolution layer Conv25, a second splicing fusion layer BiFPN Concat26 and a residual convolution layer C2f_27 connected in sequence. Concat26 and residual convolution layer C2f_27. The first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map are obtained through residual convolution layer C2f_18, residual convolution layer C2f_21, residual convolution layer C2f_24 and residual convolution layer C2f_27 respectively; at the same time, the first intermediate feature map 40*40*512 and the second intermediate feature map 80*80*256 are obtained through residual convolution layer C2f_12 and residual convolution layer C2f_15 respectively.
[0113] It is worth noting that through the point sampling layers DySample10, DySample13, and DySample16, the feature map can retain more edge information. Through the first splicing and fusion layer BiFPN Concat11, BiFPN Concat14, and BiFPN Concat17, and the second splicing and fusion layer BiFPN Concat20, BiFPN Concat23, and BiFPN Concat26, the feature fusion adds the jump connection of the direct output features from the backbone network and increases the fusion weight, so that the network can perform specific fusion of features of different sizes, and the feature map enhanced by the neck network fusion obtains stronger expression ability.
[0114] Preferably, the point sampling layer is used to change the size of the input feature map according to the scaling factor of the feature, including:
[0115] The input feature map is divided into g groups according to the number of channels of the input feature map, each group of input feature maps includes the same number of channels, and the coordinates of each group of input feature maps are normalized;
[0116] Perform convolution operation on the input feature map H*W*C to change the number of channels of the input feature map to obtain the feature map H*W*(2*s*s*g), further deform the feature map H*W*(2*s*s*g) to obtain the feature map sH*sW*2g, and normalize the elements of the feature map sH*sW*2g. The normalized feature map sH*sW*2g is used as the offset coordinate map of the output feature map; where s is the scaling factor of the feature;
[0117] According to the normalized input feature map of each set of coordinates and the corresponding offset coordinate map, the output feature map corresponding to each set is determined, and the output feature maps corresponding to g sets are combined to obtain the sampled feature map.
[0118] Specifically, Figure 2 As shown, the point sampling layer includes DySample10, DySample13, and DySample16. In the point sampling layer, the size of the input feature map is adjusted and changed, that is, the size of the fourth feature map 20*20*512, the first intermediate feature map 40*40*512, and the second intermediate feature map 80*80*256 are adjusted and changed respectively, so that the size of the feature map after sampling is consistent with the size of the third feature map 40*40*512, the second feature map 80*80*256, and the first feature map 160*160*128. That is, in DySample10, the feature map of 20*20*512 is adjusted to 40*40*512, in DySample13, the feature map of 40*40*512 is adjusted to 80*80*512, and in DySample16, the feature map of 80*80*256 is adjusted to 160*160*256.
[0119] Specifically, taking the point sampling layer DySample10 as an example, the fourth feature map 20*20*512 is point sampled to obtain 40*40*512, and s is determined according to the feature map size before and after sampling. The ratio of the length after sampling to the length before sampling is s, or the ratio of the width after sampling to the width before sampling is s. At this time, s=2, g is a common divisor of 512, and the number of channels 512 is evenly divided into g groups, and g can be 1, 2, 4, 8, etc. For example, in the point sampling layer DySample13, the first intermediate feature map 40*40*512 is point sampled to obtain 80*80*512, and s=2 at this time.
[0120] First, a convolution operation is performed on the fourth feature map 20*20*512 to change the number of channels so that the feature map becomes 20*20*(2*2*2*g), and the feature map 20*20*(2*2*2*g) is deformed to obtain a feature map 40*40*2g. It is worth noting that the element corresponding to each coordinate in the feature map 40*40*2g includes two values.
[0121] Next, all elements in the feature map 40*40*2g are normalized to obtain the offset coordinate map 40*40*2g. The number of channels of the offset coordinate map 40*40*2g is g, and the input fourth feature map 20*20*512 is also divided into g groups, that is, each group of input feature maps after coordinate normalization corresponds to a offset coordinate map.
[0122] For example, when g=1, there is only one offset coordinate map of the fourth feature map 20*20*512; when g=2, the 512 channels are divided into 2 groups, and the obtained offset coordinate map is 40*40*(2*2), that is, the offset coordinate map of two channels, and each group of input feature maps after coordinate normalization corresponds to one offset coordinate map.
[0123] Finally, according to the normalized input feature map of each set of coordinates and the corresponding offset coordinate map, the corresponding output feature map of each set is determined, and the corresponding output feature maps of g sets are combined to obtain the sampled feature map.
[0124] Preferably, determining each group of corresponding output feature maps according to each group of coordinate normalized input feature maps and the corresponding offset coordinate maps includes:
[0125] Determine a first coordinate of each channel feature map in the output feature map, and determine a corresponding second coordinate from the offset coordinate map of the corresponding channel according to the first coordinate;
[0126] Determine the eigenvalues of the second coordinate in the input feature map and the surrounding eight neighborhoods, and use the average value as the eigenvalue of the first coordinate in the output feature map.
[0127] Specifically, determine the first coordinate of the feature map of each channel of the output feature map 40*40*512, the first coordinate is the coordinate of any channel in the output feature map 40*40*512, and the offset coordinate map corresponding to the channel, select the eigenvalue corresponding to the first coordinate in the offset coordinate map, the eigenvalue is the second coordinate, and take the average of the 9 eigenvalues of the eight neighborhoods around the second coordinate in the input feature map as the eigenvalue corresponding to the first coordinate in the output feature map.
[0128] It is worth noting that the length and width of the offset coordinate map are the same as the length and width of the output feature map, and the coordinates of the two correspond to each other. In the output feature map, each element represents a feature value, and in the offset coordinate map, each element represents a coordinate value, which represents the coordinate of the input feature map.
[0129] The first coordinate is determined from the output feature map. According to the first coordinate, the coordinate value can be taken from the offset coordinate map of the corresponding channel as the second coordinate. According to the second coordinate, a value is taken from the input feature map. Finally, the average value of the 9 eigenvalues of the eight neighborhoods around the second coordinate is calculated as the eigenvalue of the first coordinate in the output feature map.
[0130] Preferably, the first splicing and fusion layer splices and fuses two input feature maps with different numbers of channels and the same size using the following formula:
[0131]
[0132] in, Represents the concatenated and fused feature map, They represent two feature maps of the input respectively, w1 and w2 represent the weights corresponding to the two feature maps of the input respectively, ε1 represents the first smoothing parameter, ε1≠0, and Cat represents the concatenation operation.
[0133] Specifically, Figure 2 As shown, the first splicing and fusion layer includes BiFPN Concat11, BiFPN Concat14, and BiFPN Concat17. In BiFPN Concat11, the third feature map and the fourth feature map are sampled and spliced and fused. In BiFPN Concat14, the second feature map and the first intermediate feature map are sampled and fused. In BiFPN Concat17, the first feature map and the second intermediate feature map are sampled and fused. It can be understood that in different first splicing and fusion layers, the weights corresponding to different input feature maps may be different. As a training parameter of the image detection model, the first smoothing parameter ε1≠0.
[0134] Preferably, the second splicing and fusion layer splices and fuses the three input feature maps with different numbers of channels and the same size using the following formula:
[0135]
[0136] in, Represents the concatenated and fused feature map, and They represent the three feature maps of the input respectively, w1′, w2′ and w3′ represent the weights corresponding to the three feature maps of the input respectively, ε2 represents the second smoothing parameter, ε2≠.
[0137] Specifically, Figure 2As shown, the second splicing and fusion layer includes BiFPN Concat20, BiFPN Concat23, and BiFPN Concat26. In BiFPN Concat20, the second feature map, the feature map after convolution of the first fused feature map, and the second intermediate feature map are spliced and fused. In BiFPN Concat23, the third feature map, the first intermediate feature map, and the second fused feature map are spliced and fused after convolution. In BiFPNConcat26, the fourth feature map and the third fused feature map are spliced and fused after convolution.
[0138] It can be understood that in BiFPN Concat20 and BiFPN Concat23, different weights can be used for the three different input feature maps as training parameters of the image detection model. At the same time, in BiFPN Concat26, different weights can be used for the two input feature maps as training parameters of the image detection model.
[0139] It is worth noting that the first smoothing parameter ε1 and the second smoothing parameter ε2 are used to avoid division by zero errors and can be reasonably set according to actual conditions.
[0140] It is worth noting that the second splicing fusion layer and the first sampling fusion layer in the third convolutional fusion layer, and the second sampling fusion layer and the first splicing fusion layer in the third sampling fusion layer are essentially the same, and both set and train weight parameters for the two input feature maps.
[0141] Preferably, the detection head includes a first detection head, a second detection head, a third detection head and a fourth detection head, which are respectively used to predict a first prediction result, a second prediction result, a third prediction result and a fourth prediction result of the image to be detected according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map;
[0142] The first prediction result, the second prediction result, the third prediction result and the fourth prediction result respectively include a plurality of bounding box prediction results and corresponding category prediction results;
[0143] The bounding box prediction result includes the center coordinates, length, width, and confidence level of the bounding box.
[0144] Specifically, the category prediction result includes the probability that the bounding box belongs to a preset category.
[0145] Specifically, Figure 2As shown, the detection head includes four prediction layers, the first detection head SODH layer, the second detection head Detect1, the third detection head Detect2 and the fourth detection head Detect3, which respectively predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the image to be detected according to the first fused feature map 160*160*128, the second fused feature map 80*80*256, the third fused feature map 40*40*512 and the fourth fused feature map 20*20*512.
[0146] The prediction results in each detection head include bounding box prediction results and category prediction results. It is worth noting that each image to be detected may include multiple targets, that is, the first prediction result, the second prediction result, the third prediction result and the fourth prediction result may include multiple targets.
[0147] The bounding box prediction result includes the center coordinates, length, width, and confidence level of the bounding box. For the same prediction result, each bounding box corresponds to one target.
[0148] Specifically, the center coordinates of the bounding box are the coordinates of the intersection of the diagonal lines of the predicted bounding box, the length and width are the length and width of the predicted bounding box, and the confidence of containing the target refers to the probability that the predicted bounding box contains the target. It is worth noting that the bounding boxes with low confidence of containing the target can be eliminated in the first prediction result, the second prediction result, the third prediction result and the fourth prediction result, and after elimination, it can be ensured that each bounding box includes the target as much as possible.
[0149] Preferably, the step of screening out repeated targets in the first prediction result, the second prediction result, the third prediction result and the fourth prediction result comprises:
[0150] Traversing all bounding boxes in the first prediction result, the second prediction result, the third prediction result, and the fourth prediction result, and determining the degree of overlap of the bounding boxes of any two targets;
[0151] If the overlap of the bounding boxes of the two targets meets the overlap threshold, the confidence of the two targets is further determined, and the target bounding box with a smaller confidence of the target is eliminated;
[0152] Otherwise, both targets are retained and the next screening is performed until all target bounding boxes are traversed.
[0153] Specifically, in step S3, repeated targets are screened out. The first prediction result, the second prediction result, the third prediction result, and the fourth prediction result obtained in step S2 respectively include target predictions of the image to be detected, which is equivalent to predicting the same image to be detected four times, and finally the repeated targets are eliminated in step S3.
[0154] Specifically, the overlap threshold can be set to 0.8-1. When any two predicted bounding boxes meet the overlap threshold, it can be considered that the two predicted bounding boxes are actually two prediction results of the same target. The predicted bounding box with lower confidence in containing the target can be deleted; the remaining bounding boxes represent the detected targets.
[0155] Compared with the prior art, an enhanced multi-size target detection method provided by an embodiment of the present invention detects image targets based on an improved YOLO model, and a point sampling dynamic upsampling method is used in the improved YOLO model to sample the input feature map, and a weighted method is used to splice and fuse the input feature map, thereby achieving clearer edges and high-quality upsampling, reducing the interference of redundant features, and improving the detection of the position and bounding box of multi-size targets; at the same time, four layers of feature maps from shallow to deep layers are obtained in the backbone network through the improved YOLO model, and four prediction results are obtained in the detection head, thereby effectively improving the detection capability of multi-size targets; and, when performing feature fusion in the neck network, the jump connection of the direct output features from the backbone network is increased, and the fusion weight is increased, so that the network performs specific fusion on features of different sizes, and the feature map enhanced by the neck network fusion obtains a stronger expression capability, thereby improving the model's ability to recognize targets of different sizes.
[0156] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0157] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.
Claims
1. A method for enhancing detection of multi-size targets, characterized in that: The detection method comprises: Preprocessing the image to be detected to obtain the image to be detected in a predetermined format; Input the image to be detected into a pre-trained image detection model to obtain a first prediction result, a second prediction result, a third prediction result and a fourth prediction result output by the image detection model; wherein the image detection model is an improved YOLO model, in which the neck network of the improved YOLO model samples the input feature map by a point sampling dynamic upsampling method, and simultaneously splices and fuses the input feature map by a weighted method; The repeated targets in the first prediction result, the second prediction result, the third prediction result and the fourth prediction result are screened out to obtain the final prediction result corresponding to the image to be detected.
2. The detection method according to claim 1, characterized in that The image detection model includes: The backbone network is used to receive the image to be detected, extract and enhance the features of the image to be detected, and continuously reduce the size of the feature map to obtain the first feature map, the second feature map, the third feature map and the fourth feature map from the shallow layer to the deep layer; The neck network fuses and enhances features according to the input first feature map, second feature map, third feature map and fourth feature map to obtain first to fourth fused feature maps; The detection head is used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the image to be detected according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map respectively.
3. The detection method according to claim 2, characterized in that: The neck network includes: A first sampling and fusion layer is used to perform a point sampling operation on the fourth feature map, concatenate and fuse the sampled feature map with the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first intermediate feature map; The second sampling and fusion layer is used to perform a point sampling operation on the first intermediate feature map, concatenate and fuse the sampled feature map with the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second intermediate feature map; The third sampling and fusion layer is used to perform a point sampling operation on the second intermediate feature map, concatenate and fuse the sampled feature map with the first feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first fused feature map; The first convolution fusion layer is used to perform a convolution operation on the first fused feature map, concatenate and fuse the feature map after the convolution, the second intermediate feature map, and the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second fused feature map; The second convolution fusion layer is used to perform a convolution operation on the second fused feature map, concatenate and fuse the feature map after the convolution, the first intermediate feature map, and the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a third fused feature map; The third convolution fusion layer is used to perform a convolution operation on the third fused feature map, concatenate and fuse the feature map after the convolution operation with the fourth feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a fourth fused feature map.
4. The detection method according to claim 3, characterized in that: The first sampling fusion layer, the second sampling fusion layer and the third sampling fusion layer each include a point sampling layer, a first splicing fusion layer and a residual convolution layer connected in sequence; The first convolutional fusion layer, the second convolutional fusion layer and the third convolutional fusion layer all include a convolutional layer, a second splicing fusion layer and a residual convolutional layer connected in sequence.
5. The detection method according to claim 4, characterized in that: The point sampling layer is used to change the size of the input feature map according to the scaling factor of the feature, including: The input feature map is divided into g groups according to the number of channels of the input feature map, each group of input feature maps includes the same number of channels, and the coordinates of each group of input feature maps are normalized; Perform convolution operation on the input feature map H*W*C to change the number of channels of the input feature map to obtain the feature map H*W*(2*s*s*g), further deform the feature map H*W*(2*s*s*g) to obtain the feature map sH*sW*2g, and normalize the elements of the feature map sH*sW*2g. The normalized feature map sH*sW*2g is used as the offset coordinate map of the output feature map; where s is the scaling factor of the feature; According to the normalized input feature map of each set of coordinates and the corresponding offset coordinate map, the output feature map corresponding to each set is determined, and the output feature maps corresponding to g sets are combined to obtain the sampled feature map.
6. The detection method according to claim 5, characterized in that: The step of determining each group of corresponding output feature maps according to each group of normalized input feature maps and the corresponding offset coordinate maps includes: Determine a first coordinate of each channel feature map in the output feature map, and determine a corresponding second coordinate from the offset coordinate map of the corresponding channel according to the first coordinate; Determine the eigenvalues of the second coordinate in the input feature map and the surrounding eight neighborhoods, and use the average value as the eigenvalue of the first coordinate in the output feature map.
7. The detection method according to claim 4, characterized in that: The first splicing and fusion layer splices and fuses two input feature maps with different numbers of channels and the same size using the following formula: in, Represents the concatenated and fused feature map, They represent two feature maps of the input respectively, w1 and w2 represent the weights corresponding to the two feature maps of the input respectively, ε1 represents the first smoothing parameter, ε1≠0, and Cat represents the concatenation operation.
8. The detection method according to claim 4, characterized in that: The second splicing and fusion layer splices and fuses the three input feature maps with different numbers of channels and the same size using the following formula: in, Represents the concatenated and fused feature map, and They represent the three feature maps of the input respectively, w1′, w2′ and w3′ represent the weights corresponding to the three feature maps of the input respectively, ε2 represents the second smoothing parameter, ε2≠0.
9. The detection method according to claim 2, characterized in that: The detection head includes a first detection head, a second detection head, a third detection head and a fourth detection head, which are respectively used to predict a first prediction result, a second prediction result, a third prediction result and a fourth prediction result of the image to be detected according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map; The first prediction result, the second prediction result, the third prediction result and the fourth prediction result respectively include a plurality of bounding box prediction results and corresponding category prediction results; The bounding box prediction result includes the center coordinates, length, width, and confidence level of the bounding box.
10. The detection method according to claim 9, characterized in that: The step of screening out repeated targets in the first prediction result, the second prediction result, the third prediction result, and the fourth prediction result includes: Traversing all bounding boxes in the first prediction result, the second prediction result, the third prediction result, and the fourth prediction result, and determining the degree of overlap of the bounding boxes of any two targets; If the overlap of the bounding boxes of the two targets meets the overlap threshold, the confidence of the two targets is further determined, and the target bounding box with a smaller confidence of the target is eliminated; Otherwise, both targets are retained and the next screening is performed until all target bounding boxes are traversed.
Citation Information
Cited By
Fishbone removing method, fishbone removing device, fishbone removing equipment and fishbone removing control system
CN121904350A
