X-ray contraband detection method based on contour perception and optimal distribution migration
By enhancing the feature recognition of contraband through the contour perception module and generating small sample features through the optimal distribution transfer module, the problems of overfitting and low feature recognition in the X-ray contraband detection model are solved, thereby improving detection performance and accuracy.
Patent Information
- Application Number
- CN202411971446.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2044-12-30
AI Technical Summary
Existing X-ray contraband detection models are prone to overfitting due to data scarcity and have low recognition of contraband features, making it difficult to effectively detect potential contraband.
The contour perception module estimates the contour information of contraband and incorporates it into the feature extraction process. Combined with the optimal distribution transfer module, additional small sample features are generated. The transferability of feature distributions of different categories prevents model overfitting.
It improves the recognizability of contraband features and the detection performance of the model, enhances the ability to capture the spatial geometry of objects, and significantly improves the accuracy and robustness of X-ray contraband detection.
Smart Images

Figure CN119888616B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of X-ray contraband detection, and particularly relates to an X-ray contraband detection method based on contour perception and optimal distribution migration. BACKGROUND
[0002] X-ray contraband detection (XPID) models aim to automatically analyze X-ray images of passenger luggage to detect potential contraband such as knives, guns, ammunition, etc., which plays a crucial role in maintaining public safety. However, due to strict supervision by relevant departments, the frequency of occurrence of such contraband is low, making it difficult to collect enough X-ray images for model training. This scarcity of data increases the risk of overfitting of the XPID model. To address this problem, researchers have shifted their focus to the task of few-shot X-ray contraband detection (FSXPID), which aims to train a detector with a limited number of X-ray images to classify and locate new categories of contraband.
[0003] The applicant first summarizes two challenges faced in the current FSXPID task. The first challenge is how to enhance the discriminability of the features of contraband extracted from X-ray images. Unlike traditional RGB images, contraband in X-ray images has unique features. Due to the difference in X-ray energy absorption of contraband made of different materials, X-ray images usually lack rich appearance details due to color degradation, with only clear edges and contours. The lack of significant appearance details of contraband significantly reduces the discriminability of its features. Previous XPID methods have proven that the spatial geometric structure of edges can effectively enhance the features of contraband. These methods incorporate edge information extracted from the entire image by hand-designed Canny or Sobel operators into contraband features. However, this approach inevitably introduces edge details from irrelevant background areas, resulting in additional background noise in the features. Naturally, the applicant considers utilizing the contour information of foreground contraband and incorporating it into the multi-scale feature extraction process. The second challenge is to mitigate the risk of overfitting of the FSXPID model under data scarcity conditions. In addition to the challenges posed by the unique characteristics of contraband X-ray images, the limited nature of the training data further exacerbates the difficulty of contraband detection. Existing FSXPID methods simplify the classification process of small sample features by relying on visual prototypes to establish clear decision boundaries between classes. However, the visual prototypes extracted from limited image data exhibit significant intra-class differences. In recent years, new progress has been made in small sample learning, exploring more intuitive feature synthesis-based strategies to generate additional features for new classes by estimating feature distributions. These methods focus on calibrating the statistical properties of new class distributions, but ignore the transferability between feature distributions of different classes.
[0004] In summary, how to utilize the contour information of foreground contraband to enhance the recognizability of contraband features extracted from X-ray images, and how to generate additional small-sample features through the transferability between feature distributions of different categories to prevent the risk of model overfitting, are problems that urgently need to be solved by those skilled in the art. Summary of the Invention
[0005] To address the shortcomings of the existing technologies, the technical problem this invention aims to solve is: how to provide an X-ray contraband detection method based on contour perception and optimal distribution transfer. This method estimates key contour details describing the spatial geometry of the foreground region using a contour perception module and integrates them into the feature extraction process, thereby enhancing the recognizability of contraband features extracted from X-ray images by utilizing the contour information of the foreground contraband. Simultaneously, the optimal distribution transfer module fully utilizes the contour information of the foreground contraband and the transferability between different category feature distributions, enabling the generation of additional small-sample features through the transferability between different category feature distributions. This effectively prevents model overfitting, thereby improving the performance of X-ray contraband detection.
[0006] Improve the ability to identify the characteristics of contraband and enhance the performance of the model.
[0007] To solve the above-mentioned technical problems, the present invention adopts the following technical solution:
[0008] X-ray contraband detection methods based on contour perception and optimal distribution transfer include:
[0009] S1: Acquire the X-ray image to be detected;
[0010] S2: Input the X-ray image to be detected into the trained contraband detection model and output the corresponding contraband detection image;
[0011] The steps for training a contraband detection model are as follows:
[0012] S201: Obtain X-ray images used as training samples, as well as corresponding contraband outlines and contraband annotations;
[0013] S202: Input the X-ray image into the backbone network for feature extraction to obtain multi-scale feature maps;
[0014] S203: Input the multi-scale feature map into the contour perception module to estimate the contour information of the contraband and obtain the contour probability map; and enhance the multi-scale feature map through the contour probability map to obtain the multi-scale enhanced feature map.
[0015] S204: Optimize the parameters of the contour perception module by calculating the contour loss function based on the contour probability map and the contraband contour map;
[0016] S205: Extract the region of interest from the enhanced feature map at multiple scales to obtain the ROI feature map;
[0017] S206: Input the ROI feature map into the optimal distribution transfer module to fit the feature distribution of the new category, generate additional new category features; and enhance the ROI feature map with the new category features to obtain the enhanced ROI feature map;
[0018] S207: Input the enhanced ROI feature map into the detection head for detection to obtain the contraband detection map; the contraband detection map includes the target box of the contraband and the corresponding contraband type;
[0019] S208: Optimize the parameters of the contraband detection model by calculating the loss function based on the contraband detection map and the contraband annotation map;
[0020] S209: Repeat steps S201 to S208 to iteratively train the contraband detection model until the model converges or reaches the preset number of iterations;
[0021] S3: Output the contraband detection image as the contraband detection result of the X-ray image to be detected.
[0022] Preferably, in step S202, feature extraction is performed using a backbone network based on a two-stage detector, Faster RCNN, to obtain multi-scale feature maps.
[0023] Preferably, in step S203, the processing steps for the contour perception module to generate the contour probability map are as follows:
[0024] S2031: Obtain multi-scale feature maps F i=1,2,3,4 ;
[0025] S2032: Multi-scale feature maps F i=1,2,3,4 Projecting the features onto the same dimension and then performing top-down stitching and enhancement on the projected feature maps yields the contour feature map F′. i=1,2,3,4 ;
[0026] The formula is expressed as:
[0027]
[0028] The formula for projection is expressed as:
[0029]
[0030] In the formula: BL(·) represents the base layer consisting of 3×3 convolution, batch normalization and ReLU activation function; up(·) represents upsampling operation; ⊙ represents element-wise multiplication; PL(·) represents the projection layer consisting of 1×1 convolution, 3×3 convolution and ReLU activation function;
[0031] S2033: Perform a 1×1 convolution on the contour feature map F′1 to generate a contour probability map C. P .
[0032] Preferably, in step S203, the processing steps for the contour perception module to generate the enhanced feature map are as follows:
[0033] S2034: Multi-scale feature maps F i=1,2,3,4 The input consists of a transition layer composed of 1×1 convolutions and 3×3 convolutions, resulting in the transitioned feature map TL(F). i );
[0034] S2035: For the feature map F4 at the last scale: combine the transition-processed feature map TL(F4) and the contour probability map C P The basic modules are input together and their features are fused to obtain the enhanced feature map at the final scale.
[0035] The calculation formula for the basic module is expressed as follows:
[0036]
[0037] S2036: For feature maps F before the last scale i=1,2,3 : The feature map TL(F) after transition processing i=1,2,3 Probability profile C P and the enhanced feature map at the next scale The basic modules are input together and their features are fused to obtain the enhanced feature map at this scale.
[0038] The calculation formula for the basic module is expressed as follows:
[0039]
[0040] In the formula: [·, ·] denote the splicing operation; the adjustment parameters γ and β consist of a series of different 3×3 convolutions; This represents element-wise addition. This represents element-wise multiplication;
[0041] S2037: Obtain multi-scale enhanced feature maps through the preceding steps.
[0042] Preferably, in step S204, the weighted binary cross-entropy loss and the weighted cross-union ratio loss are calculated based on the contour probability map and the contraband contour map, respectively; and the weighted binary cross-entropy loss and the weighted cross-union ratio loss are weighted and summed to obtain the contour loss function L. contour ;
[0043] The formula is expressed as:
[0044] L contour =L wBCE +L wIoU ,
[0045] In the formula: L wBCE L represents the weighted binary cross-entropy loss; wIoU This indicates the weighted average loss.
[0046] Preferably, in step S205, the multi-scale enhanced feature map is input into the RPN network and the region of interest alignment module to extract the region of interest and obtain the ROI feature map.
[0047] Preferably, in step S206, the processing steps for the optimal distribution transfer module to generate new category features are as follows:
[0048] S2061: Based on ROI feature maps F roi New category of modeling Feature distribution
[0049] S2062: Obtain the basic category dataset D base From the basic category dataset D base Extracting feature vectors Where f i Let f represent the feature vector corresponding to the i-th category, and N represent the total number of base categories; calculate the mean μ of each base category using f. base and the corresponding covariance matrix ∑ base To obtain the basic category Feature distribution
[0050] S2063: Calculate the cosine similarity between the base class and the new class in the feature space;
[0051] S2064: From basic categories Identify new categories The mean of the basic categories with the highest cosine similarity and its corresponding covariance matrix Then, model the base class that has the highest cosine similarity to the new class. Feature distribution
[0052] S2065: From basic categories and new categories The features of the basic category and the new category are sampled to obtain the basic category features S. base and new category features S novel ; where the basic category feature Sbase and new category features S novel The i-th sampling feature in the data is represented as: and m represents the number of sampling features;
[0053] S2066: Calculate basic category features S using the Earth movement distance algorithm. base and new category features S novel Optimal transmission scheme between
[0054] S2067: Adjusting the new category feature S using the optimal transmission scheme P novel The new categorical feature S′ after calibration is obtained. novel ;
[0055] The formula is expressed as:
[0056]
[0057] In the formula: Represents matrix multiplication;
[0058] S2068: The calibrated new category feature S′ novel With roi feature map F roi By concatenating the features, we obtain the enhanced ROI feature map F. roi_aug ;
[0059] The formula is expressed as:
[0060] F roi_avg =[F roi MLP(S′) novel )],
[0061] In the formula: MLP represents a multilayer perceptron consisting of fully connected layers and activation functions.
[0062] Preferably, in step S2061, the new category is calculated using the following formula. Feature distribution
[0063] In the formula: Represents the roi feature map F roi The i-th foreground roi feature in the image; M represents the roi feature map F. roi The number of mid-foreground ROI features.
[0064] Preferably, in step S2063, the cosine similarity between the base category and the new category in the feature space is calculated using the following formula:
[0065]
[0066] In the formula: d represents the cosine similarity between the mean of the j-th base category and the mean of the new category; d represents the number of base categories.
[0067] Preferably, in step S2066, the optimal transmission scheme P is calculated using the following formula:
[0068]
[0069] In the formula: P ij Indicates from the basic category The i-th sampled feature is transferred to the new category. The allocation ratio of the j-th sampling feature; Representation from basic categories The i-th sampled feature is transferred to the new category. The distance cost matrix associated with the j-th sampled feature; ||·||2 represents -norm.
[0070] Compared with existing technologies, the X-ray contraband detection method based on contour perception and optimal distribution migration in this invention has the following advantages:
[0071] First, considering the inherent visual characteristics of X-ray images, this invention designs a contour perception module for the contour information of foreground contraband. This module focuses on estimating key contour details that describe the spatial geometry of the foreground region and effectively integrates the foreground contour information of the contraband into the feature extraction process. This enables the use of the contour information of the foreground contraband to enhance the recognizability of contraband features extracted from X-ray images. It can enhance the model's ability to capture the spatial geometry of objects and distinguish contraband features, thereby improving the model's feature recognition during feature extraction and ultimately improving the performance and accuracy of X-ray contraband detection. Secondly, this invention designs an optimal distribution transfer module based on the transferability between feature distributions of different categories. Unlike directly learning the decision boundary of a new category, this module fully utilizes the contour information of the foreground contraband and the transferability between feature distributions of different categories. It transfers the base class distribution with abundant data to the new category distribution estimated with limited data, employing an optimal transfer strategy to accurately model the feature distribution of small sample categories in small sample scenarios. This achieves the generation of additional small sample features through the transferability between feature distributions of different categories. These carefully synthesized features enable the FSXPID model to possess strong small sample learning capabilities, effectively preventing model overfitting and thus improving the model's small sample detection performance and accuracy. Finally, based on the above two modules, this invention constructs a novel FSXPID model on top of Faster R-CNN to effectively enhance the discriminative power and detection performance of contraband features. Extensive experimental results demonstrate that the method proposed in this invention significantly improves detection performance and exhibits excellent robustness. Attached Figure Description
[0072] To make the objectives, technical solutions, and advantages of the invention clearer, the invention will now be described in further detail with reference to the accompanying drawings, wherein:
[0073] Figure 1 This is a general framework diagram of the contraband detection model in this embodiment of the invention.
[0074] Figure 2 This is an illustrative diagram of the contour perception module (CAM) architecture in an embodiment of the present invention.
[0075] Figure 3 This is a schematic diagram of the Optimal Distributed Migration (ODTM) module in an embodiment of the present invention. Detailed Implementation
[0076] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but only to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0077] The following detailed explanation illustrates the specific implementation methods:
[0078] Example:
[0079] This embodiment discloses an X-ray contraband detection method based on contour perception and optimal distribution migration.
[0080] X-ray contraband detection methods based on contour perception and optimal distribution transfer include:
[0081] S1: Acquire the X-ray image to be detected;
[0082] S2: Input the X-ray image to be detected into the trained contraband detection model (hereinafter also called FSXPID), and output the corresponding contraband detection image;
[0083] Combination Figure 1 As shown, the processing steps for training a contraband detection model are as follows:
[0084] S201: Obtain X-ray images used as training samples, as well as corresponding contraband outlines and contraband annotations;
[0085] S202: Input the X-ray image into the backbone network for feature extraction to obtain multi-scale feature maps;
[0086] S203: Input the multi-scale feature map into the Contour Awareness Module (CAM) to estimate the contour information of the contraband and obtain the contour probability map; and enhance the multi-scale feature map through the contour probability map to obtain the multi-scale enhanced feature map.
[0087] S204: Optimize the parameters of the contour perception module by calculating the contour loss function based on the contour probability map and the contraband contour map;
[0088] S205: Extract the region of interest from the enhanced feature map at multiple scales to obtain the ROI feature map;
[0089] S206: Input the ROI feature map into the Optimal Distribution Transfer Module (ODTM) to fit the feature distribution of the new category, generate additional new category features, and enhance the ROI feature map with the new category features to obtain the enhanced ROI feature map;
[0090] S207: Input the enhanced ROI feature map into the detection head for detection to obtain the contraband detection map; the contraband detection map includes the target box of the contraband and the corresponding contraband type;
[0091] In this embodiment, the detection head used is an existing network structure, mainly including a regression module ( Figure 1 The “Reg.” shown) and classification module ( Figure 1 The “Cls.” shown is not improved.
[0092] S208: Optimize the parameters of the contraband detection model by calculating the loss function based on the contraband detection map and the contraband annotation map;
[0093] In this embodiment, the loss function is not improved in any way and the existing loss function is used.
[0094] S209: Repeat steps S201 to S208 to iteratively train the contraband detection model until the model converges or reaches the preset number of iterations;
[0095] S3: Output the contraband detection image as the contraband detection result of the X-ray image to be detected.
[0096] First, considering the inherent visual characteristics of X-ray images, this invention designs a contour perception module for the contour information of foreground contraband. This module focuses on estimating key contour details that describe the spatial geometry of the foreground region and effectively integrates the foreground contour information of the contraband into the feature extraction process. This enables the use of the contour information of the foreground contraband to enhance the recognizability of contraband features extracted from X-ray images. It can enhance the model's ability to capture the spatial geometry of objects and distinguish contraband features, thereby improving the model's feature recognition during feature extraction and ultimately improving the performance and accuracy of X-ray contraband detection. Secondly, this invention designs an optimal distribution transfer module based on the transferability between feature distributions of different categories. Unlike directly learning the decision boundary of a new category, this module fully utilizes the contour information of the foreground contraband and the transferability between feature distributions of different categories. It transfers the base class distribution with abundant data to the new category distribution estimated with limited data, employing an optimal transfer strategy to accurately model the feature distribution of small sample categories in small sample scenarios. This achieves the generation of additional small sample features through the transferability between feature distributions of different categories. These carefully synthesized features enable the FSXPID model to possess strong small sample learning capabilities, effectively preventing model overfitting and thus improving the model's small sample detection performance and accuracy. Finally, based on the above two modules, this invention constructs a novel FSXPID model on top of Faster R-CNN to effectively enhance the discriminative power and detection performance of contraband features. Extensive experimental results demonstrate that the method proposed in this invention significantly improves detection performance and exhibits excellent robustness.
[0097] To better illustrate the technical solution of the present invention, this embodiment is described through the following steps.
[0098] I. Backbone Network
[0099] In this embodiment, feature extraction is performed using a backbone network based on a two-stage detector, Faster R-CNN, to obtain multi-scale feature maps. The backbone network is a ResNet50 network, and its feature extraction process can be represented as follows: Where H i W i and C i F represents the feature of stage i, respectively. i Height, width, and channel dimensions.
[0100] II. Contour Awareness (CAM) Module
[0101] The applicant discovered that, due to the lack of significant texture information in X-ray images of contraband, capturing edge contours to represent the spatial geometry of the contraband during detection is particularly important. This invention proposes a contour-aware (CAM) module that utilizes features from different stages of a feature extractor to estimate the contour of the contraband. Guided by the estimated contour information, CAM adaptively fuses the spatial geometry of the contraband into the features.
[0102] CAM utilizes features from different stages of the feature extractor to estimate key contour details describing the spatial geometry of the foreground region and incorporates these details into the multi-scale feature extraction process. This module was designed to enhance the model's ability to capture detailed contour information during the backbone feature extraction stage, thereby improving the recognizability of contraband features. For example... Figure 2 As shown, CAM first adopts a structure similar to FPN, fusing features from each stage of the backbone network step by step. Then, it adaptively estimates the foreground contour probability map of the contraband item based on the fused features. Notably, CAM uses contour annotation to supervise the contour perception process during the training phase. Once the foreground contour probability map is successfully estimated, CAM embeds the corresponding contour information into the backbone features through conditional batch normalization. By enhancing the spatial geometric structure representation capability of the contraband item features, it can significantly improve subsequent detection performance.
[0103] Specifically, the processing steps for the contour perception module to generate a contour probability map are as follows:
[0104] S2031: Obtain multi-scale feature maps F i=1,2,3,4 ;
[0105] Given an X-ray image of a contraband Here, H and W represent the height and width of the image, respectively. CAM uses ResNet50 as the feature extractor. Extract the corresponding feature I from F. The feature extraction process of ResNet50 can be represented as follows: Where H i W i and C i F represents the feature of stage i, respectively. i The height, width, and channel dimensions. Considering the excessive noise contained in F0, CAM only utilizes F... i=1,2,3,4 To estimate the profile probability map C P .
[0106] S2032: Multi-scale feature maps F i=1,2,3,4 Projecting the features onto the same dimension and then performing top-down stitching and enhancement on the projected feature maps yields the contour feature map F′. i=1,2,3,4 ;
[0107] The formula is expressed as:
[0108]
[0109] The formula for projection is expressed as:
[0110]
[0111] In the formula: BL(·) represents the base layer consisting of 3×3 convolution, batch normalization and ReLU activation function; up(·) represents upsampling operation; ⊙ represents element-wise multiplication; PL(·) represents the projection layer consisting of 1×1 convolution, 3×3 convolution and ReLU activation function;
[0112] S2033: Perform a 1×1 convolution on the contour feature map F′1 to generate a contour probability map C. P .
[0113] Specifically, CAM supervises the learning process of the contour probability map through contour loss: weighted binary cross-entropy loss and weighted intersection-over-union (IoU) loss are calculated based on the contour probability map and the contraband contour map, respectively; and the weighted binary cross-entropy loss and weighted IoU loss are summed to obtain the contour loss function L. contour ;
[0114] The formula is expressed as:
[0115] L contour =L wBCE +L wIoU ,
[0116] In the formula: L wBCE L represents the weighted binary cross-entropy loss; wIoU This represents the weighted intersection-union loss. It's worth noting that CAM applies a Sobel operation to the segmentation labels of the images during the training phase to obtain the true labels for the contours.
[0117] In obtaining C P Subsequently, CAM considers embedding contour information into the multi-scale feature extraction process. In different security inspection scenarios, due to differences in the placement and orientation of items, the scale of the same contraband item in X-ray images may vary significantly. CAM uses connection operations to integrate the features F processed by the transition layer... i With features The features are then fused. The fused features are then input into another base module and combined with the features... The results are then summed. Subsequently, CAM uses a method similar to conditional batch normalization to adjust the obtained results. The adjustment parameters γ and β are passed through two different 3×3 convolutional layers from C... P The purpose of learning is to embed contour information into the representation space.
[0118] Specifically, the processing steps for the contour perception module to generate enhanced feature maps are as follows:
[0119] S2034: Multi-scale feature maps F i=1,2,3,4 The input consists of a transition layer composed of 1×1 convolutions and 3×3 convolutions, resulting in the transitioned feature map TL(F). i );
[0120] S2035: For the feature map F4 at the last scale: combine the transition-processed feature map TL(F4) and the contour probability map C P The basic modules are input together and their features are fused to obtain the enhanced feature map at the final scale.
[0121] The calculation formula for the basic module is expressed as follows:
[0122]
[0123] S2036: For feature maps F before the last scale i=1,2,3 : The feature map TL(F) after transition processing i=1,2,3 Probability profile C P and the enhanced feature map at the next scale The basic modules are input together and their features are fused to obtain the enhanced feature map at this scale.
[0124] The calculation formula for the basic module is expressed as follows:
[0125]
[0126] In the formula: [·, ·] denote the splicing operation; the adjustment parameters γ and β consist of a series of different 3×3 convolutions; This represents element-wise addition. This represents element-wise multiplication;
[0127] S2037: Obtain multi-scale enhanced feature maps through the preceding steps. and The channel dimension is uniformly set to 256.
[0128] III. Extraction of Regions of Interest
[0129] In this embodiment, multi-scale enhanced feature maps are input into the RPN network and the region of interest (ROI) alignment module (such as the ROIAlign module) to extract the region of interest (ROI) and obtain the ROI feature map F. roi Specifically, the enhanced features are input into the RPN network to obtain the ROI feature vector. The backbone features are extracted from the CAM. Based on this, The features are fed into subsequent modules of Faster R-CNN to extract regions of interest. Where B represents F roi The quantity, r represents F roi The width or height. Then, the flattened F is passed through a fully connected (FC) layer. roi Transform to d-dimensional space to generate output ROI feature maps. This embodiment uses the existing RPN network and interest feature alignment module without making any improvements.
[0130] IV. Optimal Distribution Migration (ODTM) Module
[0131] To mitigate the overfitting problem caused by limited training data, the applicant employs ODTM to more accurately model the feature distribution of new categories through cross-class distribution transfer. ODTM assumes that the feature distributions between similar categories are transferable and follow a multivariate normal distribution.
[0132] First, ODTM estimates the feature distribution of the base class with sufficient samples during the pre-training phase. During training, ODTM models the feature distribution of the new class online. However, due to data scarcity, the estimated distribution of the new class is often inaccurate. To directly calibrate these estimated distributions, ODTM computes the cost matrix between the base class and the new class distributions and evaluates the transfer path in the feature space using optimal transfer theory. Next, ODTM uses Earth Mover's Distance to solve for the minimum cost required to transfer the base class distribution to the new class distribution. By optimizing the distribution transfer from the base class to the new class, ODTM can accurately represent the new class distribution and sample more new class features from it. With these carefully synthesized features, the FSXPID model achieves powerful few-shot learning capabilities.
[0133] Existing FSXPID methods primarily learn more explicit decision boundaries to distinguish new classes by utilizing limited training data. In contrast, ODTM accurately models the feature distribution of new classes using optimal transfer theory to generate additional few-sample features, such as... Figure 3 As shown, ODTM assumes that the feature distribution of each category follows a multivariate normal distribution.
[0134] Specifically, the processing steps for generating new category features by the optimal distribution transfer module are as follows:
[0135] S2061: Based on ROI feature maps F roi New category of modeling Feature distribution
[0136] The new category is calculated using the following formula. Feature distribution
[0137]
[0138] In the formula: Represents the roi feature map F roi The i-th foreground roi feature in the image; M represents the roi feature map F. roi The number of mid-foreground ROI features. Using the calculated statistical information, ODTM models the new category. The feature distribution. However, due to the limited training data for the new category, the estimated... It can only capture a portion of the features of the true distribution of the new category.
[0139] S2062: Feature distributions of similar categories can effectively transfer between different categories. ODTM utilizes distributions from base categories with abundant samples to recalibrate inaccurate features. To achieve this goal, the basic category dataset D is obtained before fine-tuning the new categories. base Using a pre-trained network (using ResNet50 network) from the basic category dataset D base Extracting feature vectors Where f i Let f represent the feature vector corresponding to the i-th category, and N represent the total number of base categories; calculate the mean μ of each base category using f. base and the corresponding covariance matrix ∑ base To obtain the basic category Feature distribution To ensure ∑ base Maintaining positive definiteness, ODTM in ∑ base Add a small positive constant ε = 1 × 10 to the diagonal elements. -4 .
[0140] S2063: Calculate the cosine similarity between the base class and the new class in the feature space;
[0141] The cosine similarity between the base class and the new class in the feature space is calculated using the following formula:
[0142]
[0143] In the formula: d represents the cosine similarity between the mean of the j-th base category and the mean of the new category; d represents the number of base categories.
[0144] S2064: From basic categories Identify new categories The mean of the basic categories with the highest cosine similarity and its corresponding covariance matrix Then, model the base class that has the highest cosine similarity to the new class. Feature distribution
[0145] S2065: From basic categories and new categories The features of the basic category and the new category are sampled to obtain the basic category features S. base and new category features S novel ; where the basic category feature S base and new category features S novel The i-th sampling feature in the data is represented as: and m represents the number of sampling features;
[0146] S2066: Calculate the basic class features S using the Earth Mover's Distance (EMD) algorithm. base and new category features S novel Optimal transmission scheme between To minimize total transmission cost;
[0147] The optimal transmission scheme P is calculated using the following formula:
[0148]
[0149] In the formula: P ij Indicates from the basic category The i-th sampled feature is transferred to the new category. The allocation ratio of the j-th sampling feature; Representation from basic categories The i-th sampled feature is transferred to the new category. The distance cost matrix associated with the j-th sampled feature; ||·||2 represents - Norm. It's worth noting that ODTM uses the Sinkhornalgorithm to solve the optimal transfer problem described above. Overall, the ultimate goal of ODTM is to transfer the base class distribution to the new class distribution at the lowest cost while satisfying constraints.
[0150] S2067: Adjusting the new category feature S using the optimal transmission scheme P novel The new categorical feature S′ after calibration is obtained. novel ;
[0151] The formula is expressed as:
[0152]
[0153] In the formula: Represents matrix multiplication;
[0154] S2068: The calibrated new category feature S′ novel With roi feature map F roi By concatenating the features, we obtain the enhanced ROI feature map F. roi_aug ;
[0155] The formula is expressed as:
[0156] F roi_aug =[F roi MLP(S′) novel )]
[0157] In the formula: MLP represents a multilayer perceptron consisting of fully connected layers (FC) and activation functions. Meanwhile, ODTM also needs to be based on S′ novel The category of F roi_aug The corresponding classification and bounding box regression labels are used for enhancement. Therefore, ODTM can be further optimized by utilizing the guidance of category label information. roi_aug Subsequent classification and bounding box regression tasks will significantly benefit from well-learned augmented features derived from the new categories.
[0158] V. Experimental Instructions
[0159] 1. Detailed experimental parameter settings and dataset
[0160] This experiment uses Faster R-CNN as the detection framework, combined with a ResNet50 backbone network pre-trained on ImageNet. The simplified process of this invention is as follows: First, inputting an X-ray image and a contour image, features are extracted by a two-stage detector, Faster R-CNN as the main backbone ResNet50. Simultaneously, CAM is used to obtain the predicted contraband contour information, and contour loss guides the model to focus on foreground contraband features, enhancing the backbone features. Then, the enhanced features are input into the RPN network to obtain the ROI feature vector, and the ROI feature vector is input into ODTM to fit an accurate new category feature distribution, generating additional new category features, which are then fed into subsequent detection along with the original ROI feature vector. Finally, the enhanced feature vector is input into the detection head to generate the final detection map.
[0161] This experiment used an RTX 4090 GPU for training and testing, with the following parameter configuration: During optimization, stochastic gradient descent (SGD) with a momentum of 0.9 and a weight decay of 0.0001 was used, and the training batch size was set to 2. In the base class training phase, the learning rate was set to 0.0025, and training was performed for 72,000 iterations. Afterward, the last fully connected (FC) layer of the classifier head was replaced with a randomly initialized FC layer. In the new class fine-tuning phase, the learning rate was reduced by an order of magnitude after the 2,800th and 3,400th iterations, respectively, for a total of 4,000 iterations. Parameters d and λ were set to 2048 and 0.2, respectively. This invention samples 150 features for each new class from the transferred distribution.
[0162] PIDray is a recently released dataset specifically designed for the XPI task, covering various real-world scenes for detecting contraband. Furthermore, the segmentation labels in PIDray help extract the contour labels of contraband. Based on the PIDray dataset, this experiment developed a customized FSXPID dataset. Following the class partitioning settings for few-shot object detection tasks, the FSXPID dataset assigns "scissors," "wrench," "gun," "bullet," "handcuffs," "knife," and "lighter" from PIDray as basic categories, while "baton," "pliers," "hammer," and "power bank" are assigned as new categories. The FSXPID dataset contains approximately 12,000 images containing only the basic categories from the PIDray training set, used to construct D... base Subsequently, the FSXPID dataset samples k = 1, 2, 3, 5, 10 labeled instances containing only the new class from the remaining training set to construct D. novel .
[0163] To comprehensively evaluate model performance, the FSXPID dataset collected approximately 12,000 images containing basic and novel categories from the PIDray test set, serving as the test set for the FSXPID dataset. Notably, each training image in the FSXPID dataset contains only simple-type images, while the test set includes three types of images: simple, hard, and hidden. Simple images contain instances of only a single category, hard images contain instances of multiple categories, and hidden images contain contraband that is difficult to detect.
[0164] 2. Evaluation Indicators
[0165] This experiment uses nAP50 to evaluate the proposed method. nAP50 represents the average accuracy for the new class when the Intersection over Union (IoU) threshold is 0.5, and it is calculated as follows:
[0166]
[0167] AP50 refers to the average precision calculated when the IoU threshold is fixed at 0.50. μ is usually a statistical value based on the dataset or target category, used to make the performance metrics of different models more comparable. In this experiment, the nAP50 (%) of the proposed FSXPID method was calculated under different settings (1 / 2 / 3 / 5 / 10-shot). The higher the value, the better the model's performance.
[0168] 3. Experimental Comparison
[0169] On the FSXPID dataset, the method of this invention was compared with nine recent state-of-the-art and reproducible methods under different settings (1 / 2 / 3 / 5 / 10-shot), and the results are shown in Table 1. The algorithm of this invention improves upon the existing FSXPID method WEN by 11.43%. Furthermore, the method of this invention significantly outperforms FSXPID methods obtained from different combinations of methods. However, under the 1-shot setting, the method of this invention only improves upon OOS-DC by 0.98%. The applicant speculates that this limited improvement stems from the scarcity of shared attributes of the category distribution extracted from a single image. The few-shot learning performance of the method of this invention gradually improves with the increase in the number of samples. In addition, OOS-SIFT and DCP-SIFT rely on semantic embeddings to generate new category features. However, the word embeddings generated from RGB images do not match the semantics of X-ray images, which limits the effectiveness of SIFT-based methods. Overall, the experimental results show that the method of this invention is specifically designed to fully utilize the unique features of X-ray images, significantly improving the performance of contraband detection.
[0170] Table 1 shows the nAP50 (%) scores on the FSXPID dataset: best results are indicated in bold.
[0171]
[0172] 4. Ablation test
[0173] In the experiments, the proposed method was subjected to a series of ablation experiments on the FSXPID dataset to verify its effectiveness. All tables in this experiment show the best results in bold black. To verify the nAP50 (%) performance of different components on the FSXPID dataset, the ablation experiments shown in Table 2 were performed to evaluate the effects of the Contour Aware Module (CAM) and the Optimal Distribution Transmission Module (ODTM). Experimental results show that using CAM and ODTM alone helps improve detection performance in 1 / 2 / 3 / 5 / 10-shot settings. Notably, using CAM alone failed to significantly improve performance in 1-shot and 2-shot settings, which may be attributed to the impact of limited training data on model performance. However, using ODTM alone improved detection performance by 1.57% to 5.58% in different shot settings. Furthermore, the combination of CAM and ODTM consistently resulted in a more significant performance improvement. The results in Table 2 demonstrate the effectiveness of these two modules in improving model detection performance.
[0174] Table 2. nAP50 (%) performance of different components on the FSXPID dataset
[0175]
[0176] To evaluate the effectiveness of different supervised images used in CAM, the ablation experiments shown in Table 3 were conducted. In the first row of Table 3, the present invention applied the Sobel operator to extract edges from the entire image and used them as supervised signals. In the second row of Table 3, the present invention only utilized edge information from the foreground region to supervise the training process. Experimental results show that background noise in the image edges significantly affects edge supervision and hinders the extraction of effective features. Using only foreground edges as supervised signals significantly improves the model's detection capability. However, some foreground regions are still partially occluded by the background and are still subject to noise interference. To further optimize the learning process, the present invention utilizes the clear outline information of the foreground contraband as supervised signals. CAM achieved optimal feature extraction performance under 1 / 2 / 3 / 5 / 10-shot settings.
[0177] Table 3. nAP50 (%) performance of different supervision signals used in CAM on the FSXPID dataset.
[0178]
[0179] To evaluate the effectiveness of different distribution modeling strategies used in ODTM, the ablation experiments shown in Table 4 were conducted. Online modeling in Table 4 refers to directly modeling the distribution of the new class during the new class fine-tuning stage, while DC represents modeling the distribution of the new class using the distribution statistics of the base classes. The new class distribution obtained through online modeling is inaccurately estimated due to data scarcity, thus limiting the performance of few-sample learning.
[0180] While DC improves performance through calibration using distribution statistics, its performance may be limited by the low semantic correlation between prohibited item categories. This invention directly transfers the distribution of the basic category to the distribution of the new category via an optimal path. This transfer makes the distribution representation of the new category more accurate and significantly improves small-sample detection performance.
[0181] Table 4. nAP50 (%) performance of different distribution modeling strategies used in ODTM on the FSXPID dataset.
[0182]
[0183] This invention evaluated the effect of different scaling factors λ using the ablation experiments shown in Table 5. According to the experimental results in the table, when λ = 0.2, nAP50 consistently exhibits the highest detection performance under 1 / 2 / 3 / 5 / 10-shot settings. Increasing or decreasing the scaling factor leads to a decrease in detection performance. The trend in Table 5 shows a decreasing performance pattern centered around λ = 0.2. Therefore, this invention sets λ = 0.2 as the optimal scaling factor.
[0184] Table 5. nAP50 (%) performance on the FSXPID dataset with different scaling factors λ
[0185]
[0186] To evaluate the impact of different contour supervision losses, the ablation experiments shown in Table 6 were performed in this invention. The cross-entropy loss L, widely used in segmentation tasks, is employed. bce and the mean squared error loss L in regression tasks contour All showed limited performance improvements. Furthermore, this invention utilizes L... tversky This method is commonly used in medical X-ray imaging to effectively improve detection performance. Meanwhile, the applicant used L... contour This enhances the perception of contour information and alleviates the imbalance in proportion between foreground and background pixels. Ablation experiments demonstrate that L... contour The effectiveness.
[0187] Table 6. nAP50 (%) performance of different contour supervision losses on the FSXPID dataset.
[0188]
[0189] This invention evaluated the effect of different sampling numbers for novel feature categories through ablation experiments, and the experimental results are shown in Table 7. In the 5-shot and 10-shot settings, the detection performance peaked when the sampling number was 100, while the detection performance was relatively low in the 1-shot, 2-shot, and 3-shot settings. Increasing the sampling number to 150 significantly improved the performance of the 1-shot, 2-shot, and 3-shot settings, while the 5-shot and 10-shot settings maintained good detection performance. However, performance decreased significantly when the sampling number exceeded 150. These results indicate that moderately increasing the sample number helps improve detection capability. Therefore, this experiment concludes that a sample number of 150 is optimal.
[0190] Table 7. nAP50 (%) performance on the FSXPID dataset with different numbers of sampled features.
[0191]
[0192] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit the technical solutions. Those skilled in the art should understand that any modifications or equivalent substitutions to the technical solutions of the present invention without departing from the spirit and scope of the present invention should be covered within the scope of the claims of the present invention.
Claims
1. A method for detecting contraband via X-ray based on contour perception and optimal distribution migration, characterized in that, include: S1: Acquire the X-ray image to be detected; S2: Input the X-ray image to be detected into the trained contraband detection model and output the corresponding contraband detection image; The steps for training a contraband detection model are as follows: S201: Obtain X-ray images used as training samples, as well as corresponding contraband outlines and contraband annotations; S202: Input the X-ray image into the backbone network for feature extraction to obtain multi-scale feature maps; S203: Input the multi-scale feature map into the contour perception module to estimate the contour information of the contraband and obtain the contour probability map; and enhance the multi-scale feature map through the contour probability map to obtain the multi-scale enhanced feature map. S204: Optimize the parameters of the contour perception module by calculating the contour loss function based on the contour probability map and the contraband contour map; S205: Extract the region of interest from the enhanced feature map at multiple scales to obtain the ROI feature map; S206: Input the ROI feature map into the optimal distribution transfer module to fit the feature distribution of the new category and generate additional new category features; The ROI feature map is then enhanced using new category features to obtain the enhanced ROI feature map; In step S206, the processing steps for the optimal distribution transfer module to generate new category features are as follows: S2061: Based on ROI feature maps F roi New category of modeling Feature distribution S2062: Obtain the basic category dataset D base From the basic category dataset D base Extracting feature vectors Where f i Let f represent the feature vector corresponding to the i-th category, and N represent the total number of base categories; calculate the mean μ of each base category using f. base and the corresponding covariance matrix ∑ base To obtain the basic category Feature distribution S2063: Calculate the cosine similarity between the base class and the new class in the feature space; S2064: From basic categories Identify new categories The mean of the basic categories with the highest cosine similarity and its corresponding covariance matrix Then, model the base class that has the highest cosine similarity to the new class. Feature distribution S2065: From basic categories and new categories The features of the basic category and the new category are sampled to obtain the basic category features S. base and new category features S novel ; where the basic category feature S base and new category features S novel The i-th sampling feature in the data is represented as: and m represents the number of sampling features; S2066: Calculate basic category features S using the Earth movement distance algorithm. base and new category features S novel Optimal transmission scheme between S2067: Adjusting the new category feature S using the optimal transmission scheme P novel The new categorical feature S′ after calibration is obtained. novel ; The formula is expressed as: In the formula: Represents matrix multiplication; S2068: The calibrated new category feature S′ novel With roi feature map F roi By concatenating the features, we obtain the enhanced ROI feature map F. roi_aug ; The formula is expressed as: F roi_aug =[F roi ,MLP(S′ novel )], In the formula: MLP represents a multilayer perceptron consisting of fully connected layers and activation functions; S207: Input the enhanced ROI feature map into the detection head for detection to obtain the contraband detection map; the contraband detection map includes the target box of the contraband and the corresponding contraband type; S208: Optimize the parameters of the contraband detection model by calculating the loss function based on the contraband detection map and the contraband annotation map; S209: Repeat steps S201 to S208 to iteratively train the contraband detection model until the model converges or reaches the preset number of iterations; S3: Output the contraband detection image as the contraband detection result of the X-ray image to be detected.
2. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 1, characterized in that: In step S202, feature extraction is performed using a backbone network based on the two-stage detector Faster RCNN to obtain multi-scale feature maps.
3. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 1, characterized in that: In step S203, the processing steps for the contour perception module to generate the contour probability map are as follows: S2031: Obtain multi-scale feature maps F i=1,2,3,4 ; S2032: Multi-scale feature maps F i=1,2,3,4 Projecting the features onto the same dimension and then performing top-down stitching and enhancement on the projected feature maps yields the contour feature map F′. i=1,2,3,4 ; The formula is expressed as: The formula for projection is expressed as: In the formula: BL(·) represents the base layer consisting of 3×3 convolution, batch normalization and ReLU activation function; up(·) represents upsampling operation; ⊙ represents element-wise multiplication; PL(·) represents the projection layer consisting of 1×1 convolution, 3×3 convolution and ReLU activation function; S2033: Perform a 1×1 convolution on the contour feature map F′1 to generate a contour probability map C. P .
4. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 3, characterized in that: In step S203, the processing steps for the contour perception module to generate enhanced feature maps are as follows: S2034: Multi-scale feature maps F i=1,2,3,4 The input consists of a transition layer composed of 1×1 convolutions and 3×3 convolutions, resulting in the transitioned feature map TL(F). i ); S2035: For the feature map F4 at the last scale: combine the transition-processed feature map TL(F4) and the contour probability map C P The basic modules are input together and their features are fused to obtain the enhanced feature map at the final scale. The calculation formula for the basic module is expressed as follows: S2036: For feature maps F before the last scale i=1,2,3 : The feature map TL(F) after transition processing i=1,2,3 Probability profile C P and the enhanced feature map at the next scale The basic modules are input together and their features are fused to obtain the enhanced feature map at this scale. The calculation formula for the basic module is expressed as follows: In the formula: [·, ·] denote the splicing operation; the adjustment parameters γ and β consist of a series of different 3×3 convolutions; This represents element-wise addition. This represents element-wise multiplication; S2037: Obtain multi-scale enhanced feature maps through the preceding steps.
5. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 1, characterized in that: In step S204, the weighted binary cross-entropy loss and the weighted cross-union ratio loss are calculated based on the profile probability map and the contraband profile map, respectively; and the weighted binary cross-entropy loss and the weighted cross-union ratio loss are summed to obtain the profile loss function L. contour ; The formula is expressed as: L contour L wBCE +L wIoU , In the formula: L wBCE L represents the weighted binary cross-entropy loss; wIOU This indicates the weighted average loss.
6. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 1, characterized in that: In step S205, the multi-scale enhanced feature map is input into the RPN network and the region of interest alignment module to extract the region of interest and obtain the ROI feature map.
7. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 1, characterized in that: In step S2061, the new category is calculated using the following formula. Feature distribution In the formula: Represents the roi feature map F roi The i-th foreground roi feature in the data; M represents the roi feature map F roi The number of mid-foreground ROI features.
8. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 1, characterized in that: In step S2063, the cosine similarity between the base category and the new category in the feature space is calculated using the following formula: In the formula: d represents the cosine similarity between the mean of the j-th base category and the mean of the new category; d represents the number of base categories.
9. The X-ray contraband detection method based on contour perception and optimal distribution migration as described in claim 1, characterized in that: In step S2066, the optimal transmission scheme P is calculated using the following formula: In the formula: P ij Indicates from the basic category The i-th sampled feature is transferred to the new category. The allocation ratio of the j-th sampling feature; Representation from basic categories The i-th sampled feature is transferred to the new category. The distance cost matrix associated with the j-th sampled feature; ||·||2 represents - Norm.
Citation Information
Patent Citations
Multi-scale target detection model method based on metric learning
CN111652216A
Security check contraband detection method based on multi-scale attention and data enhancement
CN116883933A