# An Improved Target Network Model for Rail Surface Defect Detection
## 2 Methodology
### Improved YOLOv7 Network  
Traditional CNNs have large memory requirements and computational costs, making them unsuitable to run on mobile and embedded devices. To address this issue, the MobileNet [37] network was developed. The MobileNet series is widely used in object detection for its fast and accurate detection capabilities and has become a representative of lightweight networks. The entire architecture of MobileNetV3 largely follows the design of MobileNetV2, incorporating lightweight depthwise convolution (DWC) and residual blocks. As a lightweight network, MobileNetV3 stands out for using a neural architecture search (NAS) to build the network as well as integrating the depthwise separable convolutions and linear bottleneck inverted residual structures from MobileNetV1 and MobileNetV2. Additionally, it introduces the SE lightweight attention mechanism in network construction. MobileNetV3 has shown excellent performance in tasks such as mobile image classification, object detection, and semantic segmentation. The MobileNetV3 block incorporates features from both MobileNetV1 and MobileNetV2, including the depthwise separable convolution and the inverted residual structure with linear bottlenecks. The former reduces the model's computational load, while the latter increases the model's representativeness. Figure 2 displays the layout of the MobileNetV3 block.  
Figure 2: Structure of the MobileNetV3 block.  
DWC is a commonly used convolution operation in lightweight networks. Assuming the input feature map size is \(H\times W\times N\), DWC generates M DWC features after the convolution operation of M D \(\times\) D size convolution features.  
The computational cost of the standard convolution is:  
\[H\times W\times N\times D_{K}\times D_{K}\times M \tag{1}\]  
The computational cost of DWC is:  
\[D_{K}\times D_{K}\times N\times H\times W+M\times H\times W\times N \tag{2}\]  
The comparison of computational cost between DWC and standard convolution is:  
\[\frac{D_{\kappa}\times D_{\kappa}\times N\times H\times W+M\times H\times W \times N}{H\times W\times N\times D_{\kappa}\times D_{\kappa}\times M}=\frac{1} {M}+\frac{1}{D_{\kappa}{}^{2}} \tag{3}\]  
For the commonly used 3 \(\times\) 3 convolution kernel, DWC can reduce computational costs by approximately 90%, significantly lowering the computational burden. Figure 3 illustrates the implementation process.  
To ensure the real-time performance and improve accuracy, the SE lightweight attention mechanism is introduced into the network. First, global descriptive features are obtained through the squeeze operation; then, the excitation operation generates weights for each channel; lastly, the output weights of the excitation operation are used as importance indices of feature channels for the reweight operation, which weighs the previous features and recalibrates each channel dimension. Additionally, due to the high computational cost of the sigmoid function in the Swish activation function, which is significant in real-time applications, MobileNetV3 uses an improved h-swish activation function based on the Swish activation function to reduce computational cost effectively and achieve fast detection purposes. The expression of the h-swish activation function is Equation (4):  
\[h-swish(x)=x\cdot\frac{ReLU6(x+3)}{6} \tag{4}\]  
Substituting the traditional backbone network with the lightweight MobileNetV3 network enables a significant reduction in computational expenses and model size while preserving a satisfactory level of accuracy. This makes YOLOv7 more suitable for use in resource-constrained scenarios. The structure of the network used by the algorithm is shown in Figure 4.  
Figure 3: Schematic diagram of the DWC process.