X-ray security image dangerous goods detection method based on YOLOv7

By improving the YOLOv7 model, introducing the CA attention module and BiFPN structure, and combining data augmentation and SIoU loss function, the problems of target occlusion and small target recognition in X-ray security inspection images were solved, achieving high-precision and real-time dangerous goods detection.

CN117274774BActive Publication Date: 2026-01-13HARBIN UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311221677.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-20
Publication Date
2026-01-13
Estimated Expiration
2043-09-20

AI Technical Summary

Technical Problem

In X-ray security inspection images, the occlusion caused by target stacking and the insufficient ability to locate and identify small targets in complex backgrounds make it difficult for existing technologies to meet the requirements of real-time performance and accuracy.

Method used

An improved method based on YOLOv7 is adopted, which enhances feature extraction by introducing a CA attention module, adds skip connections to prevent gradient vanishing, uses a BiFPN feature fusion structure to reduce the number of parameters, and improves the loss function to SIoU. The method also combines data augmentation and SoftNMS algorithms to improve detection accuracy.

Benefits of technology

It improves the detection accuracy and real-time performance of dangerous goods in X-ray security inspection images, and can accurately identify small targets and obscured targets in complex backgrounds, meeting the real-time and high-efficiency requirements of security inspection tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117274774B_ABST
    Figure CN117274774B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of target detection, and particularly relates to an X-ray security inspection image dangerous goods detection algorithm based on YOLOv7; the method sequentially performs the following steps: an X-ray security inspection image data set is acquired and is randomly divided in proportion; a K-means++ algorithm is used to set a prior box of the data set; an improved YOLOv7-MPCN network model is built, including: a CA (Coordinate Attention, CA) coordinate attention mechanism is combined in the YOLOv7 network; a skip connection is added in the MPConv by referring to a residual network; a BiFPN (Bidirectional Feature Pyramid Network) is used as a feature fusion structure of a down-sampling module; finally, a SIoU (SCYLIA Intersection over Union) improved loss function is used to accelerate the convergence speed. The improved YOLOv7 model is trained by using a training set to obtain an X-ray security inspection image detection model; the trained model is tested by using a test set to obtain a detection result. The improved YOLOv7 algorithm is used to detect the X-ray security inspection image, dangerous goods can be accurately positioned and identified in the dangerous goods detection process of the security inspection platform of each major transportation hub, and the security inspection efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of X-ray image target detection. Background Technology

[0002] X-ray imagery is the image acquired by X-ray security inspection equipment. X-ray images capture a wide variety of dangerous items, varying in shape and size, and even items of the same type can have significant differences in appearance. Acquiring X-ray images through security equipment allows for the detection of dangerous items without opening the baggage of the person being inspected, offering convenience and efficiency, and is widely used at entrances to major transportation hubs such as train stations, airports, and subways. Utilizing deep learning technology to assist security personnel in X-ray security inspections can, to some extent, reduce the occurrence of false positives or missed detections due to personnel fatigue from prolonged use.

[0003] The specific characteristics of X-ray security images, such as obstruction caused by overlapping luggage and items, and the arbitrary orientation of items leading to the loss of directional features of the target by the detection method, have brought many challenges to X-ray security inspection tasks.

[0004] Deep learning-based object detection methods can be broadly categorized into two types: two-stage object detection methods and one-stage object detection methods. Two-stage object detection methods consist of two steps: first, region generation, which generates candidate boxes that may contain the target based on the input image; then, a convolutional neural network further classifies and calibrates these candidate boxes. Typical two-stage detection methods include R-CNN and SPP-Net. Two-stage object detection methods offer high detection accuracy, but their slower speed does not meet the real-time requirements of X-ray hazardous materials detection. One-stage object detection methods do not require candidate box generation; they directly regress the target's class probability and location coordinates through a network. Typical one-stage object detection methods include the SSD series and the YOLO series. Summary of the Invention

[0005] This invention aims to address the occlusion problem caused by target stacking in X-ray security inspection images and the insufficient ability to locate and identify small targets in complex backgrounds. It provides a method for detecting dangerous goods in X-ray security inspection images based on YOLOv7.

[0006] The present invention discloses a method for detecting dangerous goods using X-ray security images based on YOLOv7, comprising:

[0007] Step 1: Obtain the dataset of X-ray security inspection images containing dangerous goods and divide the dataset;

[0008] Step 2: Perform data augmentation on the dataset;

[0009] Step 3: Use the K-means++ clustering method to set the prior boxes for the dataset;

[0010] Step 4: Introduce a CA attention module into the MPConv structure to enhance the feature extraction capability of the backbone network.

[0011] Step 5: Add skip connections to the branch containing the CA attention module to prevent gradient vanishing during backpropagation;

[0012] Step 6: Use BiFPN as the feature fusion structure for the downsampling module to reduce the number of model parameters;

[0013] Step 7: Improve the loss function to SIoU to enhance the accuracy of the predicted bounding boxes and accelerate the model convergence speed;

[0014] Step 8: Train the improved YOLOv7 model using the training set to obtain the X-ray security inspection image detection model;

[0015] Step 9: Test the X-ray security inspection image detection model using the test set.

[0016] Furthermore, in this invention, in step one, the publicly available dataset SIXRay is selected as the test dataset. The dangerous goods in the dataset include five categories: firearms, knives, wrenches, pliers, and scissors. First, the dataset format is converted from XML to TXT format, and then the dataset is randomly divided into training set, validation set, and test set in an 8:1:1 ratio.

[0017] Furthermore, in step two of this invention, data augmentation is performed on the dataset using two techniques, Mosaic and MixUp, which can enrich the samples and improve the problem of uneven distribution of sample types.

[0018] Furthermore, in step three of this invention, the K-means++ clustering method is used to calculate the shortest distance between each sample in the dataset and the cluster center. Then, the probability of each sample becoming a cluster center is calculated, and the roulette wheel method is used to determine the cluster center for the next clustering method. This process is repeated until the cluster centers are obtained. The specific method for obtaining the cluster centers is as follows:

[0019] Step 3.1 The IoU distance between the sample and the cluster center is:

[0020]

[0021] Where box is the sample bounding box, centroid is the cluster center, and IOU is the intersection-union ratio of the sample bounding box and the cluster center box;

[0022] Step 3.2: Repeatedly calculate the shortest distance between each sample and the center, the probability of each sample becoming a cluster center, and determine the next cluster center until k cluster centers are selected;

[0023] Step 3: Calculate the IoU distance from each sample in the dataset to the k cluster centers, and assign the sample to the class corresponding to the cluster center that is closest to it, thereby obtaining the prior box corresponding to each sample in the dataset.

[0024] Furthermore, in step four of this invention, a CA attention module is introduced into the MPConv structure to enhance the feature extraction capability of the backbone network:

[0025] In the MPConv structure of the YOLOv7 model, a coordinate attention mechanism is combined to extract features from multiple dimensions such as channel position, thereby expanding the global interactive receptive field and avoiding feature loss.

[0026] In the coordinate attention mechanism module, during the coordinate information embedding process, the input feature map X is assumed to have dimensions C×H×W, where C is the number of channels, H is the height, and W is the width. First, convolutional pooling kernels of size H×1 and 1×W are used to decompose the input image feature map into two one-dimensional encoding processes along the horizontal and vertical directions. Let X be the feature in the C-th channel. Let the direction-aware feature output in the c-th channel be of height h and width w. and Let i and j represent coordinate values, then we have:

[0027]

[0028]

[0029] in, and These are the direction-aware output features of height h and width w on the c-th channel, respectively. and These are the initial width and height of the input feature map. Then, the feature map... and Perform a stitching operation along the spatial dimension to generate an intermediate feature map. Where r is the compression ratio, and then the intermediate feature map is processed along the spatial dimension. Then split into two separate tensors and The two tensors are augmented using 1x1 convolutions to ensure that the channel dimensions of the generated feature map match those of the input feature map X. After processing with the Sigmoid activation function, two more tensors are obtained. and Finally, for and The expansion is used as attention weights to obtain the output feature map. The expression implemented by the coordinate attention mechanism module is as follows:

[0030]

[0031] in, and To use convolution operations with a kernel size of 1×1; This is a non-linear operation; is the Sigmoid function; [·, ·] is the concatenation operator.

[0032] Furthermore, in step five of this invention, a skip connection is added to the branch where the CA attention module is located to avoid gradient vanishing during backpropagation.

[0033] Furthermore, in step six of this invention, the use of the BiFPN feature fusion module with fewer parameters as the feature pyramid structure of the YOLOv7 network enables the network to fuse more features while effectively reducing the computational load of the model by introducing cross-scale connections and multi-scale weighted fusion.

[0034] The BiFPN feature fusion structure differs from the PANet feature fusion structure in that it employs a cross-scale connection approach. The input feature layer extracts features through multi-scale weighted fusion and a series of cross-scale operations within the BiFPN structure. Multi-scale feature fusion aims to fuse features at different resolutions, given multiple features at different scales. ,in express Layer characteristics, using transformation indicators Aggregate features at different scales and output multiple new aggregated features. .

[0035] BiFPN is a weighted bidirectional feature pyramid structure based on bidirectional cross-scale connectivity and fast normalization fusion. The input features are level 6 features fused as follows:

[0036]

[0037] in Intermediate features of level 6 in the downsampling path, This refers to the output features of level 6 in the upsampling path. Here, Conv is a depthwise separable convolution, and BN and an activation function are added after each convolution. BiFPN simplifies the feature fusion network by eliminating nodes with only one input, as such single-input nodes do not support feature fusion. A branch is added between the input and output nodes to simplify the network structure and enhance the feature fusion network by incorporating more features.

[0038] In the YOLOv7 network, the BiFPN structure is combined with MPConv to enhance the model's ability to locate and identify small targets in complex backgrounds. At the same time, the number of model parameters and computational cost are reduced by reducing single input nodes and cross-scale connections, which meets the real-time requirements of X-ray security inspection tasks.

[0039] Furthermore, in this invention, in step seven, SIoU is used instead of CIoU as the loss function. The YOLOv7 model uses the CIoU loss function to calculate the loss. CIoU uses relative bounding boxes to describe the aspect ratio of the ground truth box and the predicted box. When their aspect ratios are the same, the penalty term is 0, indicating that using the difference in aspect ratios as a penalty term does not accurately reflect the true difference between length and width. The SIoU loss function is used to calculate the localization loss, and its definition formula is:

[0040]

[0041] Among them, the larger the weighting parameter of shape cost in the positioning loss, the less important shape cost is in the positioning loss.

[0042] Furthermore, in this invention, the method for training the improved YOLOv7 model using the training set to obtain the X-ray security inspection image detection model in step eight is as follows:

[0043] Modify the YOLOv7 cfg file, including changing the `classes` parameter in the data's YAML file to the number of classes labeled in the dataset, and modifying the `filters` parameter in each convolutional layer to `filters=(classes+5)*3`. Set the hyperparameters of the network model, including the input image size used for training the dataset and testing model performance, the batch size of input data per batch, the number of training epochs, and the learning rate.

[0044] Before training the improved model proposed in this invention, settings are configured in hyp.scratch.p5.yaml to simulate the real-world scenario of stacked and occluded items in X-ray security inspection images using two data augmentation methods: Mosaic and Mixup. The improved YOLOv7 model is trained using the data-augmented training set. During training, an improved SIoU confidence loss function is used to construct the total loss function. The training weights are iteratively updated during gradient backpropagation, and the optimal weights from the iteration process are saved as the X-ray security inspection image detection model.

[0045] Furthermore, in step nine of this invention, the X-ray security inspection image detection model is tested using a test set. The test set is input into the X-ray security inspection image detection model for dangerous goods detection. To further improve the detection accuracy of dangerous goods obscured by stacked items in luggage, the SoftNMS flexible nonmaximum suppression method is used to filter redundant prediction boxes during detection, eliminating overlapping bounding boxes or other types of regions, thus obtaining location and category information containing the dangerous goods image. Attached Figure Description

[0046] Figure 1 This is a flowchart of the method for detecting dangerous goods using X-ray security images based on YOLOv7 in this invention.

[0047] Figure 2 This is a schematic diagram of the YOLOv7-based network structure in the method of this invention.

[0048] Figure 3 This is a schematic diagram illustrating the principle of coordinate attention (CA) added to the pooling convolutional layer in the method of this invention.

[0049] Figure 4 This is a schematic diagram of the improved feature fusion structure BiFPN in the method of this invention.

[0050] Figure 5 This is a schematic diagram illustrating the principle of MPCN combining CA and BiFPN in the method of this invention.

[0051] Figure 6 This is a comparison chart of the average accuracy of the improved method YOLOv7-MPCN and YOLOv7 in this invention.

[0052] Figure 7 This is a graph showing the training metrics of the improved method YOLOv7-MPCN in this invention on the training set.

[0053] Figure 8 This is a visualization of the detection results of the improved method YOLOv7-MPCN in this invention on the test set. Detailed Implementation

[0054] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0055] The flowchart of the hazardous materials detection method based on the improved YOLOv7 X-ray security inspection image in this specific embodiment is as follows: Figure 1 As shown, the improved YOLOv7-MPCN network structure diagram is as follows: Figure 2 As shown, it includes the following steps:

[0056] Step a: Obtain the dataset of X-ray security inspection images containing dangerous goods and divide the dataset.

[0057] In this specific implementation, the publicly available dataset, SIXRay dataset, is used.

[0058] The SIXRay dataset consists of X-ray security images obtained from personal baggage scans. It contains five categories of dangerous items: firearms, knives, pliers, wrenches, and scissors. The distribution of these dangerous items across the dataset is shown in Table 1. 8929 X-ray security images contain dangerous items. The dataset was randomly divided into training, validation, and test sets in an 8:1:1 ratio.

[0059] Table 1. Distribution of the number of categories in the SIXRay dataset

[0060] category firearms knife wrench pliers scissors quantity 3,131 1,943 2,199 3,961 983

[0061] Step b: Perform data augmentation on the dataset.

[0062] The use of Mosaic and MixUp data augmentation techniques enhances the model's robustness and better reflects security inspection scenarios. Data augmentation can prevent overfitting to some extent. Since X-ray security inspection images are mostly taken inside suitcases, using MixUp and style transfer methods can prevent the model from learning information irrelevant to the target. Mosaic and MixUp are classic data augmentation techniques combining two methods. The biggest difference between X-ray security inspection images and natural scene images is that X-ray images are transmissive; even stacked items can still show the outline of overlapping targets. MixUp can satisfy this characteristic of X-ray images. Secondly, the Mosaic data augmentation technique, which randomly crops and stitches together four images, enriches background information and shortens training time.

[0063] Step c: Use the K-means++ clustering method to set the prior boxes for the dataset.

[0064] Step c1, the IoU distance between the sample and the cluster center is:

[0065]

[0066] Where box is the sample bounding box, centroid is the cluster center, and IoU is the intersection-union ratio of the sample bounding box and the cluster center box;

[0067] Step c2: Repeatedly calculate the shortest distance between each sample and the center, the probability of each sample becoming a cluster center, and determine the next cluster center until k cluster centers are selected;

[0068] Step c3: Calculate the IoU distance from each sample in the dataset to the k cluster centers, and assign the sample to the class corresponding to the cluster center that is closest to it to obtain the prior box corresponding to each sample in the dataset. In this embodiment, the K-means++ clustering method is used to obtain 9 anchor boxes suitable for the X-ray security inspection image dataset, which are (22, 29), (33, 46), (47, 73), (71, 35), (81, 115), (147, 107), (103, 202), (195, 232), and (363, 481).

[0069] Step d: Introduce a CA attention module into the MPConv structure to enhance the feature extraction capability of the backbone network.

[0070] YOLOv7 mainly consists of three parts: Backbone, Neck, and Head. The Backbone uses ELAN (Efficient Layer Aggregation Networks) and MPConv for feature extraction. The Neck network employs a PANet design with a Feature Pyramid Network (FPN) architecture to fuse the features extracted by the Backbone network. It mainly consists of four parts: CBS, ELAN, SPC (Spatial Pyramid Pooling Cross Stage Partial Common), and MPConv. The Head network uses a Rep structure (RepVGG Block) to adjust the image channel count of the three different scale features (P3, P4, and P5) output from the Neck network. Finally, it uses 1×1 convolutions for confidence, class, and anchor box prediction.

[0071] Introducing coordinate attention (CA) into the YOLOv7 network enhances its ability to locate and identify overlapping and small targets in complex backgrounds. The CA structure is as follows: Figure 3 As shown, the coordinate attention mechanism module includes coordinate information embedding and coordinate attention generation. In the coordinate information embedding process, the size of the input feature map X is first set to C×H×W, where C is the number of channels, H is the height, and W is the width. First, convolutional pooling kernels of size H×1 and 1×W are used to decompose the input image feature map into two one-dimensional encoding processes along the horizontal and vertical directions. The direction-aware feature output is... and of

[0072] The calculation formula is:

[0073]

[0074]

[0075] Where C is the number of channels. It is the feature of X in the Cth channel. and It is the orientation-aware feature output of the c-th channel with height h and width w, where i and j represent coordinate values. and These are the initial width and height of the input feature map.

[0076] In the second stage of the CA module, namely the coordinate attention generation process, the channels with embedded coordinate information from the previous stage are first aggregated along the horizontal and vertical spatial directions to obtain a feature map. and Next, the two feature maps are spatially concatenated, and channel compression is performed using 1×1 convolution. After batch normalization and activation functions, an intermediate feature map containing two directions is obtained. Where r is the compression ratio, and then the intermediate feature map is processed along the spatial dimension. Then split into two separate tensors and The two tensors are augmented using a 1×1 convolution to ensure that the channel dimensions of the generated feature map are consistent with those of the input feature map X. After processing with the Sigmoid activation function, two tensors are obtained. and .

[0077] Finally, and The expansion is used as attention weights to obtain the output feature map. The expression implemented by the coordinate attention mechanism module is as follows:

[0078]

[0079] in, and To use convolution operations with a kernel size of 1×1; This is a non-linear operation; is the Sigmoid function; [·, ·] is the concatenation operator.

[0080] Reuse Convolutional channel expansion ensures that the feature map's feature dimensions remain consistent with the input. CA attention, through this design, allows one branch to carry horizontal positional information and another to carry vertical positional information, thus completely preserving the spatial positional information of the input image. This makes the deeper convolutions in the network more sensitive to the positional information of the feature map, enabling the model to more accurately locate target features and effectively improving the model's detection capabilities.

[0081] Step e: Add a skip connection to the branch containing the CA attention module to prevent gradient vanishing during backpropagation.

[0082] To avoid gradient vanishing and diffusion issues, a residual network structure is introduced into the YOLOv7 network. During downsampling in the YOLOv7 object detection model, the reduced size and lower resolution of the feature maps caused by the convolutional layers lead to the loss of some positional information. In the original MPConv structure, CA attention replaces the CBS (ConvBatch Norm SiLU) basic convolutional module with a kernel of 1 in the lower branch of MPConv. This extracts features from multiple dimensions, such as channel position, expanding the global interactive receptive field and preventing feature loss. A skip connection is added to the lower branch of MPConv, dividing the feature input into a main input and a residual input. When gradient vanishing or diffusion occurs in the main branch containing the CA module, the network can backpropagate gradients through the residual input branch, helping to prevent information loss.

[0083] Step f: Use BiFPN as the feature fusion structure for the downsampling module to reduce the number of model parameters.

[0084] BiFPN structure as follows Figure 4 By adopting BiFPN as the feature fusion structure of the improved MPCN (Improved Maxpooling Convolution Layer with CA and BiFPN) structure, cross-scale connectivity and multi-scale weighted fusion are introduced to further reduce the number of model parameters and computational cost.

[0085] The BiFPN feature fusion structure differs from the PANet feature fusion structure in that, in addition to having bidirectional feature fusion paths, it also employs a cross-scale connection method. The input feature layer extracts features through multi-scale weighted fusion and a series of cross-scale operations within the BiFPN structure. Multi-scale feature fusion aims to fuse features at different resolutions, given multiple features at different scales. ,in express Layer characteristics, using transformation indicators Aggregate features at different scales and output multiple new aggregated features. .

[0086] BiFPN is a weighted bidirectional feature pyramid structure based on bidirectional cross-scale connectivity and fast normalization fusion. The input features are level 6 features fused as follows:

[0087]

[0088] in Intermediate features of level 6 in the downsampling path, This refers to the output features of level 6 in the upsampling path. Here, Conv is a depthwise separable convolution, and BN and an activation function are added after each convolution. BiFPN simplifies the feature fusion network by eliminating nodes with only one input, as such single-input nodes do not support feature fusion. A branch is added between the input and output nodes to simplify the network structure and enhance the feature fusion network by incorporating more features.

[0089] In the YOLOv7 network, the MPConv module incorporates a BiFPN structure. By reducing single-input nodes and cross-scale connections, the number of model parameters and computational cost are reduced to meet the real-time requirements of X-ray security inspection tasks. The improved MPCN module structure is as follows: Figure 5 As shown, MPCN can enable networks to reach greater depths without encountering the gradient vanishing problem, and the features learned by the network are more sensitive to fluctuations in weights.

[0090] Step g: Improve the loss function to SIoU to enhance the accuracy of the predicted bounding boxes and accelerate the model convergence speed.

[0091] The YOLOv7 model uses the CIoU loss function to calculate the loss. CIoU uses relative bounding boxes to describe the aspect ratio of the ground truth bounding box and the predicted bounding box. When their aspect ratios are the same, the penalty term is 0, indicating that using the difference in aspect ratios as a penalty term does not accurately reflect the true difference between length and width. To address this issue, the SIoU loss function is used to calculate the localization loss, and its definition formula is:

[0092]

[0093]

[0094] in, Let SoU represent the SioU loss function of the model, where IoU is the intersection-over-union ratio of the predicted bounding box and the ground truth bounding box, and B represents the predicted bounding box. The bounding box represents the actual bounding box, Δ represents the distance cost, and Ω represents the shape cost.

[0095] The specific calculation methods for the angle cost, distance cost, and shape cost of the SIoU loss function are as follows:

[0096] Angular cost:

[0097]

[0098]

[0099] Where x is the sine of α, σ is the distance between the center point of the ground truth box and the center point of the predicted box, and ch is the difference in the ordinate of the center point.

[0100] Distance cost:

[0101]

[0102] Where γ = 2−Λ, ρt is the square of the difference between the coordinates of the center points of the two boxes, and Λ is calculated from the angle cost.

[0103] Shape cost:

[0104]

[0105] The weight of shape cost in the localization loss is controlled by the parameter θ; the larger the value of θ, the less important the shape cost is in the localization loss. ϖw represents the ratio of the difference between the width of the ground truth bounding box and the predicted bounding box to its maximum value, and ϖh represents the ratio of the difference between the height of the ground truth bounding box and the predicted bounding box to its maximum value.

[0106] In the YOLOv7 network model, the total loss function includes the classification loss function, the location loss function, and the confidence loss function. The confidence loss function is optimized using SIoU, thereby optimizing the total loss function. By considering the vector angle between the required regressions, the penalty index is redefined, which greatly helps the network's training convergence process and performance.

[0107] Step h: Train the improved YOLOv7 model using the training set to obtain the X-ray security inspection image detection model.

[0108] The method for training the improved YOLOv7 model using the training set to obtain the X-ray security inspection image detection model is as follows:

[0109] Modify the YOLOv7 cfg file, including changing the classes in the data's yaml file to the number of classes labeled in the dataset, and modifying the filters parameter in each convolutional layer to filter=(classes+5)*3.

[0110] Set the hyperparameters of the network model, including the input image size for training the dataset and testing model performance to 640. 640. The batch size of each input data is 8, the number of training epochs is 300, and the learning rate is 0.0001.

[0111] Before training the improved model proposed in this invention, settings are made in hyp.scratch.p5.yaml to use two data augmentation methods, Mosaic and Mixup, to simulate the real scene of X-ray security inspection images where items are stacked and obscured, thereby enhancing the generalization and robustness of the model.

[0112] Step h1: The present invention uses a common evaluation system in target detection methods to evaluate the model, including recall, F1-score, precision, and mean average precision mAP@0.5 (mean average precision, IoU threshold is 0.5).

[0113] For each class, the following metrics are calculated: AP (Average Precision), mAP (Mean Accuracy), Precision, Recall, and... The formula for calculating fractions is as follows:

[0114]

[0115]

[0116]

[0117]

[0118]

[0119] Where TP is the number of correctly identified positive samples; TN is the number of correctly identified negative samples; FP is the number of negative samples that were incorrectly identified as positive samples; and FN is the number of positive samples that were incorrectly identified as negative samples. The F1 score can be calculated from the accuracy and recall. These are positive samples that have been correctly identified. These are the correctly identified negative samples; These are negative samples that were incorrectly identified. (This is achieved through...) and The area enclosed by the precision and recall curves (PR curves) and the coordinate axes can be used to calculate the average precision for each target category.

[0120] Step h2: Since the purpose of the improved model proposed in this invention is to improve the target detection accuracy of the YOLOv7 method, the main indicator for evaluating the model performance is mAP@0.5. Therefore, the average accuracy of the original YOLOv7 model and the YOLOv7-MPCN proposed in this invention on the SIXRay dataset is compared, demonstrating that the improved model has higher detection accuracy. Figure 6 As shown.

[0121] Step h3: Train the improved YOLOv7 model using the data-augmented training set, and demonstrate this through three loss curves and three metric curves. Figure 7 As shown. `val_Box` represents the validation set bounding box; its value decreases and eventually stabilizes after 100 training epochs. `val_Objectness` represents the mean object detection loss on the validation set; the mean loss stabilizes after 200 training epochs. `val_Classification` represents the mean classification loss on the validation set; the mean loss converges after 50 training epochs. `Precision` represents the percentage of correctly identified positive classes on the validation set; the value of `Precision` stabilizes after 250 training epochs. `Recall` describes how many real positive examples are recalled by the binary classifier from the perspective of actual results; the recall rate gradually converges after 100 training epochs.

[0122] Step i: Test the X-ray security inspection image detection model using a test set.

[0123] Step i1: Test the X-ray security inspection image detection model using a test set. Input the test set into the X-ray security inspection image detection model for dangerous goods detection. To further improve the detection accuracy of dangerous goods obscured by stacked items in luggage, the Soft-NMS flexible non-maximum suppression method is used to filter redundant predicted boxes and eliminate overlapping bounding boxes or other types of regions. This method obtains the location and category information of the image containing the dangerous goods. Soft-NMS considers the scores (e.g., confidence scores) of all candidate boxes and candidate boxes with overlap with the highest-scoring candidate box, using weight decay instead of using confidence score as the standard for filtering predicted boxes, which is particularly suitable for dense target detection. The specific calculation method of Soft-NMS is as follows:

[0124]

[0125] Where M represents the bounding box with the highest confidence level. Represents the adjacent bounding boxes within the neighborhood. This represents the score of the current bounding box, and IoU represents the threshold between two bounding boxes. This represents the threshold for the bounding box. When the overlap is less than the given bounding box threshold, the classification confidence score remains unchanged; while when the overlap is greater than the given bounding box threshold, the classification confidence score decays linearly.

[0126] Step h2 and Table 2 show the comparison results of the proposed method with five different current mainstream target detection methods—M2Det, SSD (Single Shot Detector), YOLOv4, YOLOv5s, and YOLOv7—on the SIXRay dataset. Clearly, the proposed method outperforms all the compared methods, achieving the highest accuracy in detecting all four categories of hazardous materials on the dataset.

[0127] Table 2 Comparison of detection accuracy of different detection methods on the SIXRay dataset

[0128] method Gun (%) Knife (%) Wrench(%) Pliers(%) Scissors (%) mAP(%) M2Det 95.49 75.70 70.17 83.00 82.96 81.47 SSD 94.91 77.87 74.82 84.51 82.69 82.96 YOLOv4 94.40 81.69 77.38 84.50 77.55 83.11 YOLOv5s 98.40 86.70 88.40 92.70 79.20 89.10 YOLOv7 98.60 90.00 92.40 93.80 83.30 91.60 YOLOv7-MPCN 98.30 90.50 94.00 93.90 85.50 92.50

[0129] The improved method proposed in this invention achieves the following detection results on the test set: Figure 8 As shown in the figure, where Figure a) is a normal target image, Figure b) is a small target image, Figure c) is an occluded target image, and Figure d) is an overlapping target image, it can be seen that the improved method can accurately detect dangerous goods targets in luggage.

[0130] While the invention has been described herein with reference to specific embodiments, it should be understood that these embodiments are merely examples of the principles and applications of the invention. Therefore, it should be understood that many modifications can be made to the exemplary embodiments, and other arrangements can be designed without departing from the spirit and scope of the invention as defined by the appended claims. It should be understood that different dependent claims and features described herein can be combined in ways different from those described in the original claims. It is also understood that features described in conjunction with individual embodiments can be used in other described embodiments.

Claims

1. A method for detecting dangerous goods using X-ray security images based on YOLOv7, characterized in that, Includes the following steps: Step 1: Obtain the dataset of X-ray security inspection images containing dangerous goods and divide the dataset; Step 2: Perform data augmentation on the dataset; Step 3: Use the K-means++ clustering method to set the prior boxes for the dataset; Step 4: Introduce a CA attention module into the MPConv structure to enhance the feature extraction capability of the backbone network. Add skip connections to the branch where the CA attention module is located to avoid gradient vanishing during backpropagation. Use BiFPN as the feature fusion structure of the downsampling module to reduce the number of model parameters. Use BiFPN as the feature fusion structure of the improved MPConv structure to introduce cross-scale connections and multi-scale weighted fusion to further reduce the number of model parameters and computational cost. Step 5: Improve the loss function to SIoU to enhance the accuracy of the predicted bounding boxes and accelerate the model convergence speed; Step 6: Train the improved YOLOv7 model using the training set to obtain the X-ray security inspection image detection model; Step 7: Test the X-ray security inspection image detection model using the test set.

2. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, Step one, which involves acquiring a dataset of X-ray security inspection images containing hazardous materials and dividing the dataset, specifically includes: The SIXRay dataset of public X-ray security inspection images, totaling 8929 images, was divided into training, validation, and test sets in an 8:1:1 ratio. Dangerous items included five categories: firearms, knives, pliers, wrenches, and scissors.

3. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, The data augmentation of the dataset described in step two specifically includes: Data augmentation was performed on the dataset using two methods: Mosaic and Mixup. Mosaic technology involves performing a series of operations on four random images and then stitching them together. Mixup is a mixed-class augmentation technique that combines images of different classes to achieve the purpose of data augmentation.

4. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, In step three, the prior bounding boxes of the dataset are set using the K-means++ clustering method, and nine anchor boxes suitable for the X-ray security inspection image dataset are obtained through the K-means++ clustering method.

5. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, Step four is as follows: The YOLOv7 network incorporates a coordinate attention mechanism to enhance its ability to locate and identify overlapping and small targets in complex backgrounds. The coordinate attention mechanism module includes coordinate information embedding and coordinate attention generation. In the original MPConv structure, the Coordinate Attention mechanism replaces the Conv BatchNorm SiLU basic convolutional module with a kernel of 1 in the lower half of MPConv with Coordinate Attention, which effectively enhances the network's ability to locate and identify overlapping and small targets.

6. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, The jump connection added in step four is as follows: Borrowing from residual network structures, YOLOv7 avoids gradient vanishing and gradient disappearance issues by adding a skip connection to the lower half of the MPConv branch, splitting the feature input of the lower half branch into the main input and the remaining input. In some cases, when the main branch containing the CA module experiences gradient vanishing or gradient loss, the network backpropagates the gradient through the remaining input branches, which helps prevent information loss.

7. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, Step four uses a Bidirectional Feature Pyramid Network as the feature fusion structure for the downsampling module, specifically as follows: In addition to having bidirectional feature fusion paths, the BiFPN feature fusion structure also adopts a cross-scale connection method, which effectively reduces the computational cost and parameter count of the YOLOv7 network. Combining the BiFPN structure with MPConv in the YOLOv7 network meets the real-time requirements of X-ray security inspection tasks. The MPCN structure allows the network to reach greater depths without encountering the gradient vanishing problem, and the features learned by the network are more sensitive to fluctuations in weights.

8. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, Step five involves improving the confidence loss function of YOLOv7 using SIoU as follows: The YOLOv7 model uses the CIoU loss function to calculate the loss. CIoU calculates the difference in aspect ratio as a penalty term, but it cannot accurately reflect the true difference between length and width. SIoU is used to optimize the confidence loss function, thereby optimizing the overall loss function.

9. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, Step six specifically involves: The method for training the improved YOLOv7 model using the training set to obtain the X-ray security inspection image detection model is as follows: modify the YOLOv7 cfg file, including changing the classes in the data yaml file to the number of classes labeled in the dataset, and modifying the filters parameter in each convolutional layer to change filters=(classes+5)*3. Set the hyperparameters of the network model, with an input image size of 640.

640. The batch size of each input data is 8, the number of training epochs is 300, and the learning rate is 0.0001. In the hyp.scratch.p5.yaml file, two data augmentation methods, Mosaic and Mixup, are used to simulate the real-world scenario of items being stacked and obscured in X-ray security inspection images, thereby enhancing the generalization and robustness of the model. The model was evaluated using an evaluation system for object detection methods, including recall, F1-score, precision, and mean average precision (mAP@0.5).

10. The method for detecting dangerous goods using X-ray security images based on YOLOv7 according to claim 1, characterized in that, Step seven is as follows: The X-ray security inspection image detection model was tested using a test set. During detection, a flexible nonmaximum suppression method was used to filter redundant prediction boxes and eliminate overlapping bounding boxes or other types of regions. In this way, the location and category information of the dangerous goods image were obtained.

Citation Information

Patent Citations

  • X-ray security check image detection method based on improved YOLOv4

    CN113362299A

  • Port container damage detection method and system based on improved YOLOv5

    CN116645586A