Prohibited items detection method for X-ray security inspection images based on improved YOLOv5s
By introducing the heavy parameter module and SE Block into the YOLOv5s algorithm, the problem of low detection efficiency and low accuracy of prohibited items in X-ray security inspection is solved, and more efficient and accurate detection of prohibited items is achieved to meet the needs of practical applications.
Patent Information
- Application Number
- CN202210705367.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-21
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2042-06-21
AI Technical Summary
The existing technology has low efficiency and low accuracy in detecting prohibited items in X-ray security inspections. Especially because X-ray image features are difficult to learn, the detection speed and accuracy fail to meet practical application requirements.
Based on the improved YOLOv5s algorithm, the heavy parameter module (Rep Block) and the compression-excitation module (SE Block) in the path aggregation network are introduced to improve the feature extraction capability and detection accuracy of the backbone network while maintaining real-time performance.
The accuracy and speed of detecting prohibited items in X-ray security inspection images are improved to meet the needs of practical applications. The detection accuracy is higher without affecting the reasoning speed.
Smart Images

Figure CN114897887B
Abstract
Description
Technical Field
[0001] The invention belongs to the field of image detection and relates to a method for detecting prohibited items in X-ray security inspection images based on improved YOLOv5s. Background Art
[0002] X-ray baggage inspection is an important means to maintain public transportation safety. However, the current method in which security inspectors identify X-ray images with the naked eye is inefficient and prone to false detection and missed detection. Therefore, a more efficient and accurate automatic detection method for prohibited items is needed.
[0003] With the rapid development of deep learning in various fields, there have been corresponding attempts in the field of prohibited items identification in X-ray security inspection. At present, automatic identification of prohibited items based on deep learning can be divided into three aspects: automatic classification of prohibited items, automatic detection of prohibited items, and automatic segmentation of prohibited items. At first, convolutional neural networks (CNN) were applied to the automatic classification of prohibited items in X-ray security inspection through transfer learning. Later, generative adversarial network technology was used to expand limited security inspection data sets, thereby improving the recognition accuracy of prohibited items in security inspection. Kim et al. designed an O-Net structure based on U-net to automatically detect prohibited items. Miao et al. proposed a class-balanced hierarchical refinement (CHR) model to solve the problem of class imbalance between positive and negative samples in automatic detection of prohibited items. Xu et al. introduced the attention mechanism in CNN to achieve automatic segmentation of prohibited items in security inspection. Although the automatic identification technology of prohibited items based on deep learning has begun to be studied, due to the difference between X-ray images and natural light images, and the random placement of objects, the target features are not easy to learn under perspective, resulting in the detection speed of prohibited items failing to meet the requirements of practical applications and the detection accuracy still needs to be further improved.
[0004] In recent years, the One-Stage object detection algorithm has received widespread attention due to its simple structure and superior performance. YOLO (You Only Look Once) is a collection of end-to-end object detection algorithms with the characteristics and advantages of fast detection speed. The YOLOv5 algorithm recently open-sourced by the Ultralytics team maximizes the balance between real-time performance and accuracy, and has great application potential in real-time contraband detection.
[0005] YOLOv5s is the smallest network in the YOLOv5 series. This paper takes YOLOv5s as the basic model and proposes an improved method for identifying prohibited items in X-ray security inspection images. While meeting the real-time requirements of automatic detection of prohibited items, the detection accuracy is improved. First, a reparameter block (Rep Block) is designed and introduced in the backbone network of YOLOv5s. A parallel 1×1 convolution branch is constructed at the 3×3 convolution to assist the backbone network in extracting richer features during the training phase. The 1×1 branch is integrated into the 3×3 branch during the inference phase, which improves the detection accuracy without affecting the inference speed. Secondly, two squeeze and excitation blocks (Squeeze and Excitation Block, SE Block) are inserted into the path aggregation network (PAN) at the neck of YOLOv5s, which improves the detection effect of the algorithm on prohibited items without affecting the inference speed. Summary of the invention
[0006] In view of this, the object of the present invention is to provide a method for detecting prohibited items in X-ray security inspection images based on improved YOLOv5s.
[0007] In order to achieve the above object, the present invention provides the following technical solutions:
[0008] A method for detecting prohibited items in X-ray security inspection images based on improved YOLOv5s includes the following steps:
[0009] S1: Establish the Rep module based on the heavy parameter design idea;
[0010] S2: Establish a heavy parameter based YOLOv5s prohibited items detection algorithm;
[0011] S3: Improve the neck PAN.
[0012] Optionally, the S1 is specifically:
[0013] Assume that the parameters of the constructed Rep module are as shown in formula (1), that is, two parallel convolution branches are added; the information flow generated by the Rep module is expressed as y = f(x) + g(x), where f(x) and g(x) are the convolution branches implemented by the 3×3 kernel and the 1×1 kernel respectively;
[0014] Rep(3×3)=3×3-BN+1×1-BN (1)
[0015] For each 3×3 convolution, a parallel 1×1 convolution branch is constructed in the training stage, and each is normalized and then added together; in the inference stage, the 1×1 branch is merged into the 3×3 branch to obtain a 3×3 convolution branch, and the other parallel branch structure is subtracted to improve the performance of the convolutional network without affecting the network detection efficiency;
[0016] Based on the Rep module construction, the multi-branch module is converted into a single branch based on the idea of RepVGG; the model conversion is performed after the training is completed, which includes the following two steps:
[0017] ① First, fuse the convolution layer and BN layer in each branch; directly bring the convolution result into the BN formula, such as Figure 3 The left arrow in the figure shows the output as formula (2):
[0018] M (2) =bn(W (3) *M (1) ,μ (3) ,σ (3) ,γ (3) ,β (3) )+bn(W (1) *M (1) ,μ (1) ,σ (1) ,γ (1) ,β (1) ) (2)
[0019] in, and They represent the convolution kernels of 3×3 and 1×1 convolution layers, respectively. C1 and C2 represent the number of input and output channels. (3) ,σ (3) ,γ (3) ,β (3) They represent the cumulative mean, standard deviation, scaling factor, and bias term of the BN layer after the 3×3 convolution, μ (1) ,σ (1) ,γ (1) ,β (1) The cumulative mean, standard deviation, scaling factor and bias term of the BN layer after the 1×1 convolution; the input and output are expressed as * represents convolution operation;
[0020] Substituting the parameters into formula (2), we get the result as shown in formula (3); where bn is the batch normalization function in the inference phase, i∈[1,C2];
[0021]
[0022] Simplifying formula (3) yields a convolutional layer with a bias term. The convolution kernel and bias term obtained after the transformation of {W,b,μ,σ,γ,β} are expressed in the form of {W',b'}, and we have:
[0023]
[0024] For any i∈[1,C2], we have bn(W*M,μ,σ,γ,β) :,i,:,: =(W'*M) :,i,:,: b′ i ; After the fusion is completed, a 3×3 convolution kernel, a 1×1 convolution kernel and two bias terms are obtained;
[0025] ② Fuse the 3×3 convolution and 1×1 convolution, add the two deviation terms to get the fused deviation term; fill the 1×1 convolution kernel with 0 to get the 3×3 convolution kernel, and then add it to the original 3×3 convolution kernel to get the fused convolution kernel; suppose are two convolution kernels. According to the additivity principle of convolution, their addition result is expressed as formula (5). After the convolution kernel is fused, the function before fusion is realized.
[0026]
[0027] Optionally, S2 specifically includes: introducing the Rep structure into the backbone network of the YOLOv5s algorithm to obtain an upgraded backbone network consisting of a series of Rep modules and C3 modules; adjusting the PAN structure, inserting the SE module between the previous detection layer and the next detection layer in the PAN to obtain an upgraded PAN network;
[0028] The Focus module slices the image to expand its input channels by 4 times, that is, the image after the operation changes from the original RGB three channels to 12 channels; after the convolution operation, a double downsampled feature map with no information loss is obtained; the Conv module encapsulates the convolution layer, BN layer and SiLU activation function; the structure and function of the C3 module are basically the same as those of BottleneckCSP, but its floating-point operation number is lower and the running speed is faster; the SPP module splices the maximum pooling results of different sizes to achieve the fusion of local features and global features; UpSample is the upsampling layer, and its interpolation method enlarges the image to twice its original size; the three Conv[1,1] in the detection head obtain the final output feature map.
[0029] Optionally, the S3 is specifically:
[0030] The SE module consists of two parts: compression and excitation. The first step is the compression stage, in which a global average pooling is performed to compress the input W×H×C feature map into 1×1×C. This compressed feature map has a global receptive field. The second step is the excitation stage, which consists of two fully connected layers: the first fully connected layer has C×r neurons, and the second fully connected layer has C neurons, where r is a scaling parameter. Adjusting this parameter reduces the number of channels and thus reduces the amount of computation.
[0031] Optionally, after S4, the step further includes setting evaluation indicators;
[0032] The detection performance evaluation of the detector needs to consider both the accuracy Precision and the recall Recall; in target detection, the average precision mAP, macro accuracy MP, macro recall MR and macro F1 when IoU = 0.5 are used to evaluate the performance of the network model; the accuracy is defined as formula (6), and the recall is defined as formula (7); where TP, TN, FP and FN represent true positive, true negative, false positive and false negative respectively;
[0033]
[0034]
[0035] The average precision (AP) is obtained by combining the accuracy and recall rate, and is used to evaluate the accuracy of the model in detecting a single category. mAP measures the accuracy of the model in detecting all categories, and is obtained by calculating the average AP value of all categories. Its definition is as shown in formula (8). The F1 score is the weighted average of the accuracy and recall rate, and is defined as shown in formula (9). The larger the value, the better the effect.
[0036]
[0037]
[0038] Macro precision, macro recall, and macro F1 are obtained by averaging the precision, recall, and F1 scores of all categories, respectively.
[0039] The beneficial effect of the present invention is that: the present invention uses YOLOv5s as the basic model and proposes an improved method for identifying prohibited items in X-ray security inspection images. While meeting the real-time requirements of automatic detection of prohibited items, the detection accuracy is improved. First, a heavy parameter module Rep Block is designed and introduced into the YOLOv5s backbone network. A parallel 1×1 convolution branch is constructed at the 3×3 convolution to assist the backbone network in extracting richer features during the training phase. The 1×1 branch is integrated into the 3×3 branch during the reasoning phase, thereby improving the detection accuracy without affecting the reasoning speed. Secondly, two SE Blocks are inserted into the YOLOv5s neck PAN to improve the algorithm's detection effect on prohibited items without affecting the reasoning speed.
[0040] Compared with the traditional detection method, the present invention has higher detection accuracy and can better meet the practical application needs of detecting prohibited items in X-ray security inspection images.
[0041] Other advantages, objectives and features of the present invention will be described in the following description to some extent, and to some extent, will be obvious to those skilled in the art based on the following examination and study, or can be taught from the practice of the present invention. The objectives and other advantages of the present invention can be realized and obtained through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention will be described in detail below in conjunction with the accompanying drawings, wherein:
[0043] Figure 1 This is the YOLOv5s network structure diagram;
[0044] Figure 2 This is the structure diagram of the improved YOLOv5s network model;
[0045] Figure 3 for the Rep Block structure and its structural reparameterization process;
[0046] Figure 4 The fused convolution kernel is obtained by adding the ordinary 3×3 convolution kernel to the padded convolution kernel;
[0047] Figure 5 The use of SE module in convolutional layer. (a) Ordinary convolution. (b) Convolution after inserting SE module;
[0048] Figure 6 It is the confusion matrix corresponding to various prohibited items under different algorithms. DETAILED DESCRIPTION
[0049] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments only illustrate the basic concept of the present invention in a schematic manner, and the following embodiments and features in the embodiments can be combined with each other without conflict.
[0050] Among them, the drawings are only used for illustrative explanations, and they only represent schematic diagrams rather than actual pictures, and should not be understood as limitations on the present invention. In order to better illustrate the embodiments of the present invention, some parts of the drawings may be omitted, enlarged or reduced, and do not represent the size of actual products. For those skilled in the art, it is understandable that some well-known structures and their descriptions in the drawings may be omitted.
[0051] The same or similar numbers in the drawings of the embodiments of the present invention correspond to the same or similar parts; in the description of the present invention, it should be understood that if the terms "upper", "lower", "left", "right", "front", "rear", etc. indicate the orientation or position relationship, they are based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation. Therefore, the terms describing the position relationship in the drawings are only used for illustrative purposes and cannot be understood as limiting the present invention. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to specific circumstances.
[0052] 1. X-ray security inspection image dataset
[0053] X-rays have shown their powerful capabilities in security inspection tasks, but there are still few X-ray prohibited items image datasets available for research. GDXray contains 19,407 images, but only a few images (600) contain three categories of prohibited items: guns, darts, and razor blades, and all images are grayscale images with simple backgrounds, which are quite different from complex real-life scenes. OPIXray contains 8,885 X-ray prohibited items images with different overlap levels and proportions, but only contains one category of prohibited items (knives of different shapes). SIXray consists of 8,929 images of prohibited items with multiple categories. The image background is relatively complex, and dangerous goods are randomly stacked with occlusion, which is more in line with the actual situation, so the present invention selects SIXray as the experimental dataset.
[0054] 2.YOLOv5s algorithm
[0055] The YOLOv5s algorithm consists of four parts: input, backbone network, neck and detection head, such as Figure 1 As shown. The input end uses the Mosaic data enhancement method, adaptive bounding box calculation and scaled image to enrich the diversity of input data. The backbone network uses the Focus and CSP modules, among which the CSP structure is conducive to improving the network feature learning ability. The neck adopts the Feature Pyramid Networks (FPN) plus PAN structure. FPN enhances semantic propagation by upsampling, and PAN uses downsampling to enhance feature positioning. The detection head uses the Generalized Intersection over Union (GIoU) loss as the loss function of the bounding box, and uses Non Maximum Suppression (NMS) to select the border.
[0056] The present invention improves the backbone network and the neck PAN structure of the YOLOv5s algorithm respectively to generate a new network and improve the detection performance.
[0057] 3. YOLOv5s Prohibited Items Detection Algorithm Based on Heavy Parameters
[0058] The present invention improves the detection accuracy of the algorithm for prohibited items in security inspection by improving the YOLOv5s network structure, and improves the feature extraction ability of the backbone network by designing the Rep module without affecting the reasoning time; two SE modules are introduced in the neck PAN, so that the network can extract more feature information. The improved network structure is as follows Figure 2 shown.
[0059] In the problem of prohibited items detection, YOLOv5s was improved in two parts: ① The Rep structure was introduced into the backbone network of the YOLOv5s algorithm, and an upgraded backbone network consisting of a series of Rep modules and C3 modules was obtained; ② The PAN structure was further adjusted, and the SE module was inserted between the previous detection layer and the next detection layer in the PAN to obtain an upgraded PAN network. The new algorithm can not only enrich the characteristics of its backbone network, improve model performance, and enhance detection results; it can also enhance information extraction of its neck PAN, and the impact on reasoning time is negligible. The improved algorithm structure is as follows Figure 3As shown. The Focus module slices the image to expand its input channels by 4 times, that is, the image after the operation changes from the original RGB three channels to 12 channels; further through the convolution operation, a double downsampled feature map with no information loss is obtained. The Conv module encapsulates the convolution layer, BN layer and SiLU activation function. The structure and function of the C3 module are basically the same as BottleneckCSP, but its floating-point operation number is lower and the running speed is faster. The SPP module splices the maximum pooling results of different sizes to achieve the fusion of local features and global features. UpSample is an upsampling layer, and its interpolation method enlarges the image to twice its original size. The three Conv[1,1] in the detection head obtain the final output feature map.
[0060] 3.1 Rep module designed based on the idea of heavy parameters
[0061] In order to extract richer network features and improve network detection performance, researchers have designed many novel multi-branch structures. Novel components can certainly improve accuracy, but the problem brought by the multi-branch structure is that it is difficult to apply and customize, increases video memory consumption, and is not conducive to the reasoning process. Therefore, the present invention uses the re-parameterization idea to design the Rep module to improve the model accuracy, and reduces the impact on the reasoning speed by decoupling its training phase and testing phase. Assume that the parameters of the constructed Rep module are as shown in formula (1), that is, two parallel convolution branches are added. The information flow generated by the Rep module is expressed as y=f(x)+g(x), where f(x) and g(x) are convolution branches implemented by 3×3 kernel and 1×1 kernel respectively.
[0062] Rep(3×3)=3×3-BN+1×1-BN (1)
[0063] like Figure 3 As shown in the figure, for each 3×3 convolution, a parallel 1×1 convolution branch is constructed in the training stage, and each is normalized and added together. In the inference stage, the 1×1 branch is fused into the 3×3 branch to obtain a 3×3 convolution branch, minus the other parallel branch structure, thereby improving the performance of the convolutional network without affecting the network detection efficiency.
[0064] Based on the Rep module construction, we can further convert the multi-branch module into a single branch based on the RepVGG idea. The model conversion (i.e. multi-branch fusion) is performed after the training is completed, which includes the following two steps:
[0065] (1) First, fuse the convolution layer and BN layer in each branch. Directly bring the convolution result into the BN formula, such as Figure 3 The left arrow in the figure, the output can be expressed as formula (2):
[0066] M(2) =bn(W (3) *M (1) ,μ (3) ,σ (3) ,γ (3) ,β (3) )+bn(W (1) *M (1) ,μ (1) ,σ (1) ,γ (1) ,β (1) ) (2)
[0067] in, and They represent the convolution kernels of 3×3 and 1×1 convolution layers respectively, C1 and C2 represent the number of input and output channels. (3) ,σ (3) ,γ (3) ,β (3) They represent the cumulative mean, standard deviation, scaling factor, and bias term of the BN layer after the 3×3 convolution, μ (1) ,σ (1) ,γ (1) ,β (1) The cumulative mean, standard deviation, scaling factor, and bias term of the BN layer after the 1×1 convolution. The input and output are expressed as * represents the convolution operation.
[0068] Substituting the parameters into formula (2), we get the result as shown in formula (3). Where bn is the batch normalization function in the inference phase, i∈[1,C2].
[0069]
[0070] Formula (3) is further simplified to obtain a convolution layer with a bias term. The convolution kernel and bias term obtained after the transformation of {W,b,μ,σ,γ,β} are expressed in the form of {W',b'}, then:
[0071]
[0072] From this, we can verify that for any i∈[1,C2], there is bn(W*M,μ,σ,γ,β) :,i,:,: =(W'*M) :,i,:,: b′ i Therefore, after the fusion is completed, we can get a 3×3 convolution kernel, a 1×1 convolution kernel and two bias terms.
[0073] (2) Fuse the 3×3 convolution and 1×1 convolution, that is, Figure 3The two deviation terms are added to get the fused deviation term; the 1×1 convolution kernel is filled with 0 to get a 3×3 convolution kernel, and then added to the original 3×3 convolution kernel to get the fused convolution kernel, as shown in Figure 4 As shown. are two convolution kernels. According to the additivity principle of convolution, their addition result can be expressed as formula (5). Therefore, after the convolution kernel is fused, the same function can be achieved as before the fusion.
[0074]
[0075] 3.2 Improvement of Neck PAN
[0076] The present invention improves the model performance by loading the SE module in the PAN of YOLOv5s. The SE module models the correlation between feature channels, selects the attention for the channel, and strengthens the important features to improve the accuracy.
[0077] like Figure 5 As shown in the figure, the SE module mainly consists of two parts: compression and excitation. The first step is the compression stage. Through a global average pooling, the input W×H×C feature map is compressed to 1×1×C. This compressed feature map has a global receptive field. The second step is the excitation stage, which consists of two fully connected layers: the first fully connected layer has C×r neurons, and the second fully connected layer has C neurons, where r is a scaling parameter. Adjusting this parameter can reduce the number of channels and thus reduce the amount of calculation.
[0078] 4 Experiments and results analysis
[0079] 4.1 Dataset
[0080] The algorithm proposed in the present invention is experimented on the public dataset SIXray, which collects 8929 annotated images. Compared with other datasets, SIXray has more categories and a relatively large amount of data. The dataset is randomly divided into two parts, 20% of the images (1781 images) are test sets, and the rest (7148 images) are training sets, with a ratio of about 1:4. The present invention removes the detection of scissors in the experiment because the number of samples is too small and the amount of data between classes is unbalanced. The detailed distribution of each category in the dataset is shown in Table 1. In addition, many images in the dataset contain multiple objects.
[0081] Table 1. Distribution of each category in the SIXray dataset.
[0082]
[0083] Many images contain more than one prohibited item, so the total number of items is much higher than the number of images.
[0084] 4.2 Evaluation Metrics
[0085] The detection performance evaluation of the detector needs to consider both the accuracy (Precision) and the recall (Recall). In target detection, the mean average precision (mAP), macro accuracy (MP), macro recall (MR) and macro F1 (MF1) at IoU = 0.5 are used to evaluate the performance of the network model. The accuracy is defined as formula (6) and the recall is defined as formula (7). TP, TN, FP and FN represent true positive, true negative, false positive and false negative respectively.
[0086]
[0087]
[0088] Average Precision (AP) is obtained by combining precision and recall to evaluate the accuracy of the model in detecting a single category. mAP measures the accuracy of the model in detecting all categories and is obtained by calculating the average AP value of all categories. Its definition is as shown in formula (8). The F1 score is the weighted average of precision and recall, as defined in formula (9). The larger its value, the better the effect.
[0089]
[0090]
[0091] Similar to macro accuracy, macro precision, macro recall, and macro F1 are obtained by averaging the accuracy, recall, and F1 scores of all categories, respectively. In addition, the confusion matrix can also be used to assist in the analysis of the results.
[0092] 4.3 Experimental Results Analysis
[0093] The hardware configuration of the experiment is Core(TM) i9-10920X processor, GeForce RTX 3090 graphics card, and the software configuration is torch1.8.0. During the training process, SGD with momentum is used to optimize the network parameters, and the number of epochs is set to 200. The input image size is 640×640, and the batch size is 64. Experiments are conducted on multiple models while keeping other parameters consistent.
[0094] The present invention shows the experimental results of four models in total: the original YOLOv5s algorithm, the backbone network algorithm of the improved YOLOv5s using the Rep module (hereinafter referred to as Rep-YOLOv5), the improved algorithm inserting the SE module in the neck PAN (hereinafter referred to as SE-YOLOv5), and the algorithm of two improved superpositions (hereinafter referred to as RepSE-YOLOv5s).
[0095] Figure 6 The confusion matrices of different algorithms are listed, where the diagonal values represent the true positive rate (TPR), and the sum of the off-diagonal values in each column represents the false negative rate (FNR) of a class. As can be seen from the figure, the diagonal response of the confusion matrix of the RepSE-YOLOv5s algorithm is higher than the average value of the other matrices, and the better overall distribution of the confusion matrix indicates that the algorithm of the present invention can identify prohibited items more accurately.
[0096] In contrast, the algorithm has the greatest improvement in detecting wrenches. But in general, knives have the lowest true positive rate. This may be because the specific features of knives in the dataset are not single. For example, the knife category includes wide kitchen knives, slender straight knives, and small utility knives.
[0097] Table 2 shows the overall performance comparison of the four algorithms on the SIXray dataset. First, the original YOLOv5s algorithm is compared with the Rep-YOLOv5s algorithm. The data in the table shows that the macro accuracy (mAP) of the Rep-YOLOv5s algorithm is 1.1% higher than that of the original network. The other three evaluation indicators are also improved, and the detection accuracy of each category is also improved. This shows that the Rep module enhances the feature extraction ability of the backbone network and has a significant help in improving the detection performance of the algorithm. Then, by comparing the original YOLOv5s algorithm with the SE-YOLOv5s algorithm, it can be seen that the improvement of the SE module on the network's enhanced feature extraction part also improves the overall detection performance of the algorithm, especially in terms of the macro recall rate (MR), which is improved by 2.5%.
[0098] Finally, the improved RepSE-YOLOv5s algorithm with two parts is 2.6%, 1.0%, and 1.4% higher than the original YOLOv5s, Rep-YOLOv5s, and SE-YOLOv5s in terms of mAP indicators. It also has more significant advantages over the original network and the other two networks in terms of macro accuracy (mAP), macro recall (MR), and macro F1 (MF1). In addition, the table also shows that the detection accuracy of each category has been improved, especially for wrenches, the detection accuracy has increased from 86.4% to 91.3%, an increase of 4.9 percentage points. These evaluations show that the RepSE-YOLOv5s algorithm can more accurately detect all categories of prohibited items in X-ray security images, and has the potential to be further applied in practical scenarios.
[0099] Table 2 Performance comparison of detection algorithms
[0100]
[0101] In addition, the present invention also compares the number of parameters (hundred thousand, M), model size (megabyte, MB) and time required to detect a single image (millisecond, ms) of the original YOLOv5s algorithm, Rep-YOLOv5s algorithm, SE-YOLOv5s algorithm, and RepSE-YOLOv5s algorithm, as shown in Table 3. The time required to detect a single image is the result of testing the data in the test set on a GPU, including data preprocessing, model reasoning, post-processing, and non-maximum suppression (NMS). The average preprocessing time is 0.1ms and the average NMS time is 0.8 milliseconds per image.
[0102] As can be seen from Table 3, the number of parameters of the RepSE-YOLOv5s algorithm has only increased by 0.28%, the model size has increased by 2.82% (0.4MB), and the detection time has remained almost unchanged.
[0103] Table 3 Comparison of time used by different algorithms
[0104]
[0105] The improved algorithm improves the detection effect of some objects that are difficult to identify against complex backgrounds.
[0106] Aiming at the problem that the detection accuracy of X-ray security inspection images is not high enough, this paper applies the YOLOv5s algorithm with small model and fast detection speed to the detection of prohibited items in X-ray security inspection images, and proposes a RepSE-YOLOv5s detection algorithm, which improves the detection accuracy while the impact on the detection speed can be ignored. Firstly, a Rep module is designed by using the heavy parameter idea to enrich the characteristics of the YOLOv5s algorithm backbone network, and then two SE modules are inserted into the YOLOv5s algorithm neck PAN to improve the detection effect of the algorithm on prohibited items. Finally, experiments are carried out on the SIXray dataset, and the prohibited item detection performance of four different algorithm models is compared and analyzed. The results show that the average precision mean, macro accuracy, macro recall and macro F1 of the new algorithm are improved by 2.6%, 2.0%, 4.0% and 3.0% respectively compared with the original algorithm, while the detection speed is kept at 2.6 milliseconds per image, which improves the accuracy of prohibited item detection without adding extra detection time.
[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution, which should be included in the scope of the claims of the present invention.
Claims
1. A method for detecting prohibited items in X-ray security inspection images based on improved YOLOv5s, characterized by: The method comprises the following steps: S1: Establish the Rep module based on the heavy parameter design idea; S2: Establish a heavy parameter based YOLOv5s prohibited items detection algorithm; S3: Improve the neck PAN in the YOLOv5s prohibited items detection algorithm; S4: Use the improved YOLOv5s prohibited items detection algorithm to detect prohibited items; The S1 is specifically: Assume that the parameters of the constructed Rep module are as shown in formula (1), that is, two parallel convolution branches are added; the information flow generated by the Rep module is expressed as y = f(x) + g(x), where f(x) and g(x) are the convolution branches implemented by the 3×3 kernel and the 1×1 kernel respectively; Rep(3×3)=3×3-BN+1×1-BN (1) For each 3×3 convolution, a parallel 1×1 convolution branch is constructed in the training phase, and each is normalized and then added together; in the inference phase, the 1×1 branch is fused into the 3×3 branch to obtain a 3×3 convolution branch, minus another parallel branch structure; Based on the Rep module construction, the multi-branch module is converted into a single branch based on the idea of RepVGG; the model conversion is performed after the training is completed, which includes the following two steps: ① First, fuse the convolution layer and BN layer in each branch; directly bring the convolution result into the BN formula, and the output is expressed as formula (2): in, and They represent the convolution kernels of 3×3 and 1×1 convolution layers, respectively. C1 and C2 represent the number of input and output channels. (3) ,σ (3) ,γ (3) ,β (3) They represent the cumulative mean, standard deviation, scaling factor, and bias term of the BN layer after the 3×3 convolution, μ (1) ,σ (1) ,γ (1) ,β (1) The cumulative mean, standard deviation, scaling factor and bias term of the BN layer after the 1×1 convolution; the input and output are expressed as * represents convolution operation; Substituting the parameters into formula (2), we get the result as shown in formula (3); where bn is the batch normalization function in the inference phase, i∈[1,C2]; Simplifying formula (3) yields a convolutional layer with a bias term. The convolution kernel and bias term obtained after the transformation of {W,b,μ,σ,γ,β} are expressed in the form of {W',b'}, and we have: For any i∈[1,C2], we have bn(W*M,μ,σ,γ,β) :,i,:,: =(W'*M) :,i,:,: b′ i ; After the fusion is completed, a 3×3 convolution kernel, a 1×1 convolution kernel and two bias terms are obtained; ② Fuse the 3×3 convolution and 1×1 convolution, add the two deviation terms to get the fused deviation term; fill the 1×1 convolution kernel with 0 to get the 3×3 convolution kernel, and then add it to the original 3×3 convolution kernel to get the fused convolution kernel; suppose are two convolution kernels. According to the additivity principle of convolution, their addition result is expressed as formula (5). After the convolution kernel is fused, the function before fusion is realized. Conv(x,W1 (3) )+Conv(x,W2 (3) )=Conv(x,W1 (3) +W2 (3) ) (5) Specifically, S2 includes: introducing the Rep structure into the backbone network of the YOLOv5s algorithm to obtain an upgraded backbone network consisting of a series of Rep modules and C3 modules; The S3 specifically includes: adjusting the PAN structure, inserting the SE module between the upper detection layer and the lower detection layer in the PAN, and obtaining an upgraded PAN network; The Focus module slices the image to expand its input channels by 4 times, that is, the image after the operation changes from the original RGB three channels to 12 channels; after the convolution operation, a double downsampled feature map with no information loss is obtained; the Conv module encapsulates the convolution layer, BN layer and SiLU activation function; the SPP module splices the maximum pooling results of different sizes to achieve the fusion of local features and global features; UpSample is the upsampling layer, and its interpolation method enlarges the image to twice its original size; the three Conv[1,1] in the detection head obtain the final output feature map.
2. The method for detecting prohibited items in X-ray security inspection images based on improved YOLOv5s according to claim 1, characterized in that: The SE module consists of two parts: compression and excitation. The first step is the compression stage, in which a global average pooling is performed to compress the input W×H×C feature map into 1×1×C. The compressed feature map has a global receptive field. The second step is the excitation stage, which consists of two fully connected layers: the first fully connected layer has C×r neurons, and the second fully connected layer has C neurons, where r is a scaling parameter. Adjusting this parameter reduces the number of channels and thus reduces the amount of computation.
3. The method for detecting prohibited items in X-ray security inspection images based on improved YOLOv5s according to claim 2, characterized in that: After S4, the evaluation index is also set; The detection performance evaluation of the detector needs to consider both the accuracy Precision and the recall Recall; in target detection, the average precision mAP, macro accuracy MP, macro recall MR and macro F1 when IoU = 0.5 are used to evaluate the performance of the network model; the accuracy is defined as formula (6), and the recall is defined as formula (7); where TP, TN, FP, and FN represent true positive, true negative, false positive, and false negative, respectively; The average precision AP is obtained by combining the accuracy and recall rate, and is used to evaluate the accuracy of the model in detecting a single category; mAP is the accuracy of the model in detecting all categories, which is obtained by calculating the average AP value of all categories. Its definition is as shown in formula (8). F1 score is the weighted average of precision and recall, which is defined as formula (9). The larger its value, the better the effect. Macro precision, macro recall, and macro F1 are obtained by averaging the precision, recall, and F1 scores of all categories, respectively.
