Dangerous goods long tail detection method and system based on sparse dictionary and component reconstruction
Patent Information
- Application Number
- CN202611362285.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-03
- Publication Date
- 2026-10-23
AI Technical Summary
现有的基于全图分类或目标检测的算法,一旦物体不完整,往往直接判定为“非危险品”,导致严重的漏检
[0047]本发明方法及系统的有益效果是:本发明通过构建已标注的危险品图像块集合,通过K奇异值分解算法进行过完备字典的训练学习,生成几何原子字典,通过字典无法完美重构的区域自动发现潜在危险品,无需事先知道所有危险品形态,进而将危险品抽象为几何基元组合,具备跨类别泛化能力;引入三元组损失与噪声对比估计损失,构建编码器网络模型;通过编码器网络模型对待检测图像进行编码处理,结合几何原子字典进行图像重构,并对重构结构进行自适应阈值分割处理,确定待检测图像中的危险物品区域,通过部件间的空间关系图匹配,实现对拆解物品的识别,在原始拓扑结构匹配能力之上增加节点多维度属性约束,通过回溯剪枝策略完成待检测目标拓扑图与危险品标准模式库的相似度匹配,输出节点映射关系与匹配置信度,为后续风险分级决策提供量化依据;根据待检测图像中的危险物品区域,构建检测属性图,并与自定义的危险品模式库进行图结构匹配与决策,得到危险物品长尾检测结果,能够提高危险物品的检测精度。
Smart Images

Figure CN122967066A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of long-tail detection technology for articles, and in particular to a method and system for long-tail detection of hazardous articles based on sparse dictionaries and component reconstruction. Background Technology
[0002] During deep learning model training, there are abundant samples of common items (such as mobile phones, laptops, and books), but very few samples of dangerous items (such as homemade explosives, prohibited knives, and gun parts), and these samples vary greatly in shape. This results in high accuracy for head categories (common items) but extremely low accuracy for tail categories (rare dangerous items). Dangerous items are often disassembled into small parts and placed separately, or they may be obscured by other luggage. Existing algorithms based on full-image classification or object detection often directly classify incomplete objects as "non-dangerous," leading to serious missed detections.
[0003] In related technologies, current general object detection relies on data-driven deep learning models that require a large number of labeled complete object samples for training. This allows them to learn only the object morphological features covered in the training set. When object morphology is incomplete or the number of samples is insufficient, the model cannot fully learn the effective features of the target, resulting in a significant decrease in generalization ability and a marked deterioration in detection performance. Current full-image classification algorithms primarily output class probabilities for the entire image. Operations such as global average pooling in their network structure erase spatial location information of objects, thus lacking object localization capabilities. Furthermore, the model learns the global semantic features of complete objects; when target parts are missing, the global features become severely biased, causing the model to fail to correctly identify and classify them. For current few-shot learning, the core of the MAML class meta-learning algorithm is to obtain quickly adaptable features through meta-training. The initial parameters for a new task are highly dependent on the task distribution during the meta-training phase for generalization ability. When the morphological differences of hazardous materials exceed the coverage of the meta-training task, the model cannot quickly adapt to new morphological features with a small number of samples. At the same time, the effective features that the model can learn in small sample scenarios are limited, making it difficult to cover large-scale morphological changes, ultimately leading to insufficient generalization ability. For traditional feature matching, such as SIFT, ORB and other traditional handcrafted feature algorithms, the core is the extraction and matching of low-level visual features such as gray-level gradient, corner points, and texture of the image. However, the imaging principle of X-ray images is to record the attenuation of X-rays passing through the object. The core information is the density difference of the object. Images generally have the characteristics of missing texture, smooth gray-level changes, and blurred edges. Traditional algorithms cannot effectively extract and represent key discriminative features based on density, resulting in a significant decrease in matching and recognition performance. Summary of the Invention
[0004] To address the aforementioned technical problems, the purpose of this invention is to provide a method and system for detecting long-tailed hazardous materials based on sparse dictionaries and component reconstruction, which can improve the detection accuracy of hazardous materials.
[0005] The first technical solution adopted in this invention is: a long-tail detection method for hazardous materials based on sparse dictionaries and component reconstruction, comprising the following steps:
[0006] A set of labeled hazardous material image patches is constructed, and an overcomplete dictionary is trained and learned using the K-singular value decomposition algorithm to generate a geometric atom dictionary;
[0007] We introduce triplet loss and noise contrast estimation loss to construct an encoder network model;
[0008] The image to be detected is encoded using an encoder network model, and then reconstructed using a geometric atom dictionary. Adaptive threshold segmentation is then applied to the reconstructed structure to determine the hazardous material regions in the image to be detected.
[0009] Based on the hazardous material regions in the image to be detected, a detection attribute graph is constructed, and graph structure matching and decision-making are performed with a custom hazardous material pattern library to obtain the long-tail detection results of hazardous materials.
[0010] Furthermore, the step of constructing a set of labeled hazardous material image patches and training an overcomplete dictionary using the K-singular value decomposition algorithm to generate a geometric atom dictionary specifically includes:
[0011] Construct a set of labeled hazardous materials image patches;
[0012] Based on the set of labeled hazardous material image patches, the objective function is constructed by synchronously iteratively optimizing the overcomplete dictionary and sparse coefficient matrix. The objective function is based on minimizing the image feature reconstruction error, and is superimposed with an L1 sparse regularization term to constrain the sparsity of the sparse coefficients of a single sample, and the constraint conditions are set.
[0013] Based on a two-stage alternating iterative solution strategy, the objective function is solved using the K-singular value decomposition algorithm to obtain the optimized dictionary feature fit.
[0014] Based on the adaptiveness of the optimized dictionary features, the training and learning of the overcomplete dictionary specifically for the dangerous goods image patch set is iteratively optimized to generate a geometric atom dictionary.
[0015] Furthermore, the step of solving the objective function using the K-singular value decomposition algorithm based on a two-stage alternating iterative solution strategy to obtain the optimized dictionary feature fit specifically includes:
[0016] The objective function is solved iteratively by using an alternating iterative strategy. The current overcomplete dictionary is fixed, and the optimal sparse coefficient vector corresponding to each set of dangerous goods image blocks is solved one by one by the orthogonal matching pursuit algorithm to construct the sparse coefficient matrix.
[0017] Based on the sparse coefficient matrix, with all sparse coefficients fixed, the K-singular value decomposition algorithm is used to update and iterate each atom in the dictionary one by one to obtain the optimized dictionary feature fit.
[0018] Furthermore, the encoder network model specifically includes an input layer, a first convolutional pooling module, a second convolutional pooling module, a third convolutional pooling module, a global average pooling layer, and a fully connected output layer. The input layer, the first convolutional pooling module, the second convolutional pooling module, the third convolutional pooling module, the global average pooling layer, and the fully connected output layer are connected sequentially. The first convolutional pooling module, the second convolutional pooling module, and the third convolutional pooling module all include a convolutional layer, a batch normalization layer, a modified linear unit, and a max pooling layer. The loss function of the encoder network model includes triplet loss and noise contrast estimation loss.
[0019] Furthermore, the step of encoding the image to be detected using an encoder network model, reconstructing the image using a geometric atom dictionary, and performing adaptive threshold segmentation on the reconstructed structure to determine the hazardous material region in the image to be detected specifically includes:
[0020] The image to be detected is acquired and encoded using an encoder network model to obtain sparse coding.
[0021] Based on sparse coding, with the L0 norm as the sparse constraint, the orthogonal matching pursuit algorithm is used to solve for the optimal sparse coefficient vector;
[0022] The reconstruction result of the image patch is obtained by linearly combining the optimal sparse coefficient vector with the geometric atom dictionary;
[0023] The reconstruction results of the image to be detected and the image patch are calculated by difference to obtain the reconstruction residual vector and construct the pixel absolute residual map;
[0024] The Otsu method adaptive thresholding algorithm is used to perform adaptive thresholding segmentation on the pixel absolute residual map to determine the dangerous item region in the image to be detected.
[0025] Furthermore, the step of using Otsu's adaptive thresholding algorithm to perform adaptive thresholding segmentation on the pixel absolute residual map to determine the hazardous material region in the image to be detected specifically includes:
[0026] Traverse all candidate thresholds corresponding to the gray levels of all pixels in the absolute residual image, and divide the pixels into low residual background regions and high residual dangerous foreground regions based on the thresholds;
[0027] The pixel proportion and pixel variance of the low residual background region and the high residual dangerous foreground region are calculated respectively. A weighted intra-class variance objective function is constructed, and the threshold that minimizes the overall intra-class variance is selected as the candidate segmentation threshold.
[0028] Based on the weighted intra-class variance objective function, all candidate segmentation thresholds are traversed, and the minimum intra-class variance is solved to obtain the optimal adaptive threshold that fits the absolute residual map of the current pixel.
[0029] The optimal adaptive threshold is applied to the pixel absolute residual map to perform binary segmentation and determine the dangerous item region in the image to be detected.
[0030] Furthermore, the step of constructing a detection attribute graph based on the hazardous material regions in the image to be detected, and performing graph structure matching and decision-making with a custom hazardous material pattern library to obtain the long-tail detection results of hazardous materials, specifically includes:
[0031] Construct a detection attribute map based on the hazardous material regions in the image to be detected;
[0032] Build a custom hazardous materials pattern library and match it with the detection attribute graph, outputting the matching identifier and matching confidence value;
[0033] Based on the matching identifiers, the types of hazardous materials are determined, and based on the matching confidence values, the preset hazard levels are divided to obtain the long-tail detection results of hazardous materials.
[0034] Furthermore, the step of constructing a detection attribute map based on the hazardous material regions in the image to be detected specifically includes:
[0035] The hazardous material regions in the image to be detected are used as graph nodes, and each graph node carries four attributes: atom type, location coordinates, region size, and detection confidence.
[0036] The spatial relationship between any two hazardous material areas is used as a graph edge, and each graph edge carries three attributes: center distance, relative angle, and spatial topological relationship.
[0037] By combining graph nodes and graph edges, a detection attribute graph is constructed.
[0038] Furthermore, the step of constructing a custom hazardous materials pattern library, matching it with the detection attribute graph, and outputting the matching identifier and matching confidence value specifically includes:
[0039] Construct a custom hazardous materials pattern library, which stores standard topology template diagrams corresponding to various hazardous materials;
[0040] Based on the hazardous materials pattern library and combined with the detection attribute graph, the improved VF2++ subgraph isomorphism algorithm is used for matching. Four types of constraints are applied during the matching process, and graph nodes that do not meet the four types of constraints are pruned to obtain target candidate node pairs.
[0041] All candidate node pairs are traversed through a depth-first backtracking search. After the search terminates, the matching identifier and matching confidence value are output.
[0042] The second technical solution adopted in this invention is: a long-tail detection system for hazardous materials based on sparse dictionaries and component reconstruction, comprising:
[0043] The first module is used to construct a set of labeled hazardous material image blocks, and to generate a geometric atom dictionary by training an overcomplete dictionary through the K-singular value decomposition algorithm.
[0044] The second module is used to introduce triplet loss and noise contrast estimation loss to construct the encoder network model.
[0045] The third module is used to encode the image to be detected through the encoder network model, reconstruct the image by combining the geometric atom dictionary, and perform adaptive threshold segmentation on the reconstructed structure to determine the dangerous item region in the image to be detected.
[0046] The fourth module is used to construct a detection attribute graph based on the hazardous material regions in the image to be detected, and to perform graph structure matching and decision-making with a custom hazardous material pattern library to obtain long-tail detection results for hazardous materials.
[0047] The beneficial effects of the method and system of this invention are as follows: This invention constructs a set of labeled hazardous material image blocks, trains an overcomplete dictionary using the K-singular value decomposition algorithm to generate a geometric atom dictionary, and automatically discovers potential hazardous materials in areas that cannot be perfectly reconstructed by the dictionary, without needing to know all the forms of hazardous materials in advance. Furthermore, it abstracts hazardous materials into combinations of geometric primitives, possessing cross-class generalization ability. It introduces triplet loss and noise contrast estimation loss to construct an encoder network model. The encoder network model encodes the image to be detected, combines it with the geometric atom dictionary for image reconstruction, and applies adaptive thresholding to the reconstructed structure. The process involves segmentation to identify hazardous material regions in the image to be detected. Spatial relationship graph matching between components enables the identification of disassembled items. Building upon the original topology matching capability, multi-dimensional attribute constraints on nodes are added. A backtracking pruning strategy is used to match the similarity between the topology graph of the target and the standard hazardous material pattern library, outputting node mapping relationships and matching confidence scores to provide quantitative basis for subsequent risk classification decisions. Based on the hazardous material regions in the image to be detected, a detection attribute graph is constructed and matched with a custom hazardous material pattern library to obtain long-tail detection results for hazardous materials, thereby improving the detection accuracy. Attached Figure Description
[0048] Figure 1 This is a flowchart of the steps of the long-tail detection method for hazardous materials based on sparse dictionary and component reconstruction of the present invention;
[0049] Figure 2 This is a structural block diagram of the long-tail detection system for hazardous materials based on sparse dictionary and component reconstruction of the present invention;
[0050] Figure 3 This is a schematic diagram of the overall framework for long-tail detection of hazardous materials provided in a specific embodiment of the present invention;
[0051] Figure 4 This is a schematic diagram of the twin encoder structure provided in a specific embodiment of the present invention;
[0052] Figure 5 This is a schematic diagram of the encoder network structure provided in a specific embodiment of the present invention. Detailed Implementation
[0053] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments. The step numbers in the following embodiments are only for ease of explanation and do not limit the order of the steps. The execution order of each step in the embodiments can be adapted according to the understanding of those skilled in the art.
[0054] Reference Figure 1 This invention provides a long-tail detection method for hazardous materials based on sparse dictionaries and component reconstruction. The method includes the following steps:
[0055] S100. Construct a set of labeled hazardous material image blocks, and train an overcomplete dictionary using the K-singular value decomposition algorithm to generate a geometric atom dictionary;
[0056] S110. Construct a set of labeled hazardous materials image blocks;
[0057] In this embodiment, a small set of labeled hazardous material image patches is given. .
[0058] First, raw data is collected by acquiring raw X-ray images of various common hazardous materials from security inspection equipment. These images cover hazardous material samples of varying shapes and degrees of damage / obstruction, adapting to the complex imaging conditions of actual security inspection scenarios. Further data preprocessing and annotation are performed, including standardization preprocessing such as denoising and grayscale normalization of the raw X-ray images. Professional annotators accurately annotate the effective areas of hazardous materials in the images, distinguishing the core areas of complete and damaged hazardous materials. Finally, image patch extraction and dataset generation are conducted. Based on the annotation results, image patches containing the effective areas of hazardous materials are cropped, and the size and resolution of the image patches are standardized. Invalid and blurry samples are removed, ultimately constructing an annotated hazardous material image patch dataset.
[0059] S120. Based on the set of labeled hazardous material image blocks, synchronous iterative optimization of the overcomplete dictionary and sparse coefficient matrix is used as the solution direction to construct an objective function. The objective function takes the minimization of image feature reconstruction error as the basic term, superimposed with L1 sparse regularization term to constrain the sparsity of single sample sparse coefficients, and sets constraint conditions.
[0060] In this embodiment, the K-Singular Value Decomposition (K-SVD) algorithm is used to learn an overcomplete dictionary for hazardous materials images. The core objective of dictionary learning is to construct an overcomplete dictionary. This allows each image patch corresponding to a hazardous material image to be approximately represented by a linear combination of a small number of atoms in the dictionary. This optimization process can be abstracted as a minimization optimization problem with L1 sparse constraints.
[0061] For a given set of training image patches This embodiment synchronously iteratively optimizes the complete dictionary. With sparse coefficient matrix Under the premise of minimizing the image feature reconstruction error, a sparsity constraint is applied to the sparse coefficients corresponding to a single sample, and finally the optimal dictionary that fits the feature representation of hazardous materials is obtained. The corresponding objective function expression is as follows:
[0062]
[0063] Constraints:
[0064]
[0065] The parameters in the above formula are defined as follows: Indicates the first One input hazardous materials image block, for 3D column vector, This represents an overcomplete dictionary to be learned, where the number of dictionary atoms K is greater than the feature dimension of the image patch. , This represents the sparse coefficient vector corresponding to the i-th hazardous material image patch. The sparse coefficient vectors of all samples together constitute the sparse coefficient matrix. , Overcomplete dictionary The first in List the dictionary atoms and, by constraining the L2 norm of these atoms to 1, eliminate the scaling ambiguity between the dictionary and the sparse coefficients. This represents the sparse regularization hyperparameter, used to balance the feature reconstruction loss of hazardous materials images with the strength of sparse constraints. By adjusting this parameter, the number of non-zero elements in the sparse coefficients can be controlled, achieving the goal of representing hazardous materials image features with a small number of dictionary atoms.
[0066] S130. Based on a two-stage alternating iterative solution strategy, the objective function is solved using the K singular value decomposition algorithm to obtain the optimized dictionary feature fit.
[0067] Specifically, the objective function is solved iteratively using an alternating iterative strategy. The current overcomplete dictionary is fixed, and the optimal sparse coefficient vector corresponding to the set of dangerous goods image blocks is solved one by one using the orthogonal matching pursuit algorithm to construct a sparse coefficient matrix. Based on the sparse coefficient matrix, all sparse coefficients are fixed, and each atom in the dictionary is updated iteratively using the K singular value decomposition algorithm to obtain the optimized dictionary feature fit.
[0068] S140. Based on the adaptiveness of the optimized dictionary features, iteratively optimize the training and learning of the overcomplete dictionary dedicated to the dangerous goods image block set, and generate a geometric atom dictionary.
[0069] In this embodiment, during the optimization and solution phase, an alternating iteration strategy is used to solve the objective function: the first phase fixes the dictionary. The optimal sparse coefficient vector corresponding to each image patch is solved by the Orthogonal Matching Pursuit (OMP) algorithm. The second stage fixes all sparse coefficients and updates each atom in the dictionary one by one through singular value decomposition. The two stages are repeated alternately until the iteration termination condition is met, and finally the training and learning of the overcomplete dictionary for hazardous materials is completed.
[0070] Furthermore, the dictionary atom type definitions in this embodiment are shown in Table 1:
[0071] Table 1. Definition of dictionary atomic types
[0072] tubular structure Slender, hollow, uniform diameter Barrel, battery casing, metal tube Sharp edges Straight / curved edges, abrupt change angles blade, saw blade, nail High-density blocks High X-ray density, compact shape Metal block, detonator, trigger assembly L-shaped connection 90-degree or approximately 90-degree connection Frame structure, weapon grip Composite shape Multiple irregular connections Circuit boards, complex devices
[0073] S200. Introduce triplet loss and noise comparison estimation loss to construct encoder network model;
[0074] Specifically, the encoder network model includes an input layer, a first convolutional pooling module, a second convolutional pooling module, a third convolutional pooling module, a global average pooling layer, and a fully connected output layer. The input layer, the first convolutional pooling module, the second convolutional pooling module, the third convolutional pooling module, the global average pooling layer, and the fully connected output layer are connected sequentially. The first convolutional pooling module, the second convolutional pooling module, and the third convolutional pooling module all include a convolutional layer, a batch normalization layer, a modified linear unit, and a max pooling layer. The loss function of the encoder network model includes triplet loss and noise contrast estimation loss.
[0075] First, construct the twin encoder structure, such as Figure 4 As shown, it can generalize to unlabeled or poorly labeled port data, enabling the model to learn to map fragments in security images to corresponding atoms in the dictionary.
[0076] Training a Siamese encoder requires designing a suitable loss function that ensures feature vectors of similar image patches (positive sample pairs) are close to each other in the embedding space, while feature vectors of dissimilar image patches (negative sample pairs) are far apart. Two loss function forms can be used: the classic Triplet Loss, which uses the anchor sample as the center, bringing it closer to positive samples and pushing it further away from negative samples; and an enhanced version, InfoNCE Loss (Noise Contrast Estimation Loss), which uses normalized cross-entropy loss to distinguish positive sample pairs from a large number of negative samples during batch training.
[0077] The specific definitions of the two loss functions are as follows:
[0078] The Triplet Loss form is as follows:
[0079]
[0080] The enhanced InfoNCE Loss format is as follows:
[0081]
[0082] In the above formula, The encoded vector representing the anchor image patch. This represents a positive encoding vector similar to the anchor point. This represents the encoding vector that is different from the anchor point (Negative). This represents the interval threshold, typically set to 0.5. Represents cosine similarity. This represents the temperature parameter, which is usually set to 0.1.
[0083] Finally, the encoder structure is as follows: Figure 5 As shown in the figure and Table 2:
[0084] Table 2 Encoder Network Structure Data Table
[0085] enter - - - 64×64×1 Conv + BN + ReLU 3×3 1 32 64×64×32 MaxPool 2×2 2 - 32×32×32 Conv + BN + ReLU 3×3 1 64 32×32×64 MaxPool 2×2 2 - 16×16×64 Conv + BN + ReLU 3×3 1 128 16×16×128 MaxPool 2×2 2 - 8×8×128 Global Avg Pool - - - 1×1×128 Fully connected - - 128 128-dimensional feature vector
[0086] S300: The image to be detected is encoded using an encoder network model, and the image is reconstructed using a geometric atom dictionary. The reconstructed structure is then subjected to adaptive threshold segmentation to determine the hazardous material region in the image to be detected.
[0087] In this embodiment, for the image to be detected and its local image patches After obtaining the latent space features through encoder E mapping, this paper employs the Orthogonal Matching Pursuit (OMP) algorithm to solve the sparse coding of image patches. This algorithm uses an overcomplete dictionary... Image blocks to be encoded The output vector consists of sparse coefficients whose dimensions match the number of atoms in the dictionary, taking a preset maximum sparsity T as input. The specific execution process is as follows: First, the residual vector... Initialize as raw image patch The support set S is initialized to an empty set. Then, the algorithm iterates up to T times: in each iteration, the dictionary atom with the largest absolute value of the inner product with the current residual is selected from the overcomplete dictionary, and its corresponding index is added to the support set. Based on the atoms contained in the current support set, the optimal sparse coefficient estimate is obtained using the least squares method. Finally, this set of coefficients is used to reconstruct the image patch and update the residual vector. The operation terminates after reaching the preset number of sparse iterations, and the sparse coefficient vector is output. The vector takes non-zero values only in the T dimensions corresponding to the support set, and the coefficients of the other dimensions are all 0, thus satisfying the sparse constraint condition.
[0088] S310. Acquire the image to be detected and encode it using an encoder network model to obtain sparse coding.
[0089] S320. Based on sparse coding, with the L0 norm as the sparse constraint, the orthogonal matching pursuit algorithm is used to solve for the optimal sparse coefficient vector.
[0090] In this embodiment, sparse coding can reconstruct image patches based on a known sample dictionary. The residual between the original image patch and the reconstructed image patch can locate abnormal regions that do not match the prior distribution of the dictionary, corresponding to the locations of potential hazardous items in the scenario described in this paper. This process consists of three steps: sparse coding, image patch reconstruction, and residual map generation. First, sparse coding is performed on a given d-dimensional image patch (… ), an overcomplete dictionary containing K atoms In this embodiment, an L0-constrained sparse optimization model is used to solve for the optimal sparse coefficients. :
[0091]
[0092] This optimization problem can be solved efficiently using the Orthogonal Matching Pursuit (OMP) algorithm.
[0093] S330. Perform a linear combination calculation on the optimal sparse coefficient vector and the geometric atom dictionary to obtain the image patch reconstruction result;
[0094] In this embodiment, the reconstructed image patch utilizes the obtained optimal sparse coefficients and an overcomplete dictionary to achieve linear reconstruction of the original image patch, the expression of which is:
[0095]
[0096] In the above formula, This indicates a complete dictionary. This represents the image block to be encoded.
[0097] S340. Perform differential calculation on the reconstruction results of the image to be detected and the image patch to obtain the reconstruction residual vector and construct the pixel absolute residual map;
[0098] In this embodiment, the reconstruction residual is calculated by subtracting the original image patch from the reconstructed image patch to obtain the reconstruction residual vector:
[0099]
[0100] The overall reconstruction error can be measured by the L2 norm of the residuals.
[0101] To achieve pixel-level anomaly region localization, a pixel-level absolute residual map is constructed:
[0102]
[0103] The larger the residual value at a pixel location, the lower the matching degree between the image content in that area and the dictionary prior, and the higher the probability of it being identified as a dangerous item.
[0104] S350. Using the Otsu method's adaptive thresholding algorithm, adaptive thresholding segmentation is performed on the pixel absolute residual map to determine the hazardous material region in the image to be detected.
[0105] Specifically, the process iterates through all candidate thresholds corresponding to the gray levels of all pixels in the pixel absolute residual image, and divides the pixels into low residual background regions and high residual dangerous foreground regions based on the thresholds. The pixel proportion and pixel variance of the low residual background regions and high residual dangerous foreground regions are calculated respectively, and a weighted intra-class variance objective function is constructed. The threshold that minimizes the overall intra-class variance is selected as the candidate segmentation threshold. Based on the weighted intra-class variance objective function, all candidate segmentation thresholds are iterated through, and the minimum intra-class variance is solved to obtain the optimal adaptive threshold that fits the current pixel absolute residual image. The optimal adaptive threshold is applied to the pixel absolute residual image to perform binary segmentation and determine the dangerous item regions in the image to be detected.
[0106] In this embodiment, after the residual map is generated, a segmentation threshold needs to be set to distinguish between normal background areas and abnormal areas of dangerous items. Using a fixed threshold is susceptible to interference from lighting, imaging noise, and image texture, resulting in poor segmentation robustness. Therefore, this solution introduces Otsu's adaptive thresholding algorithm to automatically select the optimal threshold for the residual map. This algorithm requires no manual parameter preset; it uses the grayscale values of all pixels in the residual map as statistical samples, achieving adaptive segmentation of the foreground and background by maximizing inter-class variance and minimizing intra-class variance.
[0107] Iterate through all pixel grayscale values in the residual image to find the candidate threshold. Based on a threshold, pixels are divided into two categories: low residual background regions and high residual dangerous foreground regions. The pixel proportion and pixel variance of each category are calculated. A weighted intra-class variance objective function is constructed, and the threshold that minimizes the overall intra-class variance is selected as the optimal segmentation threshold. The specific calculation formula is as follows:
[0108]
[0109] The parameters in the above formula are defined as follows: This represents the candidate segmentation threshold for pixel grayscale values in the residual image. This indicates that the pixel grayscale value is below the threshold. The percentage of pixels in the background area. This indicates that the pixel grayscale value is higher than the threshold. The percentage of pixels in the dangerous foreground area. This represents the pixel grayscale variance of the low residual background region. This represents the pixel grayscale variance of high residual danger areas.
[0110] By iterating through all candidate thresholds and finding the minimum intra-class variance, the optimal adaptive threshold that fits the current residual map can be obtained. :
[0111]
[0112] Optimal threshold By applying the pixel-level residual image, binary segmentation can be completed. Pixel regions with residuals greater than a threshold are identified as hazardous material regions, while the remaining regions are identified as normal background regions, ultimately achieving accurate positioning of hazardous materials.
[0113] S400. Based on the hazardous material regions in the image to be detected, construct a detection attribute graph and perform graph structure matching and decision-making with a custom hazardous material pattern library to obtain the long-tail detection results of hazardous materials.
[0114] S410. Construct a detection attribute map based on the hazardous material areas in the image to be detected;
[0115] Specifically, the hazardous material regions in the image to be detected are used as graph nodes, each carrying four attributes: atom type, position coordinates, region size, and detection confidence. The spatial relationship between any two hazardous material regions is used as graph edges, each carrying three attributes: center distance, relative angle, and spatial topological relationship. By combining the graph nodes and graph edges, a detection attribute graph is constructed.
[0116] In this embodiment, during the graph construction phase, each hazardous component detected by sparse coding is abstracted as a node of the graph, and the spatial adjacency and orientation relationship between components are abstracted as edges of the graph, thereby constructing an attribute graph. ,in For a set of nodes, For the set of edges, This is an adjacency matrix. Each node... It carries four attributes: Atom type (type) identifies which geometric dictionary atom this part belongs to; position (position) is indicated by a bounding box. Representation; size refers to the area of the region; confidence reflects the reliability of the detection. Each edge It carries three attributes: center-to-center distance (distance) represents the spatial proximity of two components; relative angle (angle) describes the orientational relationship of the components; and spatial type (relation) characterizes topological semantics such as upstream / downstream, left / right, and containment. Through this graph structure, the system transforms the detection results in the image space into a structured topological description, providing a unified mathematical representation for subsequent subgraph matching.
[0117] S420. Construct a custom hazardous materials pattern library and match it with the detection attribute graph, outputting the matching identifier and matching confidence value;
[0118] Specifically, a custom hazardous materials pattern library is constructed, which stores standard topology template graphs corresponding to various hazardous materials. Based on the hazardous materials pattern library and combined with the detection attribute graph, a matching algorithm based on the improved VF2++ subgraph isomorphism is used. During the matching process, four types of constraints are applied, and graph nodes that do not meet the four types of constraints are pruned to obtain target candidate node pairs. All candidate node pairs are traversed by depth-first backtracking search, and after the search terminates, the matching identifier and matching confidence value are output.
[0119] In this embodiment, a custom hazardous materials pattern library is constructed, as shown in Table 3:
[0120] Table 3 Hazardous Materials Pattern Library
[0121] firearms Tubular + L-shaped + blocky The tubular and L-shaped structures are connected, with the blocky structure nearby. knives Sharp edges + blocky Sharp edges are the main feature Improvised explosive devices High-density blocks + circuit traces + wires Multiple high-density clusters detonator High-density blocks + small tubular structures High-density block dominance chemical container Blocky + Specific density range Regular shape and uniform density
[0122] This embodiment is based on the classic VF2++ subgraph isomorphism algorithm and is adapted and optimized for the intelligent identification of hazardous materials. On the basis of the original topology matching capability, multi-dimensional attribute constraints of nodes are added. Through the backtracking pruning strategy, the similarity matching between the topology graph of the target to be detected and the standard pattern library of hazardous materials is completed, and the node mapping relationship and matching confidence are output, providing a quantitative basis for subsequent risk classification decision-making.
[0123] Define the input parameters, specifically including:
[0124] 1) Topology query graph of the target to be detected: generated by parsing the target to be detected. Each node in the graph contains atomic type, geometric size, and spatial coordinate attributes. Edges are used to represent the topological relationships between nodes.
[0125] 2) Hazardous materials standard pattern atlas: pre-trained and stored topology templates for various hazardous materials, with node and edge attribute definitions consistent with the query graph;
[0126] 3) Globally configurable constraint parameters: node size tolerance, relative position angle tolerance, supporting global unified configuration or independent configuration according to different hazardous materials types.
[0127] The output result is:
[0128] 1) Matching flag: Boolean type, indicating whether the current query graph has a valid subgraph matching the template graph;
[0129] 2) Node bidirectional mapping set: Records the one-to-one correspondence between query graph nodes and template graph nodes. When multiple sets of subgraphs meet the matching conditions, it returns the complete set of all valid mappings.
[0130] 3) Matching confidence: A similarity index in the range of 0 to 1, calculated by weighting the matching node coverage and the average deviation of node attributes.
[0131] For multi-dimensional matching constraint rules, when traversing candidate nodes for pairing, only nodes that simultaneously meet the following four types of constraints can enter the candidate matching set. If any condition is not met, branch pruning is immediately performed, terminating the current path search:
[0132] 1) The node atom types must be completely consistent;
[0133] 2) The absolute deviation of the node geometry is less than the preset tolerance;
[0134] 3) The angular error between the relative positions of the two nodes is less than the angular tolerance;
[0135] 4) The topology, number of adjacent edges, and association relationships of the first-order neighborhood of the candidate node are topologically compatible with the set of matched nodes.
[0136] Initialize an empty node mapping set, load the query graph, hazardous materials template graph, and constraint parameters; traverse candidate node pairs using a depth-first backtracking search, filtering for valid matching nodes based on the four types of constraints mentioned above; prune branches that do not meet the constraints in a timely manner to reduce invalid traversals and improve algorithm retrieval efficiency; set a triple recursion termination condition: all nodes in the query graph or template graph have completed valid bidirectional mapping, there are no candidate node pairs that meet the constraints, and the algorithm times out or reaches the maximum iteration limit, avoiding performance runaway in large-scale data scenarios; after the search terminates, calculate the percentage of valid matching nodes and the average attribute deviation of all matching nodes, and calculate the confidence score of this subgraph matching using a weighted method; finally, output the matching validity identifier, the complete node mapping set, and the matching similarity confidence score.
[0137] The maximum execution time for a single subgraph matching task is limited to a preset timeout threshold. The maximum size of the topology graph nodes that can be processed is set. When the number of graph nodes to be matched exceeds the maximum, it is directly judged as a matching anomaly and transferred to the manual review process to ensure the stability of the system in batch detection scenarios.
[0138] S430. Determine the type of hazardous material based on the matching identifier, classify the preset hazard level based on the matching confidence value, and obtain the long-tail detection results of hazardous materials.
[0139] In this embodiment, based on the three quantitative indicators of matching type, number of matching nodes, and matching confidence output by the subgraph isomorphism algorithm, risk levels are classified according to preset thresholds. The priority of judgment under multi-mode matching conflict and the business handling strategies corresponding to each level are clarified. At the same time, fallback rules for various system abnormal scenarios are added to achieve standardized management and control of the entire process of identification, judgment, early warning, and closed loop.
[0140] Set basic definitions and rule priorities, specifically including:
[0141] 1) Complete match: The query graph and the hazardous materials template graph achieve a one-to-one bidirectional mapping of all nodes, and the topology and all node attribute constraints meet the requirements;
[0142] 2) Partial matching: Only some nodes form a valid mapping relationship, and a one-to-one correspondence between all nodes is not achieved;
[0143] 3) Priority judgment rule: If multiple hazardous material templates are matched in a single detection, the matching result with the highest confidence level shall be selected as the final risk judgment basis.
[0144] Establish tiered risk assessment and handling rules, specifically including:
[0145] 1) For a perfect match scenario, if the confidence level is ≥0.8: it is judged as a high risk, and an emergency audible and visual alarm is immediately triggered across the entire domain. The current test sample is locked, and the original image, topology data, and node matching logs are fully stored and uploaded to the security warning platform. An emergency response notification is pushed to on-site and back-end management personnel. If the confidence level is ≤0.6 and <0.8: it is judged as a medium risk, and a local audible and visual alarm is triggered. The target sample is marked, a risk reminder is pushed to management personnel, and all test and matching data are archived simultaneously. If the confidence level is <0.6: it is judged as a low risk, and no active alarm is triggered. Only the test record is stored in the local database, and the sample is included in the regular sampling review queue. It can be retrospectively reviewed according to the sampling rules later.
[0146] 2) For some matching scenarios, when the number of valid matching nodes reaches the preset threshold and the attribute deviations of all matching nodes are within the tolerance range, it is judged as a suspicious risk and is forcibly transferred to the manual review stage. After the staff completes the sample verification, they can choose to upgrade the high-risk alarm or remove the risk and allow normal passage based on the review conclusion. If the number of valid matching nodes does not reach the preset threshold, it is judged as no security threat, the system automatically allows passage, and only retains a brief passage and matching log for traceability.
[0147] 3) For scenarios without matching, if the topology map to be detected does not produce a valid sub-map match with any of the hazardous materials templates in the database, it is determined to be a safety level, the equipment is directly released, and only the basic passage log is saved.
[0148] Set up fallback rules for abnormal scenarios. For abnormal scenarios that cannot complete subgraph matching normally, such as image parsing failure, empty topology graph data, constraint parameter out of bounds, and algorithm execution timeout, they are uniformly marked as abnormal detection samples. The system is prohibited from automatically releasing them. They must be manually verified on-site to confirm safety before the release operation can be completed. At the same time, abnormal events are recorded and archived separately to facilitate subsequent fault investigation and process optimization.
[0149] Regarding data retention and closed-loop management requirements, all risk-level samples and abnormal samples must have their original detection images, topology data, node mapping records, confidence levels, judgment times, and operator information permanently retained; manual review tasks must have processing time limits set, and review results must be archived online in a closed loop to form an auditable and traceable security testing ledger.
[0150] Reference Figure 2 A long-tail detection system for hazardous materials based on sparse dictionaries and component reconstruction includes:
[0151] The first module 201 is used to construct a set of labeled hazardous material image blocks and to generate a geometric atom dictionary by training an overcomplete dictionary through the K-singular value decomposition algorithm.
[0152] The second module 202 is used to introduce triplet loss and noise contrast estimation loss to construct encoder network model;
[0153] The third module 203 is used to encode the image to be detected through the encoder network model, reconstruct the image by combining the geometric atom dictionary, and perform adaptive threshold segmentation on the reconstructed structure to determine the dangerous item region in the image to be detected.
[0154] The fourth module 204 is used to construct a detection attribute graph based on the hazardous material regions in the image to be detected, and to perform graph structure matching and decision-making with a custom hazardous material pattern library to obtain the long-tail detection results of hazardous materials.
[0155] In summary, such as Figure 3 As shown, the overall architecture of this system consists of four core modules connected in series: First, the basic component dictionary construction module for hazardous materials uses the K-singular value decomposition algorithm to learn a complete geometric atom dictionary from a small number of labeled hazardous material image patches, abstracting hazardous materials into basic geometric units such as tubular structures, sharp edges, high-density blocks, L-shaped connections, and composite shapes; next, the Siamese encoder module trains a feature extraction network through contrastive learning, mapping image patches to a discriminative embedding space to enhance the generalization ability of component-level features; then, the residual-based component activation detection module performs sparse encoding and reconstruction on the image to be inspected, and uses the reconstructed residual map for adaptive threshold segmentation to locate potential hazardous areas; finally, the graph structure matching and decision module constructs the detected components into an attribute graph, performs subgraph isomorphic matching with a predefined hazardous material pattern library, and finally outputs the hazardous material category and confidence level. The system takes a full X-ray image of the security check as input and outputs a map of the types and locations of hazardous materials and their corresponding activated components. The system adopts a cascaded pipeline architecture of "decomposition, reconstruction, and matching" to achieve progressive reasoning from the pixel level to the semantic level.
[0156] The content of the above method embodiments is applicable to this system embodiment. The specific functions implemented in this system embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.
[0157] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this is not intended to limit the scope of the embodiments of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the embodiments of the present application.
Claims
1. A long-tail detection method for hazardous materials based on sparse dictionary and component reconstruction, characterized in that, Includes the following steps: A set of labeled hazardous material image patches is constructed, and an overcomplete dictionary is trained and learned using the K-singular value decomposition algorithm to generate a geometric atom dictionary; We introduce triplet loss and noise contrast estimation loss to construct an encoder network model; The image to be detected is encoded using an encoder network model, and then reconstructed using a geometric atom dictionary. Adaptive threshold segmentation is then applied to the reconstructed structure to determine the hazardous material regions in the image to be detected. Based on the hazardous material regions in the image to be detected, a detection attribute graph is constructed, and graph structure matching and decision-making are performed with a custom hazardous material pattern library to obtain the long-tail detection results of hazardous materials.
2. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 1, characterized in that, The step of constructing a set of labeled hazardous material image patches and training an overcomplete dictionary using the K-singular value decomposition algorithm to generate a geometric atom dictionary specifically includes: Construct a set of labeled hazardous materials image patches; Based on the set of labeled hazardous material image patches, the objective function is constructed by synchronously iteratively optimizing the overcomplete dictionary and sparse coefficient matrix. The objective function is based on minimizing the image feature reconstruction error, and is superimposed with an L1 sparse regularization term to constrain the sparsity of the sparse coefficients of a single sample, and the constraint conditions are set. Based on a two-stage alternating iterative solution strategy, the objective function is solved using the K-singular value decomposition algorithm to obtain the optimized dictionary feature fit. Based on the adaptiveness of the optimized dictionary features, the training and learning of the overcomplete dictionary specifically for the dangerous goods image patch set is iteratively optimized to generate a geometric atom dictionary.
3. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 2, characterized in that, The step of solving the objective function using the K-singular value decomposition algorithm based on the two-stage alternating iterative solution strategy to obtain the optimized dictionary feature fit specifically includes: The objective function is solved iteratively by using an alternating iterative strategy. The current overcomplete dictionary is fixed, and the optimal sparse coefficient vector corresponding to each set of dangerous goods image blocks is solved one by one by the orthogonal matching pursuit algorithm to construct the sparse coefficient matrix. Based on the sparse coefficient matrix, all sparse coefficients are fixed, and each atom in the dictionary is updated iteratively using the K-singular value decomposition algorithm to obtain the optimized dictionary feature fit.
4. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 3, characterized in that, The encoder network model specifically includes an input layer, a first convolutional pooling module, a second convolutional pooling module, a third convolutional pooling module, a global average pooling layer, and a fully connected output layer. The input layer, the first convolutional pooling module, the second convolutional pooling module, the third convolutional pooling module, the global average pooling layer, and the fully connected output layer are connected sequentially. The first convolutional pooling module, the second convolutional pooling module, and the third convolutional pooling module all include a convolutional layer, a batch normalization layer, a modified linear unit, and a max pooling layer. The loss function of the encoder network model includes triplet loss and noise contrast estimation loss.
5. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 4, characterized in that, The step of encoding the image to be detected using an encoder network model, reconstructing the image using a geometric atom dictionary, and performing adaptive threshold segmentation on the reconstructed structure to determine the hazardous material region in the image to be detected specifically includes: The image to be detected is acquired and encoded using an encoder network model to obtain sparse coding. Based on sparse coding, with the L0 norm as the sparse constraint, the orthogonal matching pursuit algorithm is used to solve for the optimal sparse coefficient vector; The reconstruction result of the image patch is obtained by linearly combining the optimal sparse coefficient vector with the geometric atom dictionary; The reconstruction results of the image to be detected and the image patch are calculated by difference to obtain the reconstruction residual vector and construct the pixel absolute residual map; The Otsu method adaptive thresholding algorithm is used to perform adaptive thresholding segmentation on the pixel absolute residual map to determine the dangerous item region in the image to be detected.
6. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 5, characterized in that, The step of using Otsu's adaptive thresholding algorithm to perform adaptive thresholding segmentation on the pixel absolute residual map to determine the hazardous material region in the image to be detected specifically includes: Iterate through all candidate thresholds corresponding to the gray levels of all pixels in the absolute residual image, and divide the pixels into low residual background regions and high residual dangerous foreground regions based on the thresholds. The pixel proportion and pixel variance of the low residual background region and the high residual dangerous foreground region are calculated respectively. A weighted intra-class variance objective function is constructed, and the threshold that minimizes the overall intra-class variance is selected as the candidate segmentation threshold. Based on the weighted intra-class variance objective function, all candidate segmentation thresholds are traversed, and the minimum intra-class variance is solved to obtain the optimal adaptive threshold that fits the absolute residual map of the current pixel. The optimal adaptive threshold is applied to the pixel absolute residual map to perform binary segmentation and determine the dangerous item region in the image to be detected.
7. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 6, characterized in that, The step of constructing a detection attribute graph based on the hazardous material regions in the image to be detected, and performing graph structure matching and decision-making with a custom hazardous material pattern library to obtain the long-tail detection results of hazardous materials specifically includes: Construct a detection attribute map based on the hazardous material regions in the image to be detected; Build a custom hazardous materials pattern library and match it with the detection attribute graph, outputting the matching identifier and matching confidence value; Based on the matching identifiers, the types of hazardous materials are determined, and based on the matching confidence values, the preset hazard levels are divided to obtain the long-tail detection results of hazardous materials.
8. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 7, characterized in that, The step of constructing a detection attribute map based on the hazardous material regions in the image to be detected specifically includes: The hazardous material regions in the image to be detected are used as graph nodes, and each graph node carries four attributes: atom type, location coordinates, region size, and detection confidence. The spatial relationship between any two hazardous material areas is used as a graph edge, and each graph edge carries three attributes: center distance, relative angle, and spatial topological relationship. By combining graph nodes and graph edges, a detection attribute graph is constructed.
9. The method for detecting long-tail hazardous materials based on sparse dictionary and component reconstruction according to claim 8, characterized in that, The step of constructing a custom hazardous materials pattern library, matching it with the detection attribute graph, and outputting the matching identifier and matching confidence value specifically includes: Construct a custom hazardous materials pattern library, which stores standard topology template diagrams corresponding to various hazardous materials; Based on the hazardous materials pattern library and combined with the detection attribute graph, the improved VF2++ subgraph isomorphism algorithm is used for matching. Four types of constraints are applied during the matching process, and graph nodes that do not meet the four types of constraints are pruned to obtain target candidate node pairs. All candidate node pairs are traversed through a depth-first backtracking search. After the search terminates, the matching identifier and matching confidence value are output.
10. A long-tail detection system for hazardous materials based on sparse dictionaries and component reconstruction, characterized in that, Includes the following modules: The first module is used to construct a set of labeled hazardous material image blocks, and to generate a geometric atom dictionary by training an overcomplete dictionary through the K-singular value decomposition algorithm. The second module is used to introduce triplet loss and noise contrast estimation loss to construct the encoder network model. The third module is used to encode the image to be detected through the encoder network model, reconstruct the image by combining the geometric atom dictionary, and perform adaptive threshold segmentation on the reconstructed structure to determine the dangerous item region in the image to be detected. The fourth module is used to construct a detection attribute graph based on the hazardous material regions in the image to be detected, and to perform graph structure matching and decision-making with a custom hazardous material pattern library to obtain long-tail detection results for hazardous materials.