Improved YOLOv8 X-ray security check image dangerous goods detection system
By improving the YOLOv8 model, combining GELAN and EMA modules, the loss function is updated to inner-CIoU, which solves the problem of low detection accuracy of overlapping objects in X-ray security images, and realizes efficient and accurate detection of prohibited items, which is suitable for real-time security inspection.
Patent Information
- Application Number
- CN202411061740.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-02
- Publication Date
- 2024-11-29
AI Technical Summary
The detection accuracy of overlapping objects in X-ray security images is not high, the detection speed of traditional algorithms is slow and cannot meet the real-time requirements, making it difficult to accurately detect chaotic arrangements and prohibited items of different sizes in luggage.
Improve the YOLOv8 model, through data enhancement, introduction of GELAN and EMA modules, update the loss function to inner-CIoU, build a YOLO-GEMA network, enhance feature extraction and overlapping object detection capabilities, and improve detection accuracy and speed.
It improves the accuracy and efficiency of detection of prohibited items in X-ray security images, reduces false alarms and missed inspections, and is suitable for real-time applications, and can quickly and accurately identify prohibited items of different sizes and overlaps.
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] The invention belongs to the field of dangerous goods detection using X-ray security inspection images. Background Art
[0002] The demand for luggage security inspection of prohibited items in public places such as airports, rail transit, and customs is increasing. Traditional X-ray security inspection mainly relies on manual screening, which is not only inefficient, but also its accuracy and stability are limited by the experience and concentration of security inspectors, resulting in missed inspections and false alarms. In order to improve the accuracy and efficiency of X-ray security image dangerous goods detection, the technology of X-ray security image dangerous goods detection of prohibited items based on deep learning came into being.
[0003] X-ray security images have some unique characteristics that increase the difficulty of dangerous goods detection using computer vision technology:
[0004] 1. Problem of messy items: Items in luggage are usually arranged in a disorderly manner. X-rays have a transmission effect, and dangerous goods often overlap in security inspection images.
[0005] 2. Imaging angle problem: Fixed perspective X-rays can easily cause poor imaging angles for dangerous goods, making it difficult to accurately and effectively extract the features of prohibited items.
[0006] 3. Dangerous goods size problem: The detection of prohibited items can be regarded as a multi-scale, multi-target detection problem. Size differences can easily cause the detection model to ignore smaller targets or even cause missed detections.
[0007] The target detection algorithms based on deep learning are mainly divided into two categories: two-stage and one-stage. The two-stage target detection algorithm includes two steps: first, region generation is performed to generate candidate boxes that may contain the target based on the input image; then, the candidate boxes are further classified and position calibrated using a convolutional neural network. Typical algorithms include Region-Convolutional Neural Network (R-CNN) and Space Pyramid Pooling-Network (SPP-Net). This type of algorithm has high detection accuracy, but due to its complex processing process, the detection speed is slow and cannot meet the real-time requirements of X-ray security image dangerous goods detection. In contrast, the one-stage target detection algorithm directly regresses the target's category probability and position coordinate value through the network without generating candidate boxes. Typical one-stage algorithms include Single Shot MultiBox Detector (SSD) series and You Only Look Once (YOLO) series. The YOLOv8 model provides five network structures of different sizes (n, s, m, l, x), which can better meet the needs of different scenarios, improve the real-time and accuracy of detection, and has great development potential in the detection of dangerous goods in X-ray security inspection images. Summary of the invention
[0008] The present invention aims to solve the problem of low detection accuracy of overlapping targets in X-ray security inspection images, and proposes an X-ray security inspection image dangerous goods detection system based on improved YOLOv8.
[0009] The present invention provides an improved YOLOv8 X-ray security inspection image dangerous goods detection system, comprising:
[0010] Step 1: Perform data enhancement on the X-ray security inspection image dataset (PIDray);
[0011] Step 1. Convert the format of the PIDray dataset from json to txt;
[0012] Step 1 and 2: Use horizontal flipping for data augmentation and set the parameter (flip) to 0.5, which allows the model to learn the mirror representation of the object and enhance the robustness to direction changes;
[0013] Step 13: Use Scale Transformation for data enhancement and set the parameter (scale) to 0.5. This allows the model to adapt to objects of different sizes, which is crucial for detecting the same object at different distances.
[0014] Step 2: Combined with YOLOv8, GELAN (Generalized Efficient Layer Aggregation Network) and EMA (Effcient Multi-Scale Attention) modules are introduced for improvement, the loss function is updated to inner-CIoU, and the YOLO-GEMA network is constructed;
[0015] Step 21: In Backbone and Neck of YOLOv8, the GELAN network architecture is adopted, and RepNCSP is adopted in any block in GELAN to enhance the network feature extraction capability and improve the computational efficiency;
[0016] Step 22: Add the EMA module to the Neck of YOLOv8 to enhance the detection capability of overlapping dangerous goods in X-ray security inspection images;
[0017] Step 2 and 3: Improve the loss function to inner-CIoU to improve the accuracy of prediction boxes of different scales and speed up the convergence of the model;
[0018] Step 3: Use the training set to train the improved YOLOv8 model to obtain the X-ray security inspection image detection model.
[0019] Step 4: Use the test set to test the trained X-ray security image detection model.
[0020] Furthermore, in the present invention, in step 1, a public PIDray dataset is selected for model training and testing, and data enhancement is performed.
[0021] Step 1: First, convert the format of the data set from json format to txt format. The data set includes a divided training set and a test set. The division structure of the data set is shown in Table 1. In the present invention, the training set adopts Train and the test set adopts the Easy mode in Test.
[0022] Table 1 PIDray dataset structure division table
[0023]
[0024] Step 1 and 2: Use horizontal flipping and set the parameter (flip) to 0.5, which allows the model to learn the mirror representation of the object and enhance the robustness to direction changes;
[0025] Step 13: Use Scale Transformation for data enhancement and set the parameter (scale) to 0.5. This allows the model to adapt to objects of different sizes, which is crucial for identifying the same object at different distances.
[0026] Furthermore, in the present invention, in step 2, YOLOv8 is combined, GELAN and EMA modules are introduced for improvement, the loss function is updated to inner-CIoU, and a YOLO-GEMA network is constructed;
[0027] Step 21: Use GELAN network architecture in Backbone and Neck of YOLOv8:
[0028] In the detection of dangerous goods in X-ray security images, the GELAN architecture is combined with the RepNCSP module, which has an optimized gradient path and efficient feature fusion capabilities, which is crucial to improving detection accuracy and speed. By combining the gradient path optimization of CSPNet with the layer aggregation efficiency of ELAN, the RepNCSPELAN4 module significantly enhances the feature extraction capabilities, especially when dealing with overlapping and sized objects. The module optimizes gradient transmission and reduces computational load, enabling the network to quickly and accurately identify and locate dangerous goods, especially when the objects are cluttered and overlapped. Its lightweight design ensures efficient real-time applications and is suitable for a variety of model sizes and complexities.
[0029] Step 22: Add the EMA module to the Neck of YOLOv8 to enhance the recognition ability of overlapping dangerous goods in X-ray security inspection images.
[0030] In X-ray security image detection systems, channel or spatial attention mechanisms have shown significant effects in generating more distinguishable feature representations. However, when modeling cross-channel relationships, reducing the channel dimension may have a negative impact on the extraction of deep visual representations. In this paper, an efficient multi-scale attention module (EMA) is adopted.
[0031] The EMA module plays a key role in enhancing the effectiveness of X-ray security image detection systems. Its design utilizes channel and spatial attention mechanisms to improve the necessary feature differentiation capabilities to accurately and efficiently detect contraband in X-ray security images. By maintaining the full channel dimension and integrating multi-scale convolutional structures (1×1 and 3×3 convolutions), the EMA module effectively captures detailed and wider spatial features. This ability is critical for distinguishing overlapping items in luggage that are usually chaotically arranged in X-ray security images. The parallel substructure of the EMA module enables it to handle items of different sizes in luggage. The multi-scale design enables the module to detect small items that may be overlooked while accurately describing large items, thereby addressing the challenges of multi-scale detection. By integrating an enhanced attention mechanism to focus on the areas of interest in X-ray security images, the EMA module reduces the possibility of false alarms and missed detections.
[0032] For any given input feature map, EMA divides it into G sub-features in the channel dimension to learn different semantics. It is generally assumed that each sub-feature contains C / G channels, and the learned attention weights will be used to enhance the feature representation of the region of interest in each sub-feature.
[0033] EMA adopts three parallel paths to extract attention weight descriptors from grouped feature maps. Two paths are in the 1×1 branch, while the third one is in the 3×3 branch. The 1×1 branch uses two 1D global average pooling operations to encode channels along two spatial directions, while the 3×3 branch uses a single 3×3 convolution kernel to capture multi-scale feature representations.
[0034] EMA achieves richer feature aggregation by establishing interdependencies between channels and spatial positions and adopting a cross-spatial information aggregation method. The outputs of the 1×1 branch and the 3×3 branch are transformed through a 2D global average pooling to encode global spatial information, and then through a joint activation mechanism of channel features, to finally obtain two spatial attention maps. The final output feature map is obtained as an aggregation of two sets of spatial attention weight values through a Sigmoid function.
[0035] Step 2 and 3: Improve the loss function to inner-CIoU to improve the accuracy of prediction boxes of different scales and speed up the convergence of the model;
[0036] In the detection of dangerous goods in X-ray security images, the use of the Inner-IoU loss function can significantly improve the accuracy and speed of bounding box regression, which is crucial for detection accuracy. X-ray security images usually involve complex backgrounds and overlapping objects, and the traditional IoU loss function may cause gradient vanishing or slow convergence in these cases. Inner-IoU optimizes the loss calculation by introducing auxiliary bounding boxes and scaling factors, allowing the model to quickly adjust the predicted box to accurately capture dangerous goods of various sizes. In addition, the implementation of Inner-IoU helps reduce detection errors caused by significant changes in object size, thereby improving the overall efficiency and accuracy of detection.
[0037] Furthermore, in the present invention, in step three, the improved YOLOv8 model is trained using the training set to obtain an X-ray security inspection image detection model;
[0038] Modify the cfg file of YOLOv8, including changing the classes in the yaml file of the data to the number of categories marked in the dataset. Set the hyperparameters of the network model, including the input image size used for training the dataset and testing the model performance, the input data volume per batch, the number of training rounds, and the learning rates lr0 and lrf.
[0039] Furthermore, in the present invention, in step 4, the trained 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. In order to further improve the detection accuracy of dangerous goods blocked by stacked items in luggage, the NMS non-maximum suppression method is used during detection to filter redundant prediction boxes, eliminate overlapping bounding boxes or other types of areas, and obtain location information and category information containing dangerous goods images. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a flow chart of the method for detecting dangerous goods in X-ray security inspection images using improved YOLOv8 in the method of the present invention.
[0041] Figure 2 It is a schematic diagram of the network structure of YOLO-GEMA in the method of the present invention.
[0042] Figure 3 It is a schematic diagram of the principle of RepNCSPELAN4 in the method of the present invention.
[0043] Figure 4 It is a schematic diagram of the principle of EMA in the method of the present invention.
[0044] Figure 5 It is a schematic diagram of the principle of inner-CIoU in the method of the present invention.
[0045] Figure 6 This is a comparison chart of the average accuracy of YOLO-GEMA and YOLOv8 in the method of the present invention.
[0046] Figure 7 It is a training index result diagram of YOLO-GEMA in the method of the present invention on the training set.
[0047] Figure 8 It is a visualization detection result diagram of YOLO-GEMA in the method of the present invention on the test set. DETAILED DESCRIPTION
[0048] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0049] The flowchart of the X-ray security inspection image dangerous goods detection method based on improved YOLOv8 in this specific implementation is as follows: Figure 1 As shown, the YOLO-GEMA network structure is as follows Figure 2 As shown, the following steps are included:
[0050] Step a: Use the PIDray security inspection image dataset and perform format conversion and data enhancement.
[0051] Step a1: In this specific implementation, a public data set PIDray data set is used.
[0052] PIDray dataset: The PIDray dataset contains X-ray security images obtained from personal luggage scans. Dangerous goods in the dataset include: batons, pliers, hammers, power banks, scissors, wrenches, guns, bullets, sprayers, handcuffs, knives, and lighters. The number of each category is as follows: Figure 2 As shown. First, convert the format of the dataset from json format to txt format. The dataset contains a divided training set and test set. The training set uses train and the test set uses easy.
[0053] Table 2 Distribution of the number of categories in the PIDray dataset
[0054] category quantity baton 2399 pliers 6814 hammer 6229 power bank 8116 Scissors 7060 wrench 6437 gun 3757 bullet 2957 sprayer 4227 Handcuffs 3388 knife 5549 lighter 6157
[0055] Step a2: horizontal flipping is performed and the parameter (flip) is set to 0.5, which allows the model to learn the mirror representation of the object and enhance the robustness to direction changes;
[0056] Step a3: Scale Transformation is used for data enhancement, and the parameter (scale) is set to 0.5, which enables the model to adapt to objects of different sizes, which is crucial for detecting the same object at different distances.
[0057] Step b, combined with YOLOv8, introduce GELAN and EMA modules for improvement, update the loss function to inner-CIoU, and build a YOLO-GEMA network;
[0058] Step b1: In the YOLOv8 network, the GELAN network architecture is adopted, and RepNCSP is adopted in any block in the GELAN to form RepNCSPELAN4. This module can enhance the network feature extraction capability and improve the computational efficiency. The schematic diagram of RepNCSPELAN4 is as follows: Figure 3As shown. RepNCSPELAN4 is a key feature extraction and fusion module, which is essential for detecting small or oddly shaped prohibited items that may be missed. It combines convolutional layers and RepNCSP for efficient feature extraction and fusion. Structurally, the RepNCSP component includes convolutional layers and multiple RepNBottleneck modules. These modules leverage the gradient path optimization of CSPNet and the efficient layer aggregation of ELAN. By combining CSPNet and ELAN, RepNCSPELAN4 significantly enhances feature extraction, thereby improving the performance of object detection tasks. The integration of CSPNet ensures an optimized gradient path, facilitating better training and convergence. Its lightweight and fast design makes it suitable for real-time applications, while its modular structure allows scalability to accommodate various model sizes and complexities. The advanced design of RepNCSPELAN4 provides a robust and efficient solution, ensuring high accuracy and fast inference speed.
[0059] Step b2: Add an EMA module in front of the detection head to enhance the recognition capability of overlapping objects.
[0060] The EMA module plays a vital role in improving the efficiency of dangerous goods detection systems in X-ray security images. Its design utilizes channel and spatial attention mechanisms to improve the necessary feature discrimination to accurately and effectively detect prohibited items in X-ray security images. By maintaining the full channel dimension and integrating multi-scale convolutional structures (1×1 and 3×3 convolutions), the EMA module effectively captures detailed and wider spatial features. This ability is critical to distinguishing overlapping dangerous goods that are usually chaotically arranged in baggage in X-ray security images. The parallel substructure of the EMA module enables it to handle items of different sizes in baggage. The multi-scale design allows the module to detect smaller items that may be overlooked, as well as accurately characterize larger items, solving the challenges of multi-scale detection. By integrating an enhanced attention mechanism to focus on areas of interest in the X-ray image, the EMA module reduces the possibility of false alarms and missed detections. The EMA principle is as follows Figure 4 As shown. For any given feature input EMA divides X into G sub-features along the channel dimension to learn different semantics.
[0061] Step b3: Improve the loss function to inner-CIoU to improve the accuracy of prediction boxes of different scales and accelerate the convergence of the model;
[0062] In the detection of dangerous goods in X-ray security images, the use of Inner-IoU loss function can significantly improve the accuracy and speed of bounding box regression, which is critical to detection accuracy. X-ray images often involve complex backgrounds and overlapping items, and in these cases, the traditional IoU loss function may cause gradient vanishing or slow convergence. Inner-IoU optimizes the loss calculation by introducing auxiliary bounding boxes and scaling factors, allowing the model to quickly adjust the predicted box to accurately capture dangerous goods of various sizes. In addition, the implementation of Inner-IoU helps reduce detection errors caused by significant changes in item size, thereby improving the overall efficiency and accuracy of detection.
[0063] exist Figure 5 In the figure, the real box and anchor box are represented as b gt and b, the center point of the real box and the center point of the internal box are and (x c ,y c ). The width and height of the ground-truth box are represented as w gt and h gt , the width and height of the anchor box are denoted as w and h.
[0064] The calculation formula of CIoU is:
[0065]
[0066] Among them, α is a positive trade-off parameter, and its calculation formula is as follows:
[0067]
[0068] v represents the consistency of length and width, and the calculation formula is as follows:
[0069]
[0070] The variable ratio corresponds to the scaling factor, and its value range is [0.5, 1.5]. inner The calculation formula is as follows:
[0071]
[0072]
[0073] union=(w gt *h gt )*(ratio) 2 +(w*h)*(ratio) 2 -inter
[0074]
[0075] The calculation formula of Inner-CIoU is:
[0076] L Inner-CIoU =L CIoU +IoU-IoU inner
[0077] Step c: Use the training set to train the improved YOLOv8 model to obtain the X-ray security inspection image detection model.
[0078] Step c1, set the hyperparameters of the network model, including the input image size of 640×640 for training the data set and testing the model performance, the input data batch size of 32, the number of training epochs of 300, and the learning rate lr of 0.02.
[0079] Step c2: Use the data-enhanced training set to train the improved YOLOv8 model, as shown by three loss curves and three metric curves: Figure 7 As shown in the figure, val / box_loss represents the boundingbox of the validation set. As the number of training rounds increases to 200, its value becomes smaller and smaller and finally stabilizes. val / cls_loss represents the mean loss of the validation set classification. After the number of training rounds reaches 150, the mean loss converges. val / dfl_loss represents the mean loss of the validation set target detection. After the number of training rounds reaches 150, the mean loss tends to be stable.
[0080] Step d: Use the test set to test the X-ray security inspection image detection model.
[0081] Step d1 and Table 3 show the comparison results of the method proposed in the present invention and five different methods of current mainstream target detection algorithms, namely YOLOv4, YOLOv5s, YOLOv7, YOLOv8n, and YOLOv10, on the PIDray dataset.
[0082] Table 3 Comparison of detection accuracy of different detection methods on PIDray dataset
[0083]
[0084] The detection effect of the improved method proposed in this invention on the test set is as follows Figure 8 As shown in the figure, (a) is a normal target image, (b) is an occluded target image, and (c) is an image with a special imaging angle. It can be seen that the improved method can accurately detect dangerous goods targets in luggage.
[0085] Although the present invention is described with reference to specific embodiments, it should be understood that these embodiments are merely examples of the principles and applications of the present invention. It should therefore be understood that many modifications may be made to the exemplary embodiments and that other arrangements may be devised without departing from the spirit and scope of the present invention as defined by the appended claims. It should be understood that the features described in the various dependent claims and the present invention may be combined in a manner different from that described in the original claims. It should also be understood that the features described in conjunction with the individual embodiments may be used in other described embodiments.
Claims
1. An improved YOLOv8 X-ray security image dangerous goods detection system, characterized in that: The following steps are involved: Step 1: Perform data enhancement on the X-ray security inspection image dataset (PIDray); Step 1. Convert the format of the PIDray dataset from json to txt; Step 1 and 2: Use horizontal flipping for data augmentation and set the parameter (flip) to 0.5, which allows the model to learn the mirror representation of the object and enhance the robustness to direction changes; Step 13: Use Scale Transformation for data enhancement and set the parameter (scale) to 0.
5. This allows the model to adapt to objects of different sizes, which is crucial for detecting the same object at different distances. Step 2: Combined with YOLOv8, GELAN (Generalized Efficient Layer Aggregation Network) and EMA (Effcient Multi-Scale Attention) modules are introduced for improvement, the loss function is updated to inner-CIoU, and the YOLO-GEMA network is constructed; Step 21: In Backbone and Neck of YOLOv8, the GELAN network architecture is adopted, and RepNCSP is adopted in any block in GELAN to enhance the network feature extraction capability and improve the computational efficiency; Step 22: Add the EMA module to the Neck of YOLOv8 to enhance the detection capability of overlapping dangerous goods in X-ray security inspection images; Step 2 and 3: Improve the loss function to inner-CIoU to improve the accuracy of prediction boxes of different scales and speed up the convergence of the model; Step 3: Use the training set to train the improved YOLOv8 model to obtain the X-ray security inspection image detection model; Step 4: Use the test set to test the X-ray security image detection model. An improved YOLOv8 X-ray security image dangerous goods detection system, characterized in that: As described in step 1, obtain a dataset of X-ray security inspection images containing dangerous goods, convert the dataset format from json format to txt format, and the dataset contains a divided training set and test set. The training set uses train and the test set uses easy. Use horizontal flipping and set the parameter (flip) to 0.5, which allows the model to learn the mirror representation of the object and enhance the robustness to direction changes; Scale Transformation is used for data enhancement, and the parameter (scale) is set to 0.5, which enables the model to adapt to objects of different sizes, which is crucial for identifying the same object at different distances. An improved YOLOv8 X-ray security image dangerous goods detection system, characterized in that: In step 2, combined with YOLOv8, GELAN (Generalized Efficient Layer Aggregation Network) and EMA (Effcient Multi-Scale Attention) modules are introduced for improvement, the loss function is updated to inner-CIoU, and the YOLO-GEMA network is constructed, specifically: The GELAN network architecture is adopted, and RepNCSP is adopted in any block in GELAN to enhance the network feature extraction capability and improve computational efficiency; RepNCSP is adopted in any block in GELAN to form RepNCSPELAN4, which can enhance the network feature extraction capability and improve computational efficiency; RepNCSPELAN4 is a key feature extraction and fusion module, which is crucial for detecting small or occluded prohibited items that may be missed. It combines convolutional layers and RepNCSP to achieve efficient feature extraction and fusion. Structurally, the RepNCSP component includes convolutional layers and multiple RepNBottleneck modules, which utilize the gradient path optimization of CSPNet and the efficient layer aggregation of ELAN. By combining CSPNet and ELAN, RepNCSPELAN4 significantly enhances feature extraction, thereby improving the performance of object detection tasks. The integration of CSPNet ensures an optimized gradient path, promoting better training and convergence; The EMA (Effcient Multi-Scale Attention) module is added to the Neck of YOLOv8 to enhance the recognition of overlapping objects; the EMA module plays a vital role in improving the efficiency of X-ray dangerous goods detection systems. Its design utilizes channel and spatial attention mechanisms to improve the necessary feature discrimination to accurately and effectively detect dangerous goods in X-ray security images. By maintaining the full channel dimension and integrating multi-scale convolution structures (1×1 and 3×3 convolutions), the EMA module effectively captures detailed and wider spatial features. This ability is crucial for distinguishing overlapping objects in the usually chaotic arrangement of luggage in X-ray security images. The parallel substructure of the EMA module enables it to handle objects of different sizes in luggage. The multi-scale design allows the module to detect smaller objects that may be overlooked, as well as accurately characterize larger objects, solving the challenges of multi-scale detection. By integrating an enhanced attention mechanism to focus on areas of interest in X-ray images, the EMA module reduces the possibility of false positives and missed detections. An improved YOLOv8 X-ray security image dangerous goods detection system, characterized in that: In step 3, the improved YOLOv8 model is trained using the training set to obtain an X-ray security inspection image detection model; An improved YOLOv8 X-ray security inspection image dangerous goods detection system is characterized in that the trained X-ray security inspection image detection model is tested using a test set as described in step 4.
Citation Information
Patent Citations
Dangerous article detection method and system
CN118247563A
Deep neural network-based security check system and method
WO2020187077A1
Cited By
Night traffic scene salient target detection method based on improved YOLOv9
CN119832528A
Complex multi-scale adaptive battery shell defect detection method
CN119963564A
X-ray security check image hazardous article detection system combining multi-scale attention to improve YOLOv8
CN120147968A
Navigation logistics real-time dangerous goods identification system and method
CN120564137A
