Security inspection target detection method based on improved YOLOv7
By improving the security inspection target detection method of YOLOv7, using SwinT and FHD structures and DCSP strategies, the problem of low accuracy of YOLOv7 in detecting small target objects has been solved. The detection accuracy on OPIXray and HiXray data sets has been significantly improved, and the model has been enhanced. Robustness and small target recognition capabilities.
Patent Information
- Application Number
- CN202410634867.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing security inspection target detection methods have low accuracy when detecting small target objects, especially in subway security inspections due to dense crowds and occlusion between small target objects, which lead to missed detections. The mAP50 of YOLOv7 on the HiXray data set is only 0.228, which is difficult to meet the security inspection requirements. Real-time and accuracy requirements.
A security inspection target detection method based on improved YOLOv7 is adopted, by introducing the feature extraction backbone network SwinT of self-attention global perception and the four-dimensional detection structure FHD of multi-scale hierarchical feature fusion, adding a fourth detection head to capture small-scale features, and using DCSP, a branch detection strategy that decouples classification and positioning tasks, improves the model's detection capabilities for small target objects.
The mAP50 increased by 4.8% on the OPIXray data set, and the mAP increased by 2.8% on the HiXray data set, which significantly improved the detection accuracy of small target objects and enhanced the model's robustness and recognition ability of small target objects.
Smart Images

Figure CN118609042A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of security inspection target detection, and in particular to a security inspection target detection method based on improved YOLOv7. Background Art
[0002] With the increase in the number of people in the subway, the pressure on subway security inspection is increasing. At present, subway security inspection mainly relies on manual observation to see if there are dangerous items. This method requires a lot of human resources, and people are prone to fatigue during long-term observation, resulting in missed inspections of dangerous items. It is not stable and it is difficult to meet the needs of security inspection sites, which makes subways, a public place with dense crowds, a great safety hazard. Among them, the object detection technology based on deep learning has made great progress. Object detection based on deep learning is divided into two categories: single-stage and two-stage. The advantage of the single-stage object detection model is fast speed, which has a faster detection speed while ensuring a certain accuracy. Compared with the single-stage object detection model, the two-stage object detection model has the advantage of high detection accuracy, but the detection speed is reduced. The single-stage object detection model can be simply understood as end-to-end. After inputting the picture, the box and type can be directly output. It is more suitable for scenarios such as security inspection that have high real-time requirements.
[0003] The YOLO series has become one of the most important models for target detection in the current industry due to its ease of use, ease of modification, stability, and fast detection speed. The YOLOv7 network only uses convolution operations for feature extraction. As a local operation, convolution operations usually only model between pixels in a region and are difficult to capture long-distance dependencies. This makes it easy for YOLOv7 to lose features and cause missed detections when detecting small targets.
[0004] In actual security inspection scenarios, the objects to be detected include a variety of small target objects such as lighters, cosmetics, and utility knives. The mAP50 of YOLOv7 for non-metallic lighters (small targets) in HiXray is only 0.228, and the detection accuracy is low. In addition, due to the particularity of security inspection scenarios, the high degree of occlusion between small target objects is more unfavorable for model detection. Based on the above situation, the existing security inspection target detection methods have the problem of low detection accuracy for small target object detection. Summary of the invention
[0005] This application provides a security inspection target detection method based on improved YOLOv7.
[0006] In the first aspect, the present application provides a security inspection target detection method based on improved YOLOv7, which adopts the following technical solutions:
[0007] The security inspection target detection method based on improved YOLOv7 includes:
[0008] Acquire image data of security inspection targets;
[0009] Perform data enhancement on the image data, and divide the enhanced image data into training set, validation set and test set;
[0010] Perform clustering operations on the labeled samples in the training set;
[0011] Build a security inspection dangerous goods detection model based on improved YOLOv7;
[0012] The training set is input into the security inspection dangerous goods detection model to start training, and the hyperparameters are adjusted according to the validation set;
[0013] Use the security inspection dangerous goods detection model to detect the test set.
[0014] Preferably, the image is input into a convolution kernel of a fixed size to segment the original two-dimensional image data to obtain a plurality of block image data;
[0015] Perform feature extraction on multiple block image data through a fully connected layer to obtain a first scale feature map;
[0016] Inputting the first scale feature map into a first size feature module to obtain a second scale feature map;
[0017] Inputting the second scale feature map into the second size feature module to obtain a third scale feature map;
[0018] Inputting the third scale feature map into the third size feature module to obtain a fourth scale feature map;
[0019] Among them, the scales of the first scale feature map, the second scale feature map, the third scale feature degree map and the fourth scale feature degree map are gradually halved.
[0020] Preferably, the first size feature module, the second size feature module and the third size feature module are collectively referred to as size feature modules, and the size feature module includes a layer normalization unit, a first window self-attention unit, a second window self-attention unit and a multilayer perceptron. The specific formulas of the layer normalization unit, the first window self-attention unit, the second window self-attention unit and the multilayer perceptron are as follows:
[0021]
[0022]
[0023]
[0024]
[0025] In the formula, Z L is the output feature of the multilayer perceptron; It is the output feature of the first window self-attention unit or the second window self-attention unit; W-MSA is the output data obtained by calculating the self-attention of the first window self-attention unit; SW-MSA is the output data of the second window self-attention unit; LN is the output data of the layer normalization unit.
[0026] Preferably, the number of channels of the input feature map is adjusted by a 1×1 convolution layer shared convolution to generate shared features, so that the classification has two branches for the classification task and the positioning task;
[0027] The shared features are processed based on the first 1×1 convolutional layer, and the features of the processed data are extracted through two 3×3 second convolutional layers;
[0028] Fusion processing is performed based on the residual structure and the features of the first 1×1 convolutional layer;
[0029] The 1×1 third convolutional layer is used as the derived structure of the shared convolution, and a concat operation is performed with one of the 3×3 second convolutional layers, followed by a 1×1 convolutional layer to obtain the category output result.
[0030] Preferably, the shared features are input into the fourth 3×3 convolution layer for convolution, and the convolution result is input into the 1×1 convolution layer to obtain the regression data and confidence data of the target prediction box; the regression data is the coordinate value and length and width value of the upper left corner of the prediction box.
[0031] Preferably, an upsampling operation is performed on the input feature map to obtain a feature map processing object;
[0032] Based on the Conv operation and the corresponding number of channels and convolution kernel size, the feature map processing object is processed;
[0033] The feature map processed by each processing branch is fused with the feature maps processed by other processing branches through the Concat operation;
[0034] Perform IDetect operation on the fused feature map to generate the corresponding detection output result.
[0035] Preferably, the enhanced image data is divided into a training set, a validation set and a test set in a ratio of 7:2:1.
[0036] In summary, the present application includes at least one of the following beneficial technical effects: by using a feature extraction backbone network SwinT based on self-attention global perception, it is used to enhance the feature extraction and detection of small target objects; a four-dimensional detection structure FHD (Four Head Detection) based on multi-scale hierarchical feature fusion is proposed, and the model's detection ability for small targets is enhanced by introducing a fourth detection head; a branch detection strategy DCSP (Decoupled Cross Stage Partial) based on the decoupling of classification and positioning tasks is proposed, and different branches are used for classification and regression tasks respectively, so that the improved YOLOv7 can detect small target objects. The mAP50 is improved by 4.8% on the OPIXray dataset and the mAP is improved by 2.8% on the HiXray dataset, thereby improving the detection accuracy of small target objects. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 This is a flowchart of the steps of the security inspection target detection method based on the improved YOLOv7 in this embodiment;
[0038] Figure 2 This is a network structure diagram of a security inspection dangerous goods detection model in a security inspection target detection method based on improved YOLOv7 in this embodiment;
[0039] Figure 3 This is a structural diagram of the feature extraction backbone network SwinT in the security inspection target detection method based on the improved YOLOv7 in this embodiment;
[0040] Figure 4 Schematic diagram of the structure of the four-dimensional detection structure FHD in the security inspection target detection method based on the improved YOLOv7 in this embodiment;
[0041] Figure 5 This is a network structure diagram of the branch detection strategy DCSP in the security target detection method based on the improved YOLOv7 in this embodiment. DETAILED DESCRIPTION
[0042] The following is combined with Figure 1-Figure 5 This application is described in further detail.
[0043] The embodiment of the present application discloses a security inspection target detection method based on improved YOLOv7.
[0044] Example: Figure 1 As shown, the present invention is based on an improved security inspection target detection method of YOLOv7, including:
[0045] S100, acquiring image data of the security inspection target; wherein the detection head includes a first detection head, a second detection head, a third detection head, and a fourth detection head. The first detection head may be a P3 / 8 detection head, the second detection head may be a P4 / 16 detection head, and the third detection head may be a P5 / 32 detection head. The fourth detection head is a detection head specifically for small-scale feature maps added on the basis of the first detection head, the second detection head, and the third detection head. The detection head is designed to capture and identify tiny target features of small-scale feature maps. The detection head operates directly on the P2 / 4 layer feature map, and the P2 layer feature map provides a denser pixel representation than other layers, which is suitable for identifying small-sized targets.
[0046] S200, performing data enhancement on the image data, and dividing the enhanced image data into a training set, a validation set, and a test set; wherein, the Mosaic+Mixup method can be used to perform data enhancement on the image data, and the enhanced data set is divided into a training set, a validation set, and a test set in a ratio of 7:2:1.
[0047] S300, clustering the labeled samples in the training set; performing K-means clustering operation by using the autoachor method.
[0048] S400, builds a security dangerous goods detection model based on improved YOLOv7; the improvements of the security dangerous goods detection model (XS-YOLO) include: a feature extraction backbone network SwinT based on self-attention global perception, which is used to enhance the feature extraction and detection of small target objects; a four-dimensional detection structure FHD based on multi-scale hierarchical feature fusion, which mainly enhances the model's detection ability for small targets by introducing a fourth detection head; a branch detection strategy DCSP based on the decoupling of classification and positioning tasks, using different branches for classification and regression tasks respectively.
[0049] S500, the training set is input into the security inspection dangerous goods detection model to start training, and the hyperparameters are adjusted according to the validation set;
[0050] S600, use the security inspection dangerous goods detection model to detect the test set.
[0051] In this embodiment, by adding a detection head specifically for the small-scale feature map to the basic row of the original detection head, the small target features of the small-scale feature map captured and identified are more accurate, which is conducive to the identification of small targets and improves the detection accuracy. By performing data enhancement on the collected image data, the robustness of the training model is enhanced. By improving the YOLOv7 model, the feature extraction and detection of small target objects are enhanced, and the conflict problem between the classification and positioning tasks in YOLOv7 is also solved, further improving the detection accuracy of small target objects.
[0052] In step S400, a security inspection dangerous goods detection model based on improved YOLOv7 is constructed, including the following steps:
[0053] S410, input the image into a convolution kernel of a fixed size to segment the original two-dimensional image data to obtain multiple blocks of image data; this is equivalent to dividing the image into patches. For example, an image with an initial resolution of H×W×3 is subdivided into 4×4 patches through Patch Partition, and the resulting feature map dimension is H / 4×W / 4×48.
[0054] S420, extract features from multiple block image data through a fully connected layer to obtain a first-scale feature map; each segmented patch is mapped to a high-dimensional space through Linear Embedding to generate a richer feature representation.
[0055] S430, inputting the first scale feature map into a first size feature module to obtain a second scale feature map;
[0056] S440, inputting the second scale feature map into a second size feature module to obtain a third scale feature map;
[0057] S450, input the third scale feature map into a third size feature module to obtain a fourth scale feature map, wherein the scales of the first scale feature map, the second scale feature map, the third scale feature map, and the fourth scale feature map are gradually halved.
[0058] The first size feature module, the second size feature module and the third size feature module are collectively referred to as size feature modules. The size feature module includes a Patch Merging and several Swin Transformer Blocks, and the Swin Transformer Block includes a layer normalization unit, a first window self-attention unit, a second window self-attention unit and a multilayer perceptron. The specific formulas of the layer normalization unit, the first window self-attention unit, the second window self-attention unit and the multilayer perceptron are as follows:
[0059]
[0060]
[0061]
[0062]
[0063] In the formula, Z L is the output feature of the multilayer perceptron; It is the output feature of the first window self-attention unit or the second window self-attention unit; W-MSA is the output data obtained by calculating the self-attention of the first window self-attention unit; SW-MSA is the output data of the second window self-attention unit; LN is the output data of the layer normalization unit.
[0064] Among them, the first window self-attention unit maps the input features into queries, keys and values through a linear transformation, and then calculates the similarity between the query and the key to obtain the attention score. This score represents the strength of the association between the feature points. After the score is converted into a probability distribution through the Softmax function, it is used to weight the value vector, thereby aggregating the information of each point in the window. The first window self-attention limits the input feature map to a small window range, and the pixels or feature points in each window only interact with other points in the same window. The second window self-attention unit adds a strategy based on the first window self-attention unit. Between two adjacent Swin Transformer Blocks, the position of the window is changed by moving horizontally or vertically. This displacement allows the feature points originally in one window to appear in the adjacent window in the next layer, so that the originally non-intersecting windows partially overlap in the new layer. Therefore, the second window self-attention unit not only captures the feature association within the window, but also connects the information of adjacent windows, enhancing the integration of global information.
[0065] Patch Merging is used to reduce the spatial size of feature maps and increase channel data by merging adjacent patches to reduce the size of feature maps. At the same time, the features of adjacent patches are fused and the number of channels is increased through linear transformation. In this step, each adjacent patch is merged into a large patch and the dimension is reduced through an unbiased fully connected layer.
[0066] In this embodiment, through the above steps, the model gradually expands the receptive field and learns more and more rich image features while maintaining high efficiency. At the end of the network, the dimension of the feature map obtained will be greatly reduced, the number of channels will be greatly increased, and the feature map obtained can provide rich information for the input of subsequent tasks.
[0067] In step S400, a security inspection dangerous goods detection model based on improved YOLOv7 is constructed, which also includes the following steps:
[0068] S460, through the 1×1 convolution layer shared convolution, the number of channels of the input feature map is adjusted to generate shared features, forming a classification with two branches for classification tasks and positioning tasks; on the classification branch, considering the complexity of fine-grained classification, the following measures are taken to improve the accuracy while ensuring the lightweight of the head.
[0069] S470, processing the shared features based on a 1×1 first convolutional layer, and extracting features from the processed data through two 3×3 second convolutional layers;
[0070] S480, performing fusion processing based on the residual structure and the features of the first 1×1 convolutional layer;
[0071] S490, the 1×1 third convolution layer is used as the derived structure of the shared convolution, and a concat operation is performed with one of the 3×3 second convolution layers, followed by a 1×1 convolution layer to obtain a category output result;
[0072] S4100, input the shared features into the fourth convolutional layer of 3×3 for convolution, and input the convolution result into the 1×1 convolutional layer to obtain the regression data and confidence data of the target prediction box; the regression data is the coordinate value and length and width value of the upper left corner of the prediction box.
[0073] In this embodiment, in the classification branch, compared with directly using a 3×3 convolutional layer for processing, the structure adopted by the present invention introduces a jump connection in the convolutional layer, which not only allows different stages of the network to share features, but also reduces the amount of calculation. At the same time, by dividing the input features into two parts, one part is transmitted to the final fusion layer through a jump connection, and the other part is processed through a series of convolutional layers, which effectively reduces redundant information and improves the learning efficiency of the network. At the same time, due to the existence of the jump connection, the propagation of features is strengthened to prevent the gradient disappearance problem.
[0074] In step S400, a security inspection dangerous goods detection model based on improved YOLOv7 is constructed, which also includes the following steps:
[0075] S4110, performing an upsampling operation on the input feature map to obtain a feature map processing object;
[0076] S4120, processing the feature map processing object based on the Conv operation and the corresponding number of channels and convolution kernel size;
[0077] S4130, fusing the feature graph processed by each processing branch with the feature graph processed by other processing branches through a Concat operation;
[0078] S4140, performing an IDetect operation on the fused feature map to generate a corresponding detection output result.
[0079] In this embodiment, a feature map is selected as the object of subsequent processing through an upsampling operation, and then a series of new convolution layers are performed on the selected feature map, including a Conv operation and convolution with the corresponding number of channels and convolution kernel size, and after the convolution, it is fused with the output feature maps of other branches through a Concat operation, so that information from different levels can be comprehensively utilized, and the fused information is used to generate the final detection output through an IDetect operation, thereby achieving target detection using the fused feature map.
[0080] Among them, the comparative experimental data of the cluster analysis security dangerous goods detection model (XS-YOLO) and other mainstream models on the OPIXray dataset are as follows:
[0081]
[0082] The comparative experimental data of the security inspection dangerous goods detection model (XS-YOLO) and other mainstream models on HiXray are as follows:
[0083]
[0084] Compared with the existing security inspection target detection method based on improved YOLOv7 / YOLOv5, the present invention improves the accuracy of detecting small target objects.
[0085] The above are all preferred embodiments of the present application, and the protection scope of the present application is not limited thereto. Therefore, any equivalent changes made according to the structure, shape, and principle of the present application should be included in the protection scope of the present application.
Claims
1. The security inspection target detection method based on improved YOLOv7 is characterized by: include: Acquire image data of security inspection targets; Perform data enhancement on the image data, and divide the enhanced image data into training set, validation set and test set; Perform clustering operations on the labeled samples in the training set; Build a security inspection dangerous goods detection model based on improved YOLOv7; The training set is input into the security inspection dangerous goods detection model to start training, and the hyperparameters are adjusted according to the validation set; Use the security inspection dangerous goods detection model to detect the test set.
2. The security inspection target detection method based on improved YOLOv7 according to claim 1, characterized in that: The construction of the security inspection dangerous goods detection model based on the improved YOLOv7 is specifically as follows: Input the image into a convolution kernel of a fixed size to segment the original two-dimensional image data to obtain multiple block image data; Perform feature extraction on multiple block image data through a fully connected layer to obtain a first scale feature map; Inputting the first scale feature map into a first size feature module to obtain a second scale feature map; Inputting the second scale feature map into the second size feature module to obtain a third scale feature map; Inputting the third scale feature map into the third size feature module to obtain a fourth scale feature map; Among them, the scales of the first scale feature map, the second scale feature map, the third scale feature degree map and the fourth scale feature degree map are gradually halved.
3. The security inspection target detection method based on improved YOLOv7 according to claim 2, characterized in that: The first size feature module, the second size feature module and the third size feature module are collectively referred to as size feature modules, and the size feature module includes a layer normalization unit, a first window self-attention unit, a second window self-attention unit and a multi-layer perceptron. The specific formulas of the layer normalization unit, the first window self-attention unit, the second window self-attention unit and the multi-layer perceptron are as follows: In the formula, Z L is the output feature of the multilayer perceptron; It is the output feature of the first window self-attention unit or the second window self-attention unit; W-MSA is the output data obtained by calculating the self-attention of the first window self-attention unit; SW-MSA is the output data of the second window self-attention unit; LN is the output data of the layer normalization unit.
4. The security inspection target detection method based on improved YOLOv7 according to claim 1, characterized in that: The construction of the security inspection dangerous goods detection model based on the improved YOLOv7 also includes: The input feature map is shared through a 1×1 convolutional layer to adjust the number of channels and generate shared features, forming a classification with two branches for classification and positioning tasks; The shared features are processed based on the first 1×1 convolutional layer, and the features of the processed data are extracted through two 3×3 second convolutional layers; Fusion processing is performed based on the residual structure and the features of the first 1×1 convolutional layer; The 1×1 third convolutional layer is used as the derived structure of the shared convolution, and a concat operation is performed with one of the 3×3 second convolutional layers, followed by a 1×1 convolutional layer to obtain the category output result.
5. The security inspection target detection method based on improved YOLOv7 according to claim 4 is characterized in that: The shared convolution of the 1×1 convolution layer is used to adjust the number of channels of the input feature map to generate shared features, so as to form a classification having two branches for classification tasks and positioning tasks, and further comprising: The shared features are input into the fourth convolutional layer of 3×3 for convolution, and the convolution result is input into the 1×1 convolutional layer to obtain the regression data and confidence data of the target prediction box; the regression data is the coordinate value and length and width value of the upper left corner of the prediction box.
6. The security inspection target detection method based on improved YOLOv7 according to claim 5 is characterized in that: The construction of the security inspection dangerous goods detection model based on the improved YOLOv7 also includes: Perform upsampling operation on the input feature map to obtain a feature map processing object; Based on the Conv operation and the corresponding number of channels and convolution kernel size, the feature map processing object is processed; The feature map processed by each processing branch is fused with the feature maps processed by other processing branches through the Concat operation; Perform IDetect operation on the fused feature map to generate the corresponding detection output result.
7. The security inspection target detection method based on improved YOLOv7 according to claim 1, characterized in that: Also includes: The enhanced image data is divided into training set, validation set and test set in a ratio of 7:2:1.
