Training method for image detection model of security inspection machine

Through the improved YOLO model and loss function training method, the problem of large detection errors of multi-sized targets in the image detection model is solved, the detection accuracy and precision are improved, and the recognition ability of targets of different sizes is enhanced.

CN118762166APending Publication Date: 2024-10-11BEIJING HANGXING MACHINERY MFG CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410898219.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-05
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

Existing image detection models have large errors and low accuracy when detecting multi-sized targets, especially the detection of small targets, resulting in low detection accuracy and poor generalization ability.

Method used

The improved YOLO model is used to sample the feature maps through the dynamic upsampling method of point sampling, and the feature maps are spliced ​​and fused in a weighted manner. The model is trained by combining the category loss function and the regression loss function to increase the features in the neck network. Fusion and detection head prediction results improve the model's detection capabilities for multi-sized targets.

Benefits of technology

It achieves clearer edges and high-quality upsampling, reduces the interference of redundant features, improves the detection accuracy and precision of multi-sized targets, and enhances the ability to identify targets of different sizes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118762166A_ABST
    Figure CN118762166A_ABST
Patent Text Reader

Abstract

The invention relates to a training method of an image detection model for a security inspection machine, belongs to the technical field of image detection, and solves the problems of large error and low accuracy when an image detection model detects multi-size target images in the prior art. The training method comprises the steps that each historical image is labeled through an image labeling tool, and historical image data and labeling information form a data set; an image detection model is constructed, the image detection model is an improved YOLO model, a neck network in the improved YOLO model adopts a point sampling dynamic upsampling method to sample the input feature maps, and meanwhile, a weighting mode is adopted to splice and fuse the input feature maps; and training the image detection model by using the training set in each training round, and verifying the training effect by using the verification set to obtain the optimal image detection model. And the accuracy of multi-size target detection by the trained image detection model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image detection, and in particular to a training method for an image detection model used in a security inspection machine. Background Art

[0002] With the rapid growth in the number of travelers and express delivery items, security inspection plays an increasingly important role in ensuring public safety. Security inspections usually rely on X-rays for perspective scanning, and after imaging, security inspectors determine whether there are prohibited items. When working, security inspectors need to stay focused to avoid missing prohibited items, which would cause irreparable harm to public safety. However, this state of concentration cannot be maintained for a long time, and frequent shift changes will also lead to a large consumption of human resources. Therefore, people are in urgent need of accurate, automatic and efficient prohibited item detection technology to improve the work efficiency of security inspectors and ensure public safety.

[0003] The success of machine learning methods in various fields has encouraged researchers to apply them to the task of detecting contraband in security inspection images. Currently, the trained image detection models in the existing technology mainly focus on the detection of large objects, especially knives and sticks, but ignore the detection of multi-sized objects, especially the detection of small objects such as lighters. As a result, when detecting image objects, it is impossible to simultaneously take into account objects of multiple sizes, and generally has problems such as low detection accuracy and poor generalization ability.

[0004] Therefore, there is an urgent need for a technical solution for model training to detect multi-size objects. Summary of the invention

[0005] In view of the above analysis, an embodiment of the present invention aims to provide a training method for an image detection model for a security inspection machine, so as to solve the problem of large error and low accuracy of the image detection model in the prior art when detecting multi-size target images.

[0006] An embodiment of the present invention provides a training method for an image detection model of a security inspection machine, the training method comprising:

[0007] Acquire historical image data stored in the security inspection machine, pre-process the historical image data to obtain historical image data in a predetermined format, annotate each historical image using an image annotation tool, and the historical image data and annotation information form a data set;

[0008] Constructing an image detection model, wherein the image detection model is an improved YOLO model, in which the neck network uses a point sampling dynamic upsampling method to sample the input feature map, and simultaneously uses a weighted method to splice and fuse the input feature map;

[0009] The data set is divided into a training set, a validation set, and a test set, and the training rounds are determined; in each training round, the training set is used to train the image detection model, and the validation set is used to verify the training effect to obtain the optimal image detection model; the test set is used to test the optimal image detection model to obtain a trained image detection model.

[0010] Based on the further improvement of the above method, the step of annotating each historical image by using an image annotation tool includes:

[0011] Use the image annotation tool LabelImg to mark the location of the target in the image using a standard bounding box and mark the target category;

[0012] The annotation information includes the center coordinates, length, width and category of the bounding box.

[0013] Based on the further improvement of the above method, the loss function of the image detection model includes a category loss function and a regression loss function, and the category loss function adopts a cross entropy loss function;

[0014] The regression loss function is:

[0015] L Shape-IoU =1-IoU+distance shape +0.5×Ω shape ;

[0016]

[0017]

[0018]

[0019]

[0020]

[0021]

[0022]

[0023] Among them, L Shape-IoU represents the bounding box loss, B represents the predicted area of ​​the bounding box, and B gt represents the real area of ​​the bounding box, x c ,y c Represents the predicted center coordinates of the bounding box, represents the true center coordinates of the bounding box, w and h represent the predicted length and width of the bounding box, w gt 、h gtrepresents the actual length and width of the bounding box, scale represents the scale factor, θ represents the shape factor, and C represents the diagonal length of the minimum bounding box that can simultaneously enclose the predicted area and the real area of ​​the bounding box.

[0024] Based on the further improvement of the above method, the preprocessing includes one or more of the following operations:

[0025] Image enhancement operations;

[0026] Image denoising operation;

[0027] Image augmentation operations.

[0028] Based on the further improvement of the above method, the image detection model includes:

[0029] The backbone network is used to receive historical training images, extract and enhance features of the historical training images, and continuously reduce the size of feature maps to obtain first feature maps, second feature maps, third feature maps, and fourth feature maps from shallow to deep layers;

[0030] The neck network fuses and enhances features according to the input first feature map, second feature map, third feature map and fourth feature map to obtain first to fourth fused feature maps;

[0031] The detection head is used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the historical training image according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map.

[0032] Based on the further improvement of the above method, the neck network includes:

[0033] A first sampling and fusion layer is used to perform a point sampling operation on the fourth feature map, concatenate and fuse the sampled feature map with the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first intermediate feature map;

[0034] The second sampling and fusion layer is used to perform a point sampling operation on the first intermediate feature map, concatenate and fuse the sampled feature map with the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second intermediate feature map;

[0035] The third sampling and fusion layer is used to perform a point sampling operation on the second intermediate feature map, concatenate and fuse the sampled feature map with the first feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first fused feature map;

[0036] The first convolution fusion layer is used to perform a convolution operation on the first fused feature map, concatenate and fuse the feature map after the convolution, the second intermediate feature map, and the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second fused feature map;

[0037] The second convolution fusion layer is used to perform a convolution operation on the second fused feature map, concatenate and fuse the feature map after the convolution, the first intermediate feature map, and the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a third fused feature map;

[0038] The third convolution fusion layer is used to perform a convolution operation on the third fused feature map, concatenate and fuse the feature map after the convolution operation with the fourth feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a fourth fused feature map.

[0039] Based on the further improvement of the above method, the first sampling fusion layer, the second sampling fusion layer and the third sampling fusion layer all include a point sampling layer, a first splicing fusion layer and a residual convolution layer connected in sequence;

[0040] The first convolutional fusion layer, the second convolutional fusion layer and the third convolutional fusion layer all include a convolutional layer, a second splicing fusion layer and a residual convolutional layer connected in sequence.

[0041] Based on the further improvement of the above method, the point sampling layer is used to change the size of the input feature map according to the scaling factor of the feature, including:

[0042] The input feature map is divided into g groups according to the number of channels of the input feature map, each group of input feature maps includes the same number of channels, and the coordinates of each group of input feature maps are normalized;

[0043] Perform convolution operation on the input feature map H*W*C to change the number of channels of the input feature map to obtain the feature map H*W*(2*s*s*g), further deform the feature map H*W*(2*s*s*g) to obtain the feature map sH*sW*2g, and normalize the elements of the feature map sH*sW*2g. The normalized feature map sH*sW*2g is used as the offset coordinate map of the output feature map; where s is the scaling factor of the feature;

[0044] According to the normalized input feature map of each set of coordinates and the corresponding offset coordinate map, the output feature map corresponding to each set is determined, and the output feature maps corresponding to g sets are combined to obtain the sampled feature map.

[0045] Based on the further improvement of the above method, the step of determining each group of corresponding output feature maps according to the normalized input feature map of each group of coordinates and the corresponding offset coordinate map includes:

[0046] Determine a first coordinate of each channel feature map in the output feature map, and determine a corresponding second coordinate from the offset coordinate map of the corresponding channel according to the first coordinate;

[0047] Determine the eigenvalues ​​of the second coordinate in the input feature map and the surrounding eight neighborhoods, and use the average value as the eigenvalue of the first coordinate in the output feature map.

[0048] Based on the further improvement of the above method, the first splicing and fusion layer splices and fuses two input feature maps with different numbers of channels and the same size through the following formula:

[0049]

[0050] in, Represents the concatenated and fused feature map, Respectively represent the two input feature maps, w1 and w2 represent the weights corresponding to the two input feature maps, ε1 represents the first smoothing parameter, ε1≠0, and Cat represents the concatenation operation;

[0051] The second splicing and fusion layer splices and fuses the three input feature maps with different numbers of channels and the same size using the following formula:

[0052]

[0053] in, Represents the concatenated and fused feature map, and They represent the three feature maps of the input respectively, w1′, w2′ and w3′ represent the weights corresponding to the three feature maps of the input respectively, ε2 represents the second smoothing parameter, ε2≠0.

[0054] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects:

[0055] 1. The improved YOLO model is used as the training object. The dynamic upsampling method of point sampling is used in the improved YOLO model to sample the input feature map. At the same time, the input feature map is spliced ​​and fused in a weighted manner. The image is detected through the trained image detection model, which achieves clearer edges and high-quality upsampling, reduces the interference of redundant features, and improves the detection accuracy of multi-size targets;

[0056] 2. The image detection model is trained through regression loss function and category loss function, which improves the accuracy of target detection by the image detection model;

[0057] 3. The improved YOLO model obtains four layers of feature maps from shallow to deep layers in the backbone network, and obtains four prediction results in the detection head, which effectively improves the detection ability of multi-size objects;

[0058] 4. When performing feature fusion in the neck network, the jump connection of the features directly output from the backbone network is added, and the fusion weight is increased, so that the network can perform specific fusion of features of different sizes. The feature map enhanced by the neck network fusion obtains stronger expression ability, which improves the ability of the image detection model to recognize targets of different sizes.

[0059] In the present invention, the above-mentioned technical solutions can also be combined with each other to achieve more preferred combination solutions. Other features and advantages of the present invention will be described in the subsequent description, and some advantages can become obvious from the description, or can be understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained through the contents particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0060] The drawings are only for the purpose of illustrating particular embodiments and are not to be considered limiting of the present invention. Like reference symbols denote like components throughout the drawings.

[0061] Figure 1 A schematic diagram of a flow chart of a method for training an image detection model for a security inspection machine provided by an embodiment of the present invention;

[0062] Figure 2 A schematic diagram of the structure of an image detection model provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0063] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.

[0064] A specific embodiment of the present invention discloses a training method for an image detection model for a security inspection machine, such as Figure 1 As shown, the training method comprises:

[0065] Step S1: Acquire historical image data stored in the security inspection machine, pre-process the historical image data to obtain historical image data in a predetermined format, annotate each historical image using an image annotation tool, and the historical image data and annotation information form a data set;

[0066] Step S2: constructing an image detection model, wherein the image detection model is an improved YOLO model, in which the neck network uses a point sampling dynamic upsampling method to sample the input feature map, and simultaneously uses a weighted method to splice and fuse the input feature map;

[0067] Step S3: Divide the data set into a training set, a validation set, and a test set, and determine the training rounds; use the training set to train the image detection model in each training round, and use the validation set to verify the training effect to obtain the optimal image detection model; use the test set to test the optimal image detection model to obtain a trained image detection model.

[0068] Specifically, Figure 1 As shown, in step S1, the historical image data saved by the security inspection machine may include large-sized targets or small-sized targets, such as large-sized targets such as steel knives or baseball bats, etc., and small-sized targets such as lighters or keys, etc. Each historical image data may include one or more targets.

[0069] Specifically, the historical image data is preprocessed by expanding the image edge or deforming the image data so that the format of the historical image data meets the predetermined format, which is determined according to the image detection model in step S2. Figure 2 As shown, exemplarily, in this image detection model, the predetermined format of the required historical image data is 640*640*3, that is, the required image size is 640*640 and the number of channels is 3.

[0070] Preferably, preprocessing includes one or more of the following operations:

[0071] Image enhancement operations;

[0072] Image denoising operation;

[0073] Image augmentation operations.

[0074] Specifically, the image enhancement operation is used to improve the quality of historical image data to make it more suitable for further graphic detection, including contrast enhancement, brightness adjustment, sharpening or filtering, etc.; the image denoising operation is used to reduce the noise of historical image data, including mean filtering, median filtering, Gaussian filtering or non-local mean filtering, etc.; specifically, the image augmentation operation is used to expand the historical image data, including image rotation, image scaling, image translation, image flipping or image cropping, etc.

[0075] It is worth noting that, by preprocessing the historical image data, the preprocessed historical image data can be more suitable for the training of the image detection model, making the trained image detection model more generalizable.

[0076] Specifically, Figure 1 As shown, after preprocessing the historical image data, the historical image data is further labeled to label the target category and the corresponding target bounding box included in each historical image.

[0077] Preferably, the step of annotating each historical image by using an image annotation tool includes:

[0078] Use the image annotation tool LabelImg to mark the location of the target in the image using a standard bounding box and mark the target category;

[0079] The annotation information includes the center coordinates, length, width and category of the bounding box.

[0080] Specifically, the target bounding box information includes the center coordinates, length, and width of the bounding box, and the target category information includes the category of the target, which are combined to obtain the annotation information.

[0081] Specifically, in step S1, historical image data and corresponding annotation information are combined to obtain a data set.

[0082] Specifically, Figure 1 As shown, in step S2, an image detection model is constructed. The image detection model adopts an improved YOLO model. In the improved YOLO model, the neck network uses a point sampling dynamic upsampling method to sample the input feature map, and at the same time uses a weighted method to splice and fuse the input feature map.

[0083] Preferably, if Figure 2 As shown, the image detection model includes:

[0084] The backbone network is used to receive historical training images, extract and enhance features of the historical training images, and continuously reduce the size of feature maps to obtain first feature maps, second feature maps, third feature maps, and fourth feature maps from shallow to deep layers;

[0085] The neck network fuses and enhances features according to the input first feature map, second feature map, third feature map and fourth feature map to obtain first to fourth fused feature maps;

[0086] The detection head is used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the historical training image according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map.

[0087] Specifically, Figure 2 As shown, the image detection model includes a backbone network, a neck network and a detection head.

[0088] The backbone network receives the historical training images, extracts and enhances the features of the historical training images, and obtains the first feature map, the second feature map, the third feature map, and the fourth feature map from the shallow layer to the deep layer. Specifically, Figure 2 As shown in the figure, after the historical training image enters the image detection model, it first passes through the first convolution layer Conv0 in the backbone network, changes the number of channels of the historical training image, and the feature map after passing through the first convolution layer is 320*320*64, and then passes through the second convolution layer Conv1, the third multi-convolution module with residual C2f_2, the fourth convolution layer Conv3, the fifth multi-convolution module with residual C2f_4, the sixth convolution layer Conv5, the seventh multi-convolution module with residual C2f_6, the eighth convolution layer Conv7, and the ninth convolution layer Conv8. The multi-convolution module C2f_8 with residuals and the spatial pyramid fast pooling layer module SPPF of the tenth layer; the output feature maps 160*160*128, 80*80*256, 40*40*512, and 20*20*512 of the multi-convolution module C2f_2 with residuals on the third layer, the multi-convolution module C2f_4 with residuals on the fifth layer, the multi-convolution module C2f_6 with residuals on the seventh layer, and the spatial pyramid fast pooling layer module SPPF of the tenth layer are used as the first feature map, the second feature map, the third feature map, and the fourth feature map from the shallowest layer to the deepest layer, respectively. It is worth noting that in the backbone network, the first convolution layer Conv0, the second convolution layer Conv1, the fourth convolution layer Conv3, the sixth convolution layer Conv5 and the eighth convolution layer Conv7 are used to reduce the size of the feature map, and the third layer of the multi-convolution module C2f_2 with residual, the fifth layer of the multi-convolution module C2f_4 with residual and the seventh layer of the multi-convolution module C2f_6 with residual are used for feature enhancement of the feature map without changing the size and number of channels of the feature map.

[0089] It is worth mentioning that, through the third-layer multi-convolution module C2f_2 with residual, the fifth-layer multi-convolution module C2f_4 with residual, and the seventh-layer multi-convolution module C2f_6 with residual, the image detection model obtains richer gradient flow while being lightweight, generates more representative features, and can improve the performance and representation ability of the image detection model, making the image detection model suitable for more complex data tasks.

[0090] Specifically, Figure 2As shown, in the neck network, features are fused and enhanced according to the first feature map 160*160*128, the second feature map 80*80*256, the third feature map 40*40*512 and the fourth feature map 20*20*512 input by the backbone network to obtain the first fused feature map 160*160*128, the second fused feature map 80*80*256, the third fused feature map 40*40*512 and the fourth fused feature map 20*20*512, which are respectively input into the detection head for result prediction to obtain the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the historical training image.

[0091] Preferably, if Figure 2 As shown, the neck network includes:

[0092] A first sampling and fusion layer is used to perform a point sampling operation on the fourth feature map, concatenate and fuse the sampled feature map with the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first intermediate feature map;

[0093] The second sampling and fusion layer is used to perform a point sampling operation on the first intermediate feature map, concatenate and fuse the sampled feature map with the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second intermediate feature map;

[0094] The third sampling and fusion layer is used to perform a point sampling operation on the second intermediate feature map, concatenate and fuse the sampled feature map with the first feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first fused feature map;

[0095] The first convolution fusion layer is used to perform a convolution operation on the first fused feature map, concatenate and fuse the feature map after the convolution, the second intermediate feature map, and the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second fused feature map;

[0096] The second convolution fusion layer is used to perform a convolution operation on the second fused feature map, concatenate and fuse the feature map after the convolution, the first intermediate feature map, and the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a third fused feature map;

[0097] The third convolution fusion layer is used to perform a convolution operation on the third fused feature map, concatenate and fuse the feature map after the convolution operation with the fourth feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a fourth fused feature map.

[0098] Preferably, the first sampling fusion layer, the second sampling fusion layer and the third sampling fusion layer each include a point sampling layer, a first splicing fusion layer and a residual convolution layer connected in sequence;

[0099] The first convolutional fusion layer, the second convolutional fusion layer and the third convolutional fusion layer all include a convolutional layer, a second splicing fusion layer and a residual convolutional layer connected in sequence.

[0100] Specifically, Figure 2 As shown, the first sampling fusion layer includes a point sampling layer DySample10, a first splicing fusion layer BiFPN Concat11 and a residual convolution layer C2f_12 connected in sequence, the second sampling fusion layer includes a point sampling layer DySample13, a first splicing fusion layer BiFPN Concat14 and a residual convolution layer C2f_15 connected in sequence, and the third sampling fusion layer includes a point sampling layer DySample16, a first splicing fusion layer BiFPN Concat17 and a residual convolution layer C2f_18 connected in sequence; the first convolution fusion layer includes a convolution layer Conv19, a second splicing fusion layer BiFPN Concat20 and a residual convolution layer C2f_21 connected in sequence, the second convolution fusion layer includes a convolution layer Conv22, a second splicing fusion layer BiFPNConcat23 and a residual convolution layer C2f_24 connected in sequence, and the third convolution fusion layer includes a convolution layer Conv25, a second splicing fusion layer BiFPN Concat26 and a residual convolution layer C2f_27 connected in sequence. Concat26 and residual convolution layer C2f_27. The first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map are obtained through residual convolution layer C2f_18, residual convolution layer C2f_21, residual convolution layer C2f_24 and residual convolution layer C2f_27 respectively; at the same time, the first intermediate feature map 40*40*512 and the second intermediate feature map 80*80*256 are obtained through residual convolution layer C2f_12 and residual convolution layer C2f_15 respectively.

[0101] It is worth noting that through the point sampling layers DySample10, DySample13, and DySample16, the feature map can retain more edge information. Through the first splicing and fusion layer BiFPN Concat11, BiFPN Concat14, and BiFPN Concat17, and the second splicing and fusion layer BiFPN Concat20, BiFPN Concat23, and BiFPN Concat26, the feature fusion adds the jump connection of the direct output features from the backbone network and increases the fusion weight, so that the network can perform specific fusion of features of different sizes, and the feature map enhanced by the neck network fusion obtains stronger expression ability.

[0102] Preferably, the point sampling layer is used to change the size of the input feature map according to the scaling factor of the feature, including:

[0103] The input feature map is divided into g groups according to the number of channels of the input feature map, each group of input feature maps includes the same number of channels, and the coordinates of each group of input feature maps are normalized;

[0104] Perform convolution operation on the input feature map H*W*C to change the number of channels of the input feature map to obtain the feature map H*W*(2*s*s*g), further deform the feature map H*W*(2*s*s*g) to obtain the feature map sH*sW*2g, and normalize the elements of the feature map sH*sW*2g. The normalized feature map sH*sW*2g is used as the offset coordinate map of the output feature map; where s is the scaling factor of the feature;

[0105] According to the normalized input feature map of each set of coordinates and the corresponding offset coordinate map, the output feature map corresponding to each set is determined, and the output feature maps corresponding to g sets are combined to obtain the sampled feature map.

[0106] Specifically, Figure 2 As shown, the point sampling layer includes DySample10, DySample13, and DySample16. In the point sampling layer, the size of the input feature map is adjusted and changed, that is, the size of the fourth feature map 20*20*512, the first intermediate feature map 40*40*512, and the second intermediate feature map 80*80*256 are adjusted and changed respectively, so that the size of the feature map after sampling is consistent with the size of the third feature map 40*40*512, the second feature map 80*80*256, and the first feature map 160*160*128. That is, in DySample10, the feature map of 20*20*512 is adjusted to 40*40*512, in DySample13, the feature map of 40*40*512 is adjusted to 80*80*512, and in DySample16, the feature map of 80*80*256 is adjusted to 160*160*256.

[0107] Specifically, taking the point sampling layer DySample10 as an example, the fourth feature map 20*20*512 is point sampled to obtain 40*40*512, and s is determined according to the feature map size before and after sampling. The ratio of the length after sampling to the length before sampling is s, or the ratio of the width after sampling to the width before sampling is s. At this time, s=2, g is a common divisor of 512, and the number of channels 512 is evenly divided into g groups, and g can be 1, 2, 4, 8, etc. For example, in the point sampling layer DySample13, the first intermediate feature map 40*40*512 is point sampled to obtain 80*80*512, and s=2 at this time.

[0108] First, a convolution operation is performed on the fourth feature map 20*20*512 to change the number of channels so that the feature map becomes 20*20*(2*2*2*g), and the feature map 20*20*(2*2*2*g) is deformed to obtain a feature map 40*40*2g. It is worth noting that the element corresponding to each coordinate in the feature map 40*40*2g includes two values.

[0109] Next, all elements in the feature map 40*40*2g are normalized to obtain the offset coordinate map 40*40*2g. The number of channels of the offset coordinate map 40*40*2g is g, and the input fourth feature map 20*20*512 is also divided into g groups, that is, each group of input feature maps after coordinate normalization corresponds to a offset coordinate map.

[0110] For example, when g=1, there is only one offset coordinate map of the fourth feature map 20*20*512; when g=2, the 512 channels are divided into 2 groups, and the obtained offset coordinate map is 40*40*(2*2), that is, the offset coordinate map of two channels, and each group of input feature maps after coordinate normalization corresponds to one offset coordinate map.

[0111] Finally, according to the normalized input feature map of each set of coordinates and the corresponding offset coordinate map, the corresponding output feature map of each set is determined, and the corresponding output feature maps of g sets are combined to obtain the sampled feature map.

[0112] Preferably, determining each group of corresponding output feature maps according to each group of coordinate normalized input feature maps and the corresponding offset coordinate maps includes:

[0113] Determine a first coordinate of each channel feature map in the output feature map, and determine a corresponding second coordinate from the offset coordinate map of the corresponding channel according to the first coordinate;

[0114] Determine the eigenvalues ​​of the second coordinate in the input feature map and the surrounding eight neighborhoods, and use the average value as the eigenvalue of the first coordinate in the output feature map.

[0115] Specifically, determine the first coordinate of the feature map of each channel of the output feature map 40*40*512, where the first coordinate is the coordinate of any channel in the output feature map 40*40*512, and the offset coordinate map corresponding to the channel, select the eigenvalue corresponding to the first coordinate in the offset coordinate map, which is the second coordinate, and take the average of the 9 eigenvalues ​​of the eight neighborhoods around the second coordinate in the input feature map as the eigenvalue corresponding to the first coordinate in the output feature map.

[0116] It is worth noting that the length and width of the offset coordinate map are the same as the length and width of the output feature map, and the coordinates of the two correspond to each other. In the output feature map, each element represents a feature value, and in the offset coordinate map, each element represents a coordinate value, which represents the coordinate of the input feature map.

[0117] The first coordinate is determined from the output feature map. According to the first coordinate, the coordinate value can be taken from the offset coordinate map of the corresponding channel as the second coordinate. According to the second coordinate, a value is taken from the input feature map. Finally, the average value of the 9 eigenvalues ​​of the eight neighborhoods around the second coordinate is calculated as the eigenvalue of the first coordinate in the output feature map.

[0118] Preferably, the first concatenation and fusion layer concatenates and fuses two input feature maps with different numbers of channels and the same size using the following formula:

[0119]

[0120] in, Represents the concatenated and fused feature map, They represent two feature maps of the input respectively, w1 and w2 represent the weights corresponding to the two feature maps of the input respectively, ε1 represents the first smoothing parameter, ε1≠0, and Cat represents the concatenation operation.

[0121] Specifically, Figure 2 As shown, the first splicing and fusion layer includes BiFPN Concat11, BiFPN Concat14, and BiFPN Concat17. In BiFPN Concat11, the third feature map and the fourth feature map are sampled and spliced ​​and fused. In BiFPN Concat14, the second feature map and the first intermediate feature map are sampled and fused. In BiFPN Concat17, the first feature map and the second intermediate feature map are sampled and fused. It can be understood that in different first splicing and fusion layers, the weights corresponding to different input feature maps may be different. As a training parameter of the image detection model, the first smoothing parameter ε1≠0.

[0122] Preferably, the second splicing and fusion layer splices and fuses the three input feature maps with different numbers of channels and the same size using the following formula:

[0123]

[0124] in, Represents the concatenated and fused feature map, and They represent the three feature maps of the input respectively, w1′, w2′ and w3′ represent the weights corresponding to the three feature maps of the input respectively, ε2 represents the second smoothing parameter, ε2≠.

[0125] Specifically, Figure 2 As shown, the second splicing and fusion layer includes BiFPN Concat20, BiFPN Concat23, and BiFPN Concat26. In BiFPN Concat20, the second feature map, the feature map after convolution of the first fused feature map, and the second intermediate feature map are spliced ​​and fused. In BiFPN Concat23, the third feature map, the first intermediate feature map, and the second fused feature map are spliced ​​and fused after convolution. In BiFPNConcat26, the fourth feature map and the third fused feature map are spliced ​​and fused after convolution.

[0126] It can be understood that in BiFPN Concat20 and BiFPN Concat23, different weights can be used for the three different input feature maps as training parameters of the image detection model. At the same time, in BiFPN Concat26, different weights can be used for the two input feature maps as training parameters of the image detection model.

[0127] It is worth noting that the first smoothing parameter ε1 and the second smoothing parameter ε2 are used to avoid division by zero errors and can be reasonably set according to actual conditions.

[0128] It is worth noting that the second splicing fusion layer and the first sampling fusion layer in the third convolutional fusion layer, and the second sampling fusion layer and the first splicing fusion layer in the third sampling fusion layer are essentially the same, and both set and train weight parameters for the two input feature maps.

[0129] Preferably, the detection head includes a first detection head, a second detection head, a third detection head and a fourth detection head, which are respectively used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the historical training image according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map;

[0130] The first prediction result, the second prediction result, the third prediction result and the fourth prediction result respectively include a plurality of bounding box prediction results and corresponding category prediction results;

[0131] The bounding box prediction result includes the center coordinates, length, width, and confidence level of the bounding box.

[0132] Specifically, the category prediction result includes the probability that the bounding box belongs to a preset category.

[0133] Specifically, Figure 2 As shown, the detection head includes four prediction layers, the first detection head SODH layer, the second detection head Detect1, the third detection head Detect2 and the fourth detection head Detect3, which respectively predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the historical training image according to the first fused feature map 160*160*128, the second fused feature map 80*80*256, the third fused feature map 40*40*512 and the fourth fused feature map 20*20*512.

[0134] The prediction results in each detection head include bounding box prediction results and category prediction results. It is worth noting that each historical training image may include multiple targets, that is, the first prediction result, the second prediction result, the third prediction result and the fourth prediction result may include multiple targets.

[0135] The bounding box prediction result includes the center coordinates, length, width, and confidence level of the bounding box. For the same prediction result, each bounding box corresponds to one target.

[0136] Specifically, the center coordinates of the bounding box are the coordinates of the intersection of the diagonals of the predicted bounding box, the length and width are the length and width corresponding to the predicted bounding box, and the confidence of containing the target refers to the probability that the predicted bounding box contains the target.

[0137] Specifically, Figure 1 As shown, in step S3, the labeled data set is divided into a training set, a validation set, and a test set, and training rounds are set. In each training round, each historical training image in the training set is used to train the image detection model. During each training, the corresponding category loss value and regression loss value are solved according to the prediction results output by the image detection model and the annotation information, and then the loss function of the model is obtained, and the model parameters are optimized by back propagation based on the loss function.

[0138] Preferably, the loss function of the image detection model includes a category loss function and a regression loss function, and the category loss function adopts a cross entropy loss function;

[0139] The regression loss function is:

[0140] L Shape-IoU =1-IoU+distance shape +0.5×Ω shape ;

[0141]

[0142]

[0143]

[0144]

[0145]

[0146]

[0147]

[0148] Among them, L Shape-IoU represents the bounding box loss, B represents the predicted area of ​​the bounding box, and B gt represents the real area of ​​the bounding box, x c ,y c Represents the predicted center coordinates of the bounding box, represents the true center coordinates of the bounding box, W and h represent the predicted length and width of the bounding box, and w gt 、h gt represents the actual length and width of the bounding box, scale represents the scale factor, θ represents the shape factor, and C represents the diagonal length of the minimum bounding box that can simultaneously enclose the predicted area and the real area of ​​the bounding box.

[0149] Specifically, the category cross entropy loss function is used to quickly calculate the category of the target included in each historical image in the historical image data to obtain the category loss value, so that it can converge quickly and improve the training speed of the image detection model. At the same time, the regression loss function is used to calculate the loss of the bounding box of each historical image, so that the model can predict the position of the bounding box more accurately.

[0150] Specifically, at the end of each training round, the image detection model is verified using the historical image data in the validation set, and the category loss value and regression loss value of each historical image data in the validation set are calculated to determine the training effect of the image detection model at the end of the training round. The training effect of the image detection model at the end of the training round is compared with the training effect of the optimal image detection model saved at the end of the previous training round, and the image detection model with the better training effect is saved as the image detection model for the next training round until the set training round is completed and the optimal image detection model is determined.

[0151] Specifically, in step S3, the optimal image detection model is tested using the test set, and the tested image detection model is used as the trained image detection model.

[0152] Specifically, if the test fails, the model needs to be retrained using the training set until the model test passes, thereby obtaining a trained image detection model.

[0153] Compared with the prior art, a training method for an image detection model for a security inspection machine provided by an embodiment of the present invention uses an improved YOLO model as a training object, and uses a point sampling dynamic upsampling method in the improved YOLO model to sample the input feature map, and uses a weighted method to splice and fuse the input feature map. The image is detected by the trained image detection model, and clearer edges and high-quality upsampling are achieved, and the interference of redundant features is reduced, thereby improving the detection accuracy of multi-size targets; at the same time, the image detection model is trained by a regression loss function and a category loss function, thereby improving the accuracy of the image detection model for target detection; and, by obtaining four layers of feature maps from shallow to deep layers in the backbone network through the improved YOLO model, and by obtaining four prediction results in the detection head, the detection capability of multi-size targets is effectively improved; and, by adding the jump connection of the direct output features from the backbone network when performing feature fusion in the neck network, and increasing the fusion weight, so that the network performs specific fusion on features of different sizes, and obtains a stronger expression capability through the feature map enhanced by the neck network fusion, thereby improving the ability of the image detection model to recognize targets of different sizes.

[0154] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.

[0155] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any technician familiar with the technical field within the technical scope disclosed by the present invention should be covered within the protection scope of the present invention.

Claims

1. A training method for an image detection model for a security inspection machine, characterized in that: The training method comprises: Acquire historical image data stored in the security inspection machine, pre-process the historical image data to obtain historical image data in a predetermined format, annotate each historical image using an image annotation tool, and the historical image data and annotation information form a data set; Constructing an image detection model, wherein the image detection model is an improved YOLO model, in which the neck network uses a point sampling dynamic upsampling method to sample the input feature map, and simultaneously uses a weighted method to splice and fuse the input feature map; The data set is divided into a training set, a validation set, and a test set, and the training rounds are determined; in each training round, the training set is used to train the image detection model, and the validation set is used to verify the training effect to obtain the optimal image detection model; the test set is used to test the optimal image detection model to obtain a trained image detection model.

2. The training method according to claim 1, characterized in that: The step of labeling each historical image using an image labeling tool includes: Use the image annotation tool LabelImg to mark the location of the target in the image using a standard bounding box and mark the target category; The annotation information includes the center coordinates, length, width and category of the bounding box.

3. The training method according to claim 2, characterized in that: The loss function of the image detection model includes a category loss function and a regression loss function, and the category loss function adopts a cross entropy loss function; The regression loss function is: L Shape-IoU =1-IoU+distance shape +0.5×Ω shape ; Among them, L Shape-IoU represents the bounding box loss, B represents the predicted area of ​​the bounding box, and B gt represents the real area of ​​the bounding box, x c ,y c Represents the predicted center coordinates of the bounding box, represents the true center coordinates of the bounding box, W and h represent the predicted length and width of the bounding box, and w gt 、h gt represents the actual length and width of the bounding box, scale represents the scale factor, θ represents the shape factor, and C represents the diagonal length of the minimum bounding box that can simultaneously enclose the predicted area and the real area of ​​the bounding box.

4. The training method according to claim 1, characterized in that: Preprocessing includes one or more of the following operations: Image enhancement operations; Image denoising operation; Image augmentation operations.

5. The training method according to claim 1, characterized in that: The image detection model includes: The backbone network is used to receive historical training images, extract and enhance features of the historical training images, and continuously reduce the size of feature maps to obtain first feature maps, second feature maps, third feature maps, and fourth feature maps from shallow to deep layers; The neck network fuses and enhances features according to the input first feature map, second feature map, third feature map and fourth feature map to obtain first to fourth fused feature maps; The detection head is used to predict the first prediction result, the second prediction result, the third prediction result and the fourth prediction result of the historical training image according to the first fusion feature map, the second fusion feature map, the third fusion feature map and the fourth fusion feature map.

6. The training method according to claim 5, characterized in that: The neck network includes: A first sampling and fusion layer is used to perform a point sampling operation on the fourth feature map, concatenate and fuse the sampled feature map with the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first intermediate feature map; The second sampling and fusion layer is used to perform a point sampling operation on the first intermediate feature map, concatenate and fuse the sampled feature map with the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second intermediate feature map; The third sampling and fusion layer is used to perform a point sampling operation on the second intermediate feature map, concatenate and fuse the sampled feature map with the first feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a first fused feature map; The first convolution fusion layer is used to perform a convolution operation on the first fused feature map, concatenate and fuse the feature map after the convolution, the second intermediate feature map, and the second feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a second fused feature map; The second convolution fusion layer is used to perform a convolution operation on the second fused feature map, concatenate and fuse the feature map after the convolution, the first intermediate feature map, and the third feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a third fused feature map; The third convolution fusion layer is used to perform a convolution operation on the third fused feature map, concatenate and fuse the feature map after the convolution operation with the fourth feature map to obtain a fused image, and perform a residual convolution operation on the fused image to obtain a fourth fused feature map.

7. The training method according to claim 6, characterized in that: The first sampling fusion layer, the second sampling fusion layer and the third sampling fusion layer each include a point sampling layer, a first splicing fusion layer and a residual convolution layer connected in sequence; The first convolutional fusion layer, the second convolutional fusion layer and the third convolutional fusion layer all include a convolutional layer, a second splicing fusion layer and a residual convolutional layer connected in sequence.

8. The training method according to claim 7, characterized in that: The point sampling layer is used to change the size of the input feature map according to the scaling factor of the feature, including: The input feature map is divided into g groups according to the number of channels of the input feature map, each group of input feature maps includes the same number of channels, and the coordinates of each group of input feature maps are normalized; Perform convolution operation on the input feature map H*W*C to change the number of channels of the input feature map to obtain the feature map H*W*(2*s*s*g), further deform the feature map H*W*(2*s*s*g) to obtain the feature map sH*sW*2g, and normalize the elements of the feature map sH*sW*2g. The normalized feature map sH*sW*2g is used as the offset coordinate map of the output feature map; where s is the scaling factor of the feature; According to the normalized input feature map of each set of coordinates and the corresponding offset coordinate map, the output feature map corresponding to each set is determined, and the output feature maps corresponding to g sets are combined to obtain the sampled feature map.

9. The training method according to claim 8, characterized in that: The step of determining each group of corresponding output feature maps according to each group of normalized input feature maps and the corresponding offset coordinate maps includes: Determine a first coordinate of each channel feature map in the output feature map, and determine a corresponding second coordinate from the offset coordinate map of the corresponding channel according to the first coordinate; Determine the eigenvalues ​​of the second coordinate in the input feature map and the surrounding eight neighborhoods, and use the average value as the eigenvalue of the first coordinate in the output feature map.

10. The training method according to claim 7, characterized in that: The first splicing and fusion layer splices and fuses two input feature maps with different numbers of channels and the same size using the following formula: in, Represents the feature map after splicing and fusion, Respectively represent the two feature maps of the input, w1 and w2 represent the weights corresponding to the two feature maps of the input, ε1 represents the first smoothing parameter, ε1≠0, and Cat represents the concatenation operation; The second splicing and fusion layer splices and fuses the three input feature maps with different numbers of channels and the same size using the following formula: in, Represents the feature map after splicing and fusion, and They represent the three feature maps of the input respectively, w1′, w2′ and w3′ represent the weights corresponding to the three feature maps of the input respectively, ε2 represents the second smoothing parameter, ε2≠0.

Citation Information

Patent Citations

  • Improved security inspection dangerous goods detection method based on deep learning YOLOv7 algorithm

    CN116883747A

  • Security check picture contraband image detection method and device based on YOLOv5-Mobilenet network model and computer storage medium

    CN117218583A

  • 3D target detection method based on fusion sampling strategy and graph network

    CN117218625A

  • Steel plate surface defect detection method based on improved YOLOv8

    CN118279272A

  • Multi-model fusion-based object detection method and apparatus, device and medium

    WO2023071121A1