A method, device and medium for detecting small targets in a subway security X-ray image
By employing a multi-scale, multi-head self-attention mechanism and a network architecture jointly optimized in the spatial and frequency domains, the real-time performance and accuracy issues of small target detection in subway security X-ray images were resolved, achieving efficient target detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGXI NORMAL UNIV
- Filing Date
- 2026-04-23
- Publication Date
- 2026-07-31
AI Technical Summary
Existing target detection algorithms struggle to achieve both real-time performance and high-precision small target detection in subway security X-ray images, especially in dealing with target clustering, occlusion, and insufficient feature extraction, resulting in low detection accuracy.
A network architecture employing a multi-scale multi-head self-attention mechanism and spatial-frequency domain joint optimization is adopted. It integrates global context and local detail features through multi-scale dilated convolution and multi-head self-attention mechanism, and retains key spatial information through spatial-frequency domain joint optimization enhancement module, replacing the traditional downsampling operation.
It significantly improves the detection accuracy of small targets, alleviates occlusion and clustering problems, enhances the network's ability to identify targets with small inter-class differences and large intra-class differences in X-ray images, maintains real-time performance, and meets the real-time requirements of subway security checks.
Smart Images

Figure CN122090045B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and deep learning, and in particular to a method, device and medium for detecting small targets in subway security X-ray images based on a multi-scale multi-head self-attention mechanism and spatial-frequency domain joint optimization. Background Technology
[0002] Object detection is one of the core tasks in computer vision, and it is widely used in fields such as autonomous driving, intelligent security, and industrial quality inspection. In recent years, deep learning-based object detection algorithms have made significant progress, but many challenges still exist in specific scenarios.
[0003] As the core of urban public transportation, the security check process in subways is crucial. Traditional manual security checks are inefficient and susceptible to subjective factors. Deep learning-based target detection technology offers an automated solution. However, small target detection in subway security scenarios faces significant challenges: First, items to be inspected (such as folding knives, USB lighters, etc.) occupy relatively few pixels in X-ray images, resulting in a lack of effective feature information; second, for storage containers such as suitcases, various items are densely packed inside, leading to severe target obstruction and clustering; third, the unique characteristics of X-ray imaging make the appearance of targets easily affected by factors such as material and angle, resulting in small inter-class differences but large intra-class differences.
[0004] Object detection algorithms can be broadly categorized into two types based on their processing flow: two-stage detectors and one-stage detectors. Two-stage detectors (such as Faster R-CNN) offer high accuracy but are slow, making them unsuitable for real-time requirements. One-stage detectors (such as the YOLO series) are fast but perform poorly in detecting small objects. Recently, Transformer-based detectors (such as DETR) and their improved version RT-DETR have achieved a balance between speed and accuracy. However, they still suffer from spatial information loss due to standard convolution or pooling operations during downsampling, which severely impacts the preservation of features for small objects. Furthermore, their standard self-attention mechanism struggles to effectively balance global semantic information and local detail features when dealing with the characteristics of large intra-class differences and small inter-class differences in X-ray images.
[0005] In summary, existing technologies struggle to balance real-time performance with high-precision small target detection in complex scenarios such as subway security X-ray images. Performance bottlenecks are particularly evident in handling target clustering, occlusion, and insufficient feature extraction of small targets due to downsampling, limiting the practicality and reliability of automated security inspection systems. Therefore, a novel network architecture and optimization method are urgently needed that can maintain real-time performance while effectively improving small target detection capabilities. Summary of the Invention
[0006] Based on this, the present invention provides a method, device and medium for detecting small targets in subway security X-ray images based on a multi-scale multi-head self-attention mechanism and spatial-frequency domain joint optimization, aiming to solve the problem of low detection accuracy caused by target aggregation, occlusion and insufficient feature extraction when processing small targets in X-ray images by existing target detection methods.
[0007] In a first aspect, the present invention provides a method for detecting small targets in X-ray images of subway security checks, comprising the following steps: The X-ray image data of the subway security check to be processed is acquired and input into a preset target detection network model for processing. The target detection network model includes a backbone network, a neck and a detection head. A multi-scale multi-head self-attention module and a spatial-frequency domain joint optimization enhancement module are embedded in the neck. The backbone network is used to perform multi-level feature extraction on the subway security X-ray image data to generate multiple preliminary feature maps containing information at different scales. The multi-scale multi-head self-attention module is invoked to process at least one of the preliminary feature maps. By fusing multi-scale dilated convolution and multi-head self-attention mechanism, global context information and local detail features are captured to generate a first enhanced feature map. The spatial-frequency domain joint optimization and enhancement module is invoked to process the feature pyramid composed of the first enhanced feature map and other preliminary feature maps. Through lossless downsampling of spatial information and spatial-frequency domain joint feature optimization, a second enhanced feature map is generated. The second enhanced feature map is input into the detection head, and the second enhanced feature map is parsed by the decoder to generate and output the bounding box coordinates and category probability of small targets in the subway security X-ray image data.
[0008] As an optional implementation of the first aspect of this application, the processing step of calling the multi-scale multi-head self-attention module specifically includes: processing the original input through a multi-scale dilated convolutional unit. Perform multi-path dilated convolution processing and output a channel attention-enhanced key-value feature map. ,in The preset pooling size is defined by B and C, which represent the data batch size and the number of feature map channels, respectively. The original input is then reassembled using a query-key-value recombination unit. Rearranged into a query matrix and will Decomposed into a key matrix K and a value matrix V, satisfying Where h is the number of attention heads and d is the dimension of each attention head; attention weights are calculated and weighted aggregated into a vector by scaling the dot product attention computation unit. The calculation process is as follows: The calculation results are then rearranged back into the spatial dimension to obtain the spatial attention output. The channel attention modulation unit, consisting of a global average pooling layer, two 1×1 convolutional layers, and a sigmoid activation function, is used to generate channel weights. The residual branch U is modulated to obtain the channel attention output. The spatial attention is output through the output fusion unit. With the channel attention output The two parts are added together to obtain and output the first enhanced feature map Y. The calculation process is as follows: .
[0009] As an optional implementation of the first aspect of this application, the processing steps of the multi-scale dilated convolutional unit specifically include: compressing the number of input channels from C to [value missing] through a first compressed convolutional layer. ,in To achieve the compression ratio; the compressed features are input into three parallel dilated depthwise convolutional paths, each path sequentially containing one... Depth-separable convolutional layer and one Dilated convolutional layers, where the three paths each employ different hole ratios. And the number of groups equals the number of input channels. The feature fusion layer adds the outputs of the three paths together along the channel dimension, and then... The convolution is restored to the original number of channels C to obtain the fused features; the fused features are then downsampled to a fixed size using an adaptive average pooling layer. Generate and output the channel attention-enhanced key-value feature map. .
[0010] As an optional implementation of the first aspect of this application, the processing steps of the query-key-value reconstruction unit and the channel attention modulation unit specifically include: in the query-key-value reconstruction unit, the query matrix Q is derived from the original input. Rearranged to maintain spatial resolution The key matrix K and value matrix V are obtained by downsampling. The rearranged result has a spatial resolution of This enables a cross-scale attention mechanism; in the channel attention modulation unit, the ReLU6 activation function is used between the two 1×1 convolutional layers, and the Sigmoid function is used in the last layer to generate normalized channel weights.
[0011] As an optional implementation of the first aspect of this application, the invoked spatial-frequency domain joint optimization enhancement module includes a spatial feature reconstruction unit and a multi-dimensional feature enhancement unit. The processing steps of the invoked spatial-frequency domain joint optimization enhancement module are as follows: the spatial feature reconstruction unit processes the input feature map by adopting a spatial dimension to channel dimension mapping mechanism to achieve lossless downsampling of the spatial information of the input features, thereby obtaining a downsampled feature map; the multi-dimensional feature enhancement unit processes the downsampled feature map, wherein, firstly, the feature splitting subunit divides the downsampled feature map into a multi-dimensional processing branch and an identity mapping branch according to the channel dimension; subsequently, the multi-dimensional feature processing subunit performs multi-dimensional feature extraction and spatial-frequency domain joint optimization on the multi-dimensional processing branch to obtain optimized branch features; finally, the feature fusion subunit concatenates the optimized branch features with the identity mapping branch by channel, and then performs convolution processing to generate and output the second enhanced feature map.
[0012] As an optional implementation of the first aspect of this application, the calculation process of the spatial feature reconstruction unit is represented by the following formula: ; ;in, For input features, The output is the downsampled feature map. The operation reorganizes adjacent 2×2 spatial regions into a channel dimension. and These are the weights and biases of a 1x1 convolution, respectively. This represents the convolution operation. The output features of the spatial feature reconstruction unit.
[0013] As an optional implementation of the first aspect of this application, the multidimensional feature processing subunit includes a frequency domain attention mechanism, a spatial attention mechanism, and a multi-directional feature extractor. The processing steps of the multidimensional feature processing subunit specifically include: performing preliminary convolution processing on the input feature X. ;in, The output of the initial convolution. This indicates the initial convolution operation. and The learnable parameters are represented; features are enhanced through a frequency domain attention mechanism, the calculation process of which is as follows: ; ; ;in, and They represent the Fast Fourier Transform and the Inverse Fourier Transform, respectively. For activation function, and For learnable parameters, This represents element-wise multiplication. For average pooling, and As an intermediate variable, The enhanced features are output by the frequency domain attention mechanism; further optimization is achieved through the spatial attention mechanism, the calculation process of which is as follows: ; ;in, This represents the modulus of a complex number, where σ represents the Sigmoid function. This indicates channel-dimension broadcast multiplication. and For learnable parameters, As an intermediate variable; different directional contexts are captured by a multi-directional feature extractor, and its calculation process is as follows: ;in, This represents the depthwise convolution in the i-th direction. The optimized branch feature is the final output.
[0014] As an optional implementation of the first aspect of this application, the method further includes a model training step, wherein the model training step updates the model parameters by calculating a composite loss function and backpropagating, and the calculation step of the composite loss function includes: calculating the object loss using a binary cross-entropy loss function. The calculation formula is: ;in This indicates whether the j-th bounding box in the predicted i-th cell contains the target. B represents the number of cells, and B represents the number of bounding boxes predicted for each cell. It is an indicator function that is 1 when the j-th bounding box in cell i contains the target, and 0 otherwise. This means that the value is 1 when the j-th bounding box in cell i does not contain the target, and 0 otherwise; the class loss is calculated using the binary cross-entropy loss function. The calculation formula is: ;in This represents the probability that the j-th bounding box in the i-th cell belongs to the c-th class. This is an indicator function; it is 1 when the bounding box belongs to the c-th category, and 0 otherwise. The bounding box coordinate loss is calculated using the mean squared error loss. The calculation formula is: ;in , Let x, y, x, and y represent the true center coordinates, width, and height of the j-th bounding box in the i-th cell, respectively. These are hyperparameters used to balance the weights of the bounding box coordinate loss and other losses; the GIOU loss function is used to calculate the overlap between the predicted and ground truth boxes. The calculation formula is: ;in It is the area of the smallest closed region containing both the predicted bounding box and the ground truth bounding box. This represents the true coordinates of the j-th bounding box within the i-th cell. Indicates the predicted coordinates. It is the IoU between the predicted bounding box and the ground truth bounding box. It is a generalized intersection, union, and comparison; the above , , and The total loss is obtained by weighted summation of the four loss components, and the AdamW optimizer combined with a staged learning rate scheduling strategy is used to update the model parameters.
[0015] Secondly, embodiments of this application provide an electronic device, which includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor. When the program or instructions are executed by the processor, they implement the steps of the method described in the first aspect.
[0016] Thirdly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0017] Compared with the prior art, the beneficial effects of the present invention are as follows: 1. Improve the accuracy of small target detection: By using a multi-scale, multi-head self-attention module, local details and global context are effectively integrated, significantly enhancing the ability to represent the features of small targets.
[0018] 2. Alleviating occlusion and clustering issues: The design of multi-scale dilated convolution can extract features with different receptive fields, which helps to distinguish mutually occluded or clustered targets in dense scenes.
[0019] 3. Preservation of key spatial information: The lossless spatial feature reconstruction unit in the spatial-frequency domain joint optimization enhancement module is used to replace the traditional downsampling, which effectively avoids the loss of information of small targets in the feature map dimensionality reduction process.
[0020] 4. Enhanced feature robustness: By jointly optimizing features in the spatial and frequency domains, the network's ability to identify targets with small inter-class differences and large intra-class differences in X-ray images is enhanced, thereby improving the model's generalization and robustness.
[0021] 5. Real-time performance is ensured: This invention improves upon the RT-DETR architecture and, through efficient module design, significantly enhances detection performance while maintaining a high inference speed, meeting the real-time requirements of scenarios such as subway security checks. Attached Figure Description
[0022] Figure 1 This is a schematic diagram of the overall model structure improved based on RT-DETR in an embodiment of the present invention; Figure 2 This is a schematic diagram of the image data processing method of the multi-scale multi-head self-attention module (MSMHSA) in an embodiment of the present invention; Figure 3 This is a schematic diagram of an image data processing method using a multi-scale convolutional unit in an embodiment of the present invention; Figure 4 This is a schematic diagram of the processing method of the space-frequency domain joint optimization and enhancement module (SPDConv and CSPOmniKernel) in an embodiment of the present invention; Figure 5 This is a comparison diagram of the model effects in an embodiment of the present invention. Detailed Implementation
[0023] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0024] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0025] Example 1 Please see Figure 1 The network architecture of this invention is an improvement on RT-DETR, mainly composed of three parts: a backbone network for multi-level feature extraction, a neck network containing a feature pyramid network, and a detection head (RTDETRDecoder). The backbone network is constructed using modules such as Conv and BasicBlock. Most importantly, the neck network incorporates the multi-scale multi-head self-attention module (MSMHSA) and the spatial-frequency domain joint optimization and enhancement modules (SPDConv and CSPOmniKernel) proposed in this invention.
[0026] The overall data processing flow is as follows: S1: Acquire the subway security X-ray image data to be processed and input it into the preset target detection network model for processing. The target detection network model includes a backbone network, a neck and a detection head. A multi-scale multi-head self-attention module and a spatial-frequency domain joint optimization enhancement module are embedded in the neck. S2: Multi-level feature extraction is performed on the subway security X-ray image data through the backbone network to generate multiple preliminary feature maps containing information at different scales; S3: Call the multi-scale multi-head self-attention module to process at least one of the preliminary feature maps, and capture global context information and local detail features by fusing multi-scale dilated convolution and multi-head self-attention mechanism to generate the first enhanced feature map; S4: Call the space-frequency domain joint optimization and enhancement module to process the feature pyramid composed of the first enhanced feature map and other preliminary feature maps, and generate the second enhanced feature map through lossless downsampling of spatial information and space-frequency domain joint feature optimization; S5: Input the second enhanced feature map into the detection head, parse the second enhanced feature map through the decoder, and generate and output the bounding box coordinates and category probability of the small target in the subway security X-ray image data.
[0027] In this method, the Multi-Scale Multi-Head Self-Attention Module (MSMHSA) organically combines multi-scale dilated convolution with multi-head self-attention, enhancing both the ability to extract local features from different receptive fields and effectively capturing global contextual information, thereby generating a more representative first enhanced feature map. The method introduces a spatial-frequency domain joint optimization enhancement module, which includes a lossless spatial feature reconstruction unit (SPDConv) to replace traditional downsampling operations, preserving key spatial details while reducing feature map resolution. Simultaneously, this module also includes a multi-dimensional feature enhancement unit (CSPOmniKernel) to perform feature enhancement in both the spatial and frequency domains, further improving the network's adaptability to multi-scale targets and generating the final second enhanced feature map for detection. This invention also optimizes the loss function design, combining binary cross-entropy, GIOU loss, and mean squared error loss, and employs the AdamW optimizer and adaptive learning rate strategy for model training to improve bounding box localization accuracy and classification accuracy.
[0028] Example 2 like Figure 2 As shown, the Multi-Scale Multi-Head Self-Attention Module (MSMHSA) is one of the core components of this invention, used to replace the traditional self-attention mechanism. Its computational flow is as follows: S31. The input data (original image or feature map) is digitally processed, the extracted features are converted into digital data and stored in a tensor matrix, and the normalization process is used to speed up the convergence of the convolutional neural network. S32. A method combining multi-scale dilated convolution and multi-head channel attention is used to extract and fuse features from the input data. S33. In the multi-scale dilated convolution unit, the original input is processed... Perform multi-path dilated convolution processing and output a channel attention-enhanced key-value feature map. ,in Preset pooling size; S34, Query-Key-Value Recombination Unit, used to recompose the original input Rearranged into a query matrix and will Split into a key matrix Sum matrix ,satisfy , For the number of long positions, Dimensions for each attention head; S35, Scaling Dot Product Attention Calculation Unit, is used to calculate attention weights and weighted aggregate value vectors. Its calculation process is as follows: ; The results are then rearranged back into the spatial dimension to obtain the spatial attention output. ; S36, Channel Attention Modulation Unit, including a global average pooling layer, two 1×1 convolutional layers, and a Sigmoid activation function, is used to generate channel weights. The residual branch U is modulated to obtain the channel attention output. ; S37, Output Fusion Unit, used to add the spatial attention output and the channel attention output to obtain the final output: .
[0029] Furthermore, such as Figure 3 As shown, the multi-scale dilated convolutional unit includes: The first compressed convolutional layer reduces the number of input channels from... Compress to ,in This refers to the compression ratio; Three parallel dilated depthwise convolutional paths, each path containing a... Depth-separable convolutional layer and one Dilated convolutional layers, where the three paths each employ different hole ratios. And the number of groups equals the number of input channels. ; The feature fusion layer adds the outputs of the three paths along the channel dimension and then... Convolution restores the original number of channels C; An adaptive average pooling layer downsamples the fused feature map to a fixed size. ,in .
[0030] Furthermore, the two layers in the channel attention modulation unit The ReLU6 activation function is used between convolutions (e.g. Figure 3 As shown), the last layer uses the Sigmoid function (as shown). Figure 4 (As shown) Generate normalized channel weights.
[0031] Furthermore, the query-key-value reorganization unit is implemented through tensor rearrangement operations, specifically: Query From the original input Rearranged to maintain spatial resolution ; key AND value From the downsampling The rearranged result has a spatial resolution of This enables a cross-scale attention mechanism.
[0032] Example 3 like Figure 4 As shown, the space-frequency domain joint optimization and enhancement module (SPDConv and CSPOmniKernel) includes a spatial feature reconstruction unit and a multi-dimensional feature enhancement unit, wherein: S41: The spatial feature reconstruction unit is located in the input part of the sampling pyramid, replacing the original standard convolutional layer. It adopts a mapping mechanism from spatial dimension to channel dimension to achieve lossless downsampling of spatial information of input features. S42: The multidimensional feature enhancement unit is inserted into the sampling pyramid input part, including a feature splitting subunit, a multidimensional feature processing subunit, and a feature fusion subunit; S43: The feature splitting subunit divides the input feature map into a multi-dimensional processing branch and an identity mapping branch according to the channel dimension; S44: The multi-dimensional feature processing subunit performs multi-dimensional feature extraction and spatial-frequency domain joint optimization on the enhancement processing branch; S45: The feature fusion subunit concatenates the output of the multidimensional feature processing subunit with the identity mapping branch, and then performs convolution processing to generate the final output feature.
[0033] Furthermore, the calculation process of the spatial feature reconstruction unit is represented by the following formula: ; ; in, As input features, the SpaceToDepth operation reorganizes adjacent 2×2 spatial regions into channel dimensions. and These are the weights and biases of a 1x1 convolution, respectively. This indicates a convolution operation.
[0034] Furthermore, the multidimensional feature processing subunit includes a frequency domain attention mechanism, a spatial attention mechanism, and a multi-directional feature extractor, and its processing includes the following steps: Perform preliminary convolution processing on the input feature X: ; Enhance features through frequency domain attention mechanisms: ; ; ; in, and They represent the Fast Fourier Transform and the Inverse Fourier Transform, respectively. For activation function, and For learnable parameters, This represents element-wise multiplication; Further optimization using spatial attention mechanisms: ; ; in, Indicates taking the modulus of a complex number. This indicates channel-dimension broadcast multiplication; Capture context from different directions using a multi-directional feature extractor: ; in, This represents the depthwise convolution in the i-th direction.
[0035] Example 4 In this embodiment, the composite loss function used in the method of the present invention includes four components: (1) The binary cross-entropy loss function is used for object loss, and the calculation formula is as follows: ; in This indicates whether the j-th bounding box in the i-th cell contains the target, and B represents the number of bounding boxes predicted for each cell. It is an indicator function that is 1 when the j-th bounding box in cell i contains the target, and 0 otherwise. This means that the value is 1 when the j-th bounding box in cell i does not contain the target, and 0 otherwise.
[0036] (2) The binary cross-entropy loss function is used for class loss, and the calculation formula is as follows: ; in This represents the probability that the j-th bounding box in the i-th cell belongs to the c-th class. It is an indicator function that is 1 when the bounding box belongs to the c-th category, and 0 otherwise.
[0037] (3) The mean squared error loss is used for the bounding box coordinate loss, and the calculation formula is as follows: ; in , Let x, y, x, and y represent the true center coordinates, width, and height of the j-th bounding box in the i-th cell, respectively. It is a hyperparameter used to balance the weights of the bounding box coordinate loss and other losses.
[0038] (4) Use the GIOU loss function to calculate the overlap between the predicted bounding box and the ground truth bounding box. The calculation formula is as follows: ; ; in It is the area of the smallest closed region containing both the predicted bounding box and the ground truth bounding box. This represents the true coordinates of the j-th bounding box within the i-th cell. Indicates the predicted coordinates. It is the IoU between the predicted bounding box and the ground truth bounding box. It is a broad sense of intersection and comparison.
[0039] The composite loss function design described in this invention adopts a multi-task balanced weighting strategy, which includes using the binary cross-entropy loss function to calculate the object loss, using the binary cross-entropy loss function to calculate the category loss, using the mean squared error loss to calculate the bounding box coordinate loss, and using the GIOU loss function to calculate the degree of overlap between the predicted box and the ground truth box. The object loss uses a binary cross-entropy function to accurately measure the confidence of the target's existence, and uses a conditional indicator function to dynamically distinguish between bounding boxes containing and not containing targets, effectively improving the model's sensitivity to identifying minute defects in complex industrial contexts. The category loss uses a binary cross-entropy function to accurately model the multi-class probability distribution, and a conditional masking mechanism ensures that the category error is calculated only for the prediction box containing the target, which significantly enhances the model's fine discrimination ability. The bounding box coordinate loss uses a mean square error function combined with a coordinate balance factor to proportionally balance the center point offset and size error. The GIOU loss introduces the concept of minimum closed region to extend the traditional IoU metric. By penalizing non-overlapping regions, it enhances the stability of bounding box regression and effectively solves the common problems of partial occlusion and irregular shapes in detection. The four loss components are optimized collaboratively through preset weight coefficients to form a multi-task balancing mechanism. During training, the contribution ratio is adaptively adjusted according to the convergence dynamic characteristics of each task, thus resolving the multi-objective optimization conflict between target localization accuracy, category discrimination accuracy, and background interference suppression in complex detection scenarios.
[0040] In this implementation, the training optimization process employs the AdamW optimizer combined with a staged learning rate scheduling strategy. The AdamW optimizer is an improvement on the traditional Adam algorithm, differing in that it decouples weight decay from gradient updates, avoiding the inconsistency problem of L2 regularization in adaptive gradient methods, and is particularly suitable for Transformer architectures with a large number of parameters. The staged learning rate scheduling includes a long-cycle warm-up stage and a linear decay stage. The warm-up stage uses a high learning rate for network bias parameters and a gradual growth strategy for weight parameters, effectively overcoming the non-convexity of the parameter space in the early stages of training. The optimization process configures momentum parameters to accelerate convergence, while introducing a weight decay coefficient to control model complexity and prevent overfitting on a finite sample set. The training strategy specifically sets the final learning rate ratio to maintain learning capacity in the later stages of training, adapting to the continuous learning needs of identifying subtle features in the samples.
[0041] The training process of this invention adopts a deterministic training paradigm and an industrial hardware adaptation strategy. Deterministic training, by using a fixed random seed and enabling deterministic algorithms, ensures that the model training results are fully reproducible on different hardware platforms, meeting the stringent requirements for model stability in industrial deployments. The batch size and image resolution are optimized and balanced for industrial GPU memory capacity, avoiding memory overflow while maintaining high-precision feature extraction. The training process disables automatic precision mixing, which, although sacrificing some training speed, ensures the numerical stability of gradient calculation in small target defect detection.
[0042] The purpose of forward propagation during the training process is to gradually adjust the network parameters so that the output results are closer to the label data, thereby improving the prediction accuracy of the model. In the forward propagation stage of the training process, since the network parameters are randomly initialized, the output results may have a large difference from the label data. Therefore, it is necessary to adjust the network parameters through backpropagation to optimize the performance of the network model.
[0043] This invention establishes a robust multi-scale, multi-head self-attention and space-frequency domain joint optimization enhancement method for detection. It then combines this with small target datasets in complex scenarios and the RT-DETR network, along with a training model developed based on the author's experience (e.g., ...). Figure 5 As shown, the baseline model is the RT-DETR network, and the improved model is the method of this invention. On the one hand, it improves the accuracy and efficiency of small target detection in complex scenes. On the other hand, after training, the generated neural network model can also detect targets in new datasets or real-time images, while maintaining good accuracy and efficiency in small target detection.
[0044] Optionally, embodiments of this application also provide an electronic device, including a processor, a memory, and a program or instructions stored in the memory and executable on the processor. When the program or instructions are executed by the processor, they implement the various processes of the above-described embodiment of a method for detecting small targets in subway security X-ray images and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0045] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described embodiment of a method for detecting small targets in X-ray images of subway security checks, and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0046] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0047] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0048] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0049] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A method for detecting small targets in subway security X-ray images, characterized in that, Includes the following steps: The X-ray image data of the subway security check to be processed is acquired and input into a preset target detection network model for processing. The target detection network model includes a backbone network, a neck and a detection head. A multi-scale multi-head self-attention module and a spatial-frequency domain joint optimization enhancement module are embedded in the neck. The backbone network is used to perform multi-level feature extraction on the subway security X-ray image data to generate multiple preliminary feature maps containing information at different scales. The multi-scale multi-head self-attention module is invoked to process at least one of the preliminary feature maps. By fusing multi-scale dilated convolution and multi-head self-attention mechanisms, global contextual information and local detailed features are captured to generate a first enhanced feature map. Specifically, this includes processing the original input through a multi-scale dilated convolution unit. Perform multi-path dilated convolution processing and output a key-value feature map with channel attention enhancement. ,in The preset pooling size is defined by B and C, which represent the data batch size and the number of feature map channels, respectively. The original input is then reassembled using a query-key-value recombination unit. Rearranged into a query matrix and will Decomposed into a key matrix K and a value matrix V, satisfying Where h is the number of attention heads and d is the dimension of each attention head; attention weights are calculated and weighted aggregated into a vector by scaling the dot product attention computation unit. The calculation process is as follows: The calculation results are then rearranged back into the spatial dimension to obtain the spatial attention output. The channel attention modulation unit, consisting of a global average pooling layer, two 1×1 convolutional layers, and a sigmoid activation function, is used to generate channel weights. The residual branch U is modulated to obtain the channel attention output. The spatial attention is output through the output fusion unit. With the channel attention output The two parts are added together to obtain and output the first enhanced feature map Y. The calculation process is as follows: ; The spatial-frequency domain joint optimization and enhancement module is invoked to process the feature pyramid composed of the first enhanced feature map and other preliminary feature maps. A second enhanced feature map is generated through lossless downsampling of spatial information and spatial-frequency domain joint feature optimization. The spatial-frequency domain joint optimization and enhancement module includes a spatial feature reconstruction unit and a multi-dimensional feature enhancement unit. The specific processing steps of invoking the spatial-frequency domain joint optimization and enhancement module are as follows: the spatial feature reconstruction unit processes the input feature map, employing a spatial-to-channel dimension mapping mechanism to achieve lossless downsampling of the spatial information of the input features, resulting in a downsampled feature map; the multi-dimensional feature enhancement unit processes the downsampled feature map, firstly by using a feature splitting subunit to divide the downsampled feature map into a multi-dimensional processing branch and an identity mapping branch according to the channel dimension; subsequently, the multi-dimensional feature processing subunit performs multi-dimensional feature extraction and spatial-frequency domain joint optimization on the multi-dimensional processing branch to obtain optimized branch features; finally, the feature fusion subunit concatenates the optimized branch features with the identity mapping branch through channel concatenation, and then performs convolution processing to generate and output the second enhanced feature map. The multidimensional feature processing subunit includes a frequency domain attention mechanism, a spatial attention mechanism, and a multi-directional feature extractor. The specific processing steps of the multidimensional feature processing subunit include: performing preliminary convolution processing on the input feature X. ;in, The output of the initial convolution. This indicates the initial convolution operation. and The learnable parameters are represented; features are enhanced through a frequency domain attention mechanism, the calculation process of which is as follows: ; ; ;in, and These represent the Fast Fourier Transform and the Inverse Fourier Transform, respectively. For activation function, and For learnable parameters, This represents element-wise multiplication. For average pooling, and As an intermediate variable, The enhanced features are output by the frequency domain attention mechanism; further optimization is achieved through the spatial attention mechanism, the calculation process of which is as follows: ; ;in, This represents the modulus of a complex number, where σ represents the Sigmoid function. This indicates channel-dimension broadcast multiplication. and For learnable parameters, As an intermediate variable; different directional contexts are captured by a multi-directional feature extractor, and its calculation process is as follows: ;in, This represents the depthwise convolution in the i-th direction. The optimized branch features are the final output; The second enhanced feature map is input into the detection head, and the second enhanced feature map is parsed by the decoder to generate and output the bounding box coordinates and category probability of small targets in the subway security X-ray image data.
2. The method of claim 1, wherein, The processing steps of the multi-scale dilated convolutional unit specifically include: The input channel number is compressed from C to C / r by the first compression convolutional layer wherein is the compression ratio; The compressed features are input into three parallel dilated depthwise convolutional paths, each path containing a... Depth-separable convolutional layer and one Dilated convolutional layers, where the three paths each employ different hole ratios. And the number of groups equals the number of input channels. ; The outputs of the three paths are added in the channel dimension through a feature fusion layer, and then the added output is input into a fully connected layer The convolution is restored to the original channel number C to obtain the fused features. downsample the fusion feature to a fixed size through an adaptive average pooling layer generate and output the channel attention enhanced key-value feature map .
3. The method of claim 1, wherein, The processing steps of the query-key-value reconstruction unit and the channel attention modulation unit specifically include: In the query-key-value reorganization unit, the query matrix Q is obtained by original input rearranged to maintain spatial resolution ; the key matrix K and the value matrix V are obtained by down-sampling rearranged to maintain spatial resolution , so as to realize the cross-scale attention mechanism; In the channel attention modulation unit, the ReLU6 activation function is used between the two 1×1 convolutional layers, and the sigmoid function is used to generate normalized channel weights in the last layer.
4. The method of claim 1, wherein, The calculation process of the spatial feature reconstruction unit is represented by the following formula: ; ; in, For input features, The output is the downsampled feature map. The operation reorganizes adjacent 2×2 spatial regions into a channel dimension. and These are the weights and biases of a 1x1 convolution, respectively. This represents the convolution operation. The output features of the spatial feature reconstruction unit.
5. The method of claim 1, wherein, The method further includes a model training step, which updates the model parameters by calculating a composite loss function and backpropagating. The calculation of the composite loss function includes: The object loss is calculated using a binary cross-entropy loss function with the formula: ; in This indicates whether the j-th bounding box in the predicted i-th cell contains the target. B represents the number of cells, and B represents the number of bounding boxes predicted for each cell. It is an indicator function that is 1 when the j-th bounding box in cell i contains the target, and 0 otherwise. This means that the value is 1 when the j-th bounding box in cell i does not contain the target, and 0 otherwise; A binary cross-entropy loss function is used to compute the class loss with the formula: ; in This represents the probability that the j-th bounding box in the i-th cell belongs to the c-th class. It is an indicator function, which is 1 when the bounding box belongs to the c-th category, and 0 otherwise; The bounding box coordinate loss is calculated using mean square error loss The calculation formula is: ; in , Let x, y, x, and y represent the true center coordinates, width, and height of the j-th bounding box in the i-th cell, respectively. These are hyperparameters used to balance the weights of the bounding box coordinate loss and other losses; The GIOU loss function is used to calculate the degree of overlap between the predicted box and the real box The calculation formula is: ; in, This represents the true coordinates of the j-th bounding box within the i-th cell. Indicates the predicted coordinates. It is the IoU between the predicted bounding box and the ground truth bounding box. It is a generalized intersection and comparison; The above , , and The total loss is obtained by weighted summation of the four loss components, and the AdamW optimizer combined with a staged learning rate scheduling strategy is used to update the model parameters.
6. An electronic device, comprising: The device includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor. When the program or instructions are executed by the processor, they implement the steps of the method for detecting small targets in X-ray images of subway security checks as described in any one of claims 1-5.
7. A readable storage medium characterized by, The readable storage medium stores a program or instructions, which, when executed by a processor, implement the steps of a method for detecting small targets in subway security X-ray images as described in any one of claims 1-5.