A Terahertz Detection Method for Hazardous Materials in Subways Based on Adaptive Downsampling and Multidimensional Attention Mechanism

The terahertz detection method for dangerous goods in subways, which combines adaptive downsampling and multi-dimensional attention mechanisms, solves the problems of weak feature extraction and low robustness in traditional detection technologies, and achieves high-precision detection of dangerous goods in subways, applicable to various security scenarios.

CN120635557BActive Publication Date: 2025-12-02GUANGDONG UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510727740.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-03
Publication Date
2025-12-02
Estimated Expiration
2045-06-03

AI Technical Summary

Technical Problem

Traditional terahertz detection technology suffers from weak feature extraction capabilities, low robustness, and insufficient utilization of spatial information in hazardous materials detection, leading to a decrease in detection accuracy.

Method used

A terahertz detection method for hazardous materials in subways employs adaptive downsampling and multi-dimensional attention mechanisms. It performs dual-path processing through parallel pooling and convolution operations, combines a Transformer encoder for global context modeling, and utilizes strip pooling layers to capture long-range contextual dependencies, thereby enhancing feature extraction and detection accuracy.

Benefits of technology

It improves feature extraction capabilities and detection accuracy, enhancing the ability to detect dangerous goods in subways, and is suitable for security scenarios such as subways, rail transit, aviation hubs, and large-scale events.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120635557B_ABST
    Figure CN120635557B_ABST
Patent Text Reader

Abstract

This invention discloses a terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanisms, comprising: acquiring a terahertz image dataset; constructing a deep learning network model, the deep learning network model including a backbone feature extraction network, a neck feature extraction network, a downsampling module, a fusion channel and spatial attention module, a spatial attention module, and a YoloHead detection head connected in sequence; performing dual-path processing on the input feature map through parallel pooling and convolution operations; performing global context modeling on the feature map in the fusion channel and spatial attention module; capturing long-range context dependencies through strip pooling layers in the spatial attention module; inputting the multi-scale feature map output by the neck network into the YoloHead detection head, outputting target detection boxes; and removing redundant detection boxes through a non-maximum suppression algorithm, retaining the detection results with the highest confidence.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of hazardous materials detection technology, and in particular relates to a terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism. Background Technology

[0002] Terahertz wave detection technology, as an emerging non-destructive testing solution in the security inspection field, demonstrates significant application advantages due to its non-ionizing radiation characteristics. This technology achieves penetrating identification by analyzing the unique molecular vibrational responses of substances, effectively overcoming interference from complex environments and accurately locating potentially dangerous items hidden inside clothing, packages, or containers. Its biocompatibility ensures that the detection process will not cause ionizing damage to human tissue or the ecological environment, making it particularly suitable for the intelligent screening needs of concealed threats in high-security scenarios such as airports and rail transit hubs, providing key technological support for building a non-intrusive security inspection system.

[0003] With the rapid development of deep learning technology, powerful tools have become available for image recognition and detection. However, traditional object detection tools still have many limitations in the terahertz domain for hazardous materials detection: such as weak feature extraction capabilities (traditional downsampling modules easily lose high-frequency detail information, affecting the detection of small targets); low robustness (conventional attention mechanisms such as SE and CBAM modules are difficult to effectively distinguish hazardous materials from background noise); and the use of non-pooling operations to utilize spatial information easily weakens target edge features, leading to a decrease in detection accuracy. Therefore, it is urgent to propose a terahertz hazardous materials detection method for subways based on adaptive downsampling and a multi-dimensional attention mechanism. Summary of the Invention

[0004] To address the aforementioned technical problems, this invention proposes a terahertz detection method for hazardous materials in subways based on adaptive downsampling and a multi-dimensional attention mechanism, thereby improving the detection capability for hazardous materials in subways.

[0005] To achieve the above objectives, this invention provides a terahertz detection method for hazardous materials in subways based on adaptive downsampling and a multi-dimensional attention mechanism, comprising:

[0006] Obtain a terahertz image dataset, which contains XML files annotating the locations of hazardous materials;

[0007] A deep learning network model is constructed, which includes a backbone feature extraction network, a neck feature extraction network, a downsampling module, a fusion channel and spatial attention module, a spatial attention module, and a YOLOHead detection head connected in sequence.

[0008] In the downsampling module, the input feature map is processed through parallel pooling and convolution operations in a dual-path manner;

[0009] In the fusion channel and spatial attention module, the feature map is modeled globally using a Transformer encoder;

[0010] In the spatial attention module, long-range context dependencies are captured through strip pooling layers;

[0011] Input the multi-scale feature map output by the Neck network into the YOLOHead detection head, and output the target detection box in the normalized coordinate system;

[0012] Redundant detection boxes are removed using a nonmaximum suppression algorithm, and the detection results with the highest confidence are retained.

[0013] Optionally, the input feature map is processed in a dual-path manner through parallel pooling and convolution operations, including: performing average pooling preprocessing on the input feature map; dividing the preprocessed feature map into two paths along the channel dimension; capturing local details through 3×3 convolution downsampling in the first path; fusing channel information through max pooling and 1×1 convolution in the second path; and concatenating the outputs of the two paths along the channel dimension.

[0014] Optionally, global context modeling of the feature map using a Transformer encoder includes: flattening the input feature map into a sequence and adding two-dimensional sine-cosine positional encoding; capturing long-range dependencies using a multi-head self-attention mechanism; and enhancing feature representation through a feedforward network.

[0015] Optionally, capturing long-range contextual dependencies through strip pooling layers includes: performing horizontal and vertical strip pooling on the input feature map; modulating the pooling results through 1×1 convolution; generating spatial attention weights and weighting them onto the original feature map.

[0016] Optionally, the construction process of the downsampling module includes: in the dual-path processing, the stride of the first 3×3 convolution is set to 2 and the padding value is 1; the window size of the second max pooling is 3×3, the stride is 2, and the padding value is 1; the two output channels have the same number and feature fusion is achieved by adding them element by element.

[0017] Optionally, the construction process of the fusion channel and spatial attention module includes: when the position encoding is generated, the temperature parameter is set to 10000 and pos_dim is set to 128; the number of heads in the multi-head self-attention mechanism is 8, and the dimension of each head is 64.

[0018] Optionally, the construction process of the spatial attention module includes: the strip pooling layer contains two parallel branches in the horizontal and vertical directions, each branch contains a 3×1 convolution kernel; during dynamic weight calculation, the number of channels of the 1×1 convolution is reduced by 4.

[0019] Optionally, the structure of the neck network includes: an SPPF layer connected after the downsampling module, wherein the pyramid scale of the SPPF layer is set to 5, 9, and 13; the input of the fusion channel and the spatial attention module is the feature maps of the first two scales of the neck network.

[0020] Technical Advantages of this Invention: This invention discloses a terahertz-based method for detecting hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanisms. By introducing adaptive downsampling and multi-dimensional attention, it reduces the loss of high-frequency information during the downsampling process, combines global context modeling and local feature refinement, and captures long-range dependencies through strip pooling layers to optimize target edge and shape features. This significantly improves the feature extraction capability, detection accuracy, and robustness compared to traditional target detection algorithms, making it suitable for real-time applications and various scenarios in terahertz image hazardous material detection. It has broad application prospects in subway hazardous material detection, rail transit, aviation hubs, and security for large-scale events. Attached Figure Description

[0021] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0022] Figure 1 This is a schematic diagram of computer detection of terahertz images in terahertz hazardous materials detection according to an embodiment of the present invention;

[0023] Figure 2 This is a schematic diagram of the overall architecture of the detection network according to an embodiment of the present invention;

[0024] Figure 3 This is a schematic diagram of the network architecture of the downsampling module in the overall network architecture of the detection network according to an embodiment of the present invention;

[0025] Figure 4 This is a schematic diagram of the network that fuses the channel and spatial attention modules in the overall network architecture of the detection network according to an embodiment of the present invention;

[0026] Figure 5 This is a schematic diagram of the spatial attention module network architecture in the overall network architecture of the detection network according to an embodiment of the present invention. Detailed Implementation

[0027] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0028] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0029] like Figure 1 As shown, this embodiment provides a terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanisms, including:

[0030] By using a YOLO-based object detector and a network constructed with downsampling and multi-dimensional attention enhancement, the network is run by a computer for object detection. The implementation steps are as follows:

[0031] Step 1: Download the terahertz dataset I from the website GitHub. h =[I h1 I h2 ,...I hK ], where dataset I h The total number of elements is K = 2841, the image size is 3×640×640, and the image annotation information file format is xml.

[0032] Step 2.1: Set up as follows Figure 2 The network model shown includes a backbone feature extraction network, a neck feature extraction network, a downsampling module, a fusion channel and spatial attention, spatial attention, and a YOLOHead detection head structure.

[0033] Use size n ch The RGB image (×h×w) is input into the backbone of the network model, passing through convolution, C3k2 layer, downsampling module, SPPF layer, and fusion channel and spatial attention module, and outputting feature maps of three different scales. b1 I b2 and I b3 The scales are 128×80×80, 256×40×40, and 512×20×20, respectively. The number of C3k2 layers is set to 2, 2, 2, 2. A fusion channel and a spatial attention module are connected after the SPPF layer, and an 8-head windowed axial attention mechanism is used to focus on the I... b1 I b2 Perform dynamic weight calibration across channels and spaces to achieve lossless feature transfer between the backbone and neck.

[0034] In the overall structure of Neck, a downsampling module replaces the original Conv module to reduce the loss of high-frequency information during the downsampling process. A spatial attention module is introduced, using strip pooling to capture long-range contextual dependencies. Then, a dynamic sparse attention matrix is ​​used to calculate cross-feature map association weights. Neck outputs three feature maps of different scales. n1 I n2 and I n3 The dimensions are 128×80×80, 256×40×40 and 512×20×20 respectively.

[0035] Step 2.2: The downsampling module is as follows Figure 3 As shown, its core idea is to utilize different pooling and convolution operations in parallel to retain diverse feature information while reducing computational cost. By combining channel segmentation and dual-path processing, the spatial resolution of the input feature map is reduced through downsampling and the number of channels is adjusted. First, the input is preprocessed by performing 2×2 average pooling on the input x with a stride of 1 and padding of 0, initially reducing the spatial dimensionality and alleviating the computational burden of subsequent operations. Formula:

[0036] X pool =AvgPool2d(x, kernel_size=2, stride=1);

[0037] In the above formula, x represents the input tensor, X pool The result of the input tensor x after two-dimensional average pooling operation is given by AvgPool2d(), which means calculating the local average value of each channel of the input tensor, kernel_size represents the size of the pooling window, and stride represents the step size of the pooling window in each slide.

[0038] Then channel segmentation is performed, X pool The input is divided into two parts, x1 and x2, along the channel dimension to separate feature channels, allowing each path to independently process different feature patterns. In path 1, a 3×3 convolution downsampling process with a stride of 2 and padding of 1 captures local details while compressing the spatial dimension to half of the original input. Formula: x1 out =Conv 3×3 (x1), x1 out It is the result of convolution after input x1, Conv 3×3 () represents a 3×3 convolution downsampling operation. In path 2, it first undergoes 3×3 max pooling with a stride of 2 and padding of 1, followed by a 1×1 convolution to adjust the channels. The formula is:

[0039] x2 out =Conv 1×1 (MaxPool2d 3×3 (x2));

[0040] In the above formula, x2 out After input x2 is max-pooled to emphasize salient features, the result is then fused using convolution to integrate channel information. 1×1 () represents a 1×1 convolution downsampling operation, MaxPool2d 3×3 () indicates the use of a two-dimensional max pooling function with a pooling size of 3×3.

[0041] Finally, x1 out and x2 out The data is stitched along the channel dimension to output the shape [b, c2, h / / 2, w / / 2], where c2 is the target number of output channels. Local details (path 1) and salient features (path 2) are fused to enhance the representation capability after downsampling.

[0042] Step 2.3: Integrate the channel and spatial attention modules as follows Figure 4 As shown, this is a visual feature enhancement module based on a Transformer encoder, specifically designed for processing two-dimensional image feature maps. It captures global context through a self-attention mechanism and introduces two-dimensional sine-cosine positional encoding to preserve spatial location information, making it suitable for tasks requiring long-range dependency modeling. First, the input feature map x-shape [b, c, h, w] is flattened into a sequence form [b, h × w, c], adapting to the Transformer's sequence processing paradigm, treating spatial locations as sequence elements.

[0043] Then, a positional code matching the feature map size is generated. Sine-cosine codes are generated for the width w and height h respectively, and then concatenated to form complete positional information. Taking the width as an example, the formula is:

[0044]

[0045] PE(w)=[sin(w·ω), cos(w·ω)];

[0046] In the two formulas above, i is an index variable used to iterate through each frequency component dimension of the positional coding, and w i The frequency component is a key parameter that controls the position coding wavelength and frequency distribution. pso_dim represents the position in each direction, and temperature is a temperature parameter that controls the decay rate of the frequency component. PE(w) is the position coding component in the width direction, sin(w·ω) represents the sine coding component of position w, and cos(w·ω) represents the cosine coding component of position w.

[0047] The final position encoding dimension shape is [1, H×w, c].

[0048] Multi-head attention and feedforward networks (FFNs) are used. The input is a sequenced feature [b, h×w, c] with positional encoding (PE), and the output is an enhanced sequence feature [b, h×w, c]. The formula is:

[0049] y seq =TransformerEncoderLayer(x flat +PE);

[0050] In the above formula, y seq This represents the sequence encoded by the Transformer, where the vector at each position incorporates global dependencies. `TransformerEncoderLayer()` represents a standard Transformer encoding layer, containing multi-head self-attention and a feedforward network. `x` flat This represents the sequence after the input feature map is flattened, and PE represents the two-dimensional sine-cosine positional encoding.

[0051] Finally, the output sequence [b, h×w, c] is restored to its original shape [b, c, h, w] to maintain compatibility with downstream convolutional networks. The formula is as follows:

[0052] y = Reshape(y seq );

[0053] In the above formula, y represents the final output feature map, with the same shape as the original input. Reshape() is the operation that restores the sequence to a two-dimensional feature map, recovering its spatial structure. seq This represents the sequence encoded by the Transformer.

[0054] Step 2.4: Spatial attention module, such as Figure 5 As shown, it utilizes horizontal and vertical strip pooling operations to collect remote context from different spatial dimensions. Let x∈R C×H×W Let X be the input tensor, where C represents the number of channels, and H and W are the spatial height and width, respectively. First, X is input into two parallel paths, each containing a horizontal or vertical strip pooling layer, followed by a one-dimensional convolutional layer with a kernel size of 3 to modulate the current position and its neighboring features. Define y... h ∈R C×H and y v ∈R C×W To obtain an output z∈R that contains more useful global priors. C×H×W First, y h and y v Combining them together, as shown below, produces y∈R C×H×W :

[0055]

[0056] Then, the output feature z is calculated as follows:

[0057] z = Scale(x, σ(f(y)));

[0058] In the above formula, Scale(,) refers to element-wise multiplication, σ is the sigmoid function, which generates spatial attention weights to adaptively weight multi-scale context features to enhance the feature response of important regions and suppress irrelevant background noise, and f() is a 1×1 convolution.

[0059] Step 3: Specific training parameter configuration includes: base learning rate lr = 0.01, batch size = 16, training set and validation set split as 0.9:0.1, optimizer type selection as SGD, and total training epochs = 300.

[0060] Step 4: Use the trained network for prediction. Input the test image and output the predicted bounding box for the terahertz image target. First, input the test image I... t The image input to the network has a size of n. ch After inference via the network (×h×w), the output of Yolohead is obtained. The output feature maps have scales of 80×80, 40×40, and 20×20. The classification and regression prediction results are extracted from the feature maps of different scales and then concatenated and transformed in dimension. For ease of processing, the original channel dimension is moved to the end, resulting in the categories prediction branch and bounding box prediction branch with shapes of (b, 8400, 80) and (b, 8400, 4), respectively. All targets are sorted in descending order of their presence confidence (conf = 0.001), and then the Intersection over Union (IOU) with other predictions is calculated from high to low, discarding predictions with an IOU greater than a certain threshold (iou = 0.6). Subsequently, based on the previous preprocessing, the remaining detection boxes are restored to the original image scale before network output, and non-maximum suppression is performed to remove redundant detection boxes. The number of output detection boxes does not exceed the preset maximum number of detections (max_per_img = 300).

[0061] The original coordinate parameters (x, y, w, h) of the bounding box of the detected target are converted into values ​​(X, Y, W, H) in a normalized coordinate system and visually labeled on the test image. When the system identifies a valid detection box in the image to be inspected, it determines that the inspected person is carrying dangerous goods; if no detection box is generated, it determines that the inspected person is not carrying prohibited items.

[0062] The above are merely preferred embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism, characterized in that, include: Obtain a terahertz image dataset, which contains XML files annotating the locations of hazardous materials; A deep learning network model is constructed, which includes a backbone feature extraction network, a neck feature extraction network, a downsampling module, a fusion channel and spatial attention module, a spatial attention module, and a YOLOHead detection head connected in sequence. In the downsampling module, the input feature map is processed through parallel pooling and convolution operations in a dual-path manner; In the fusion channel and spatial attention module, the feature map is modeled globally using a Transformer encoder; In the spatial attention module, long-range context dependencies are captured through strip pooling layers; Input the multi-scale feature map output by the Neck network into the YOLOHead detection head, and output the target detection box in the normalized coordinate system; Redundant detection boxes are removed using a nonmaximum suppression algorithm, and the detection results with the highest confidence are retained.

2. The terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism as described in claim 1, characterized in that, The input feature map is processed using a dual-path approach through parallel pooling and convolution operations. This includes: preprocessing the input feature map with average pooling; dividing the preprocessed feature map into two paths along the channel dimension; capturing local details through 3×3 convolution downsampling in the first path; fusing channel information through max pooling and 1×1 convolution in the second path; and concatenating the outputs of the two paths along the channel dimension.

3. The terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism as described in claim 1, characterized in that, Global context modeling of feature maps using a Transformer encoder includes: flattening the input feature map into a sequence and adding two-dimensional sine-cosine positional encoding; capturing long-range dependencies using a multi-head self-attention mechanism; and enhancing feature representation through a feedforward network.

4. The terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism as described in claim 1, characterized in that, Capturing long-range contextual dependencies through strip pooling layers includes: performing horizontal and vertical strip pooling on the input feature map; modulating the pooling results through 1×1 convolution; generating spatial attention weights and weighting them onto the original feature map.

5. The terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism as described in claim 1, characterized in that, The construction process of the downsampling module includes: in the dual-path processing, the stride of the first 3×3 convolution is set to 2 and the padding value is 1; the window size of the second max pooling is 3×3, the stride is 2, and the padding value is 1; the two output channels have the same number and feature fusion is achieved by adding them element by element.

6. The terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism as described in claim 1, characterized in that, The construction process of the fusion channel and spatial attention module includes: when the position encoding is generated, the temperature parameter is set to 10000 and pos_dim is set to 128; the number of heads in the multi-head self-attention mechanism is 8, and the dimension of each head is 64.

7. The terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism as described in claim 1, characterized in that, The construction process of the spatial attention module includes: the strip pooling layer contains two parallel branches in the horizontal and vertical directions, and each branch contains a 3×1 convolution kernel; during dynamic weight calculation, the number of channels of the 1×1 convolution is reduced by 4.

8. The terahertz detection method for hazardous materials in subways based on adaptive downsampling and multi-dimensional attention mechanism as described in claim 1, characterized in that, The structure of the neck network includes: an SPPF layer connected after the downsampling module, with the pyramid scale of the SPPF layer set to 5, 9, and 13; the input of the fusion channel and spatial attention module is the feature maps of the first two scales of the neck network.

Citation Information

Patent Citations

  • Hazardous chemical vehicle detection method based on improved YOLOv5

    CN116863227A

  • Terahertz image hazardous article detection method based on multi-scale decomposition convolution

    CN117095158A