## 2 Methods
### Improved YOLOv7 Network Model  
In this paper, YOLOv7 is used as the benchmark model, and it is a single-stage detection algorithm with both speed and accuracy advantages over its predecessor. The YOLOv7 algorithm incorporates the strategies of concatenation-based model scaling, extended efficient long-range attention network (E-ELAN), and RepVGG structure re-parameterisation [23], etc. Its network structure consists of three parts: Backbone, Neck, and Head, respectively. The YOLOv7 network's structure is shown in Figure 4.  
The backbone consists of the convolutional basic block (CBS), the efficient layer aggregation net (ELAN) module, and the maximum pooling module (MP). The CBS module consists of a convolutional layer (Conv), a batch normalisation layer (BN), and a SiLu activation function layer, which are mainly used for feature extraction. The ELAN module branches feature maps at different scales through different depths. Then, it finally splices them together so that the deeper network can be efficiently learned and converged. The main function of the MP module is downsampling. By splicing the maxpool downsampling branch and the convolution downsampling branch, the feature maps obtained by different downsampling methods are fused, which retains as much feature information as possible without increasing the amount of calculation. Neck consists of the feature pyramid (FPN), path aggregation module (PAN), and spatial pyramid pooling (SPPCSPC), and it is responsible for fusing features from different feature layers of the backbone network and from various scales of the detection layer to generate features that carry richer information. The neck fusion network fuses the feature maps from the backbone network at three different scales with the sampled feature maps on this network separately to retain both the abstract features from the deep network and the semantic information from the shallow network. The detection head (Head) branches the three different sizes of feature maps output from the neck for multiscale prediction and accelerates the model inference through the re-parameterisation module (RepVGG Block, REP). To improve the performance of the terahertz image contraband recognition model, the following three parts are the improvements made to the YOLOv7 model. Figure 4: YOLOv7 model structure diagram. (1) The large number of stacked ELAN modules in the original backbone network of YOLOv7 leads to too many parameters in the network and a large amount of computation. In this paper, the SPD_Mobile network is used as a lightweight backbone network. The network adopts the Sandglass structure proposed in MobileNeXt, and its structure is shown in Figure 5. The Sandglass structure is designed according to the inverse residual structure in MobileNet V2, which solves the problem of gradient dispersion or gradient explosion caused by the residual structure in MobileNet-V2 and improves the accuracy of the model. The structure follows the depth-separable convolution (Dwise) [24] approach of MobileNet V1 to achieve a greater efficiency and a low weight. The structure of depth-separable convolution (Dwise) is shown in Figure 6. The module consists of two parts: layer-by-layer convolution (depthwise convolution) and point-by-point convolution (pointwise convolution). Depthwise convolution is used for spatial filtering, and its procedure is that the convolution is performed individually on each channel of the input feature map of size \(H_{1}\times W_{1}\), and the number of channels is \(C_{int}\), the size of convolution kernel is generally \(k\times k\times C_{in}\), and the number of output channels is consistent with the input. Pointwise convolution is used for information fusion; it combines the feature maps obtained in the previous step (depthwise convolution) to generate new feature maps, the size of convolution kernel is \(1\times 1\times C_{out}\), the number of output channels \(C_{out}\) is consistent with the number of convolution kernels, and the size of the output feature maps is \(H_{2}\times W_{2}\).