# A Lightweight Method for Detecting Sewer Defects Based on Improved YOLOv5
## 2 Lightweight YOLOv5 Sewer Defect Detection Model
### Lightweight Backbone Network  
Traditional convolution operations generate a large number of redundant feature maps, which often contain many similar parts [19]. Although redundant feature maps can effectively improve the detection accuracy of the model, a large number of convolution operations will also increase the calculation load, which is not conducive to lightweight deployment of the model.  
To address this issue, this paper proposes a lightweight network called GhostNet [20] based on the Ghost module to improve the original backbone network. Compared with other lightweight networks such as MobileNet [21] and ShuffleNet [22], GhostNet has better detection performance and can significantly reduce the computational cost required for ordinary convolutions while maintaining detection accuracy stability. The main idea is to obtain redundant feature layer information through low-cost linear operations, thereby generating more feature information with fewer parameters. The convolution process of the Ghost module is shown in Figure 2, and mainly consists of three steps. The first step is to generate some feature maps through traditional convolution to avoid redundancy. The second step is to generate another part of redundant feature maps through simple linear transformations of the generated feature maps. The third step is to superimpose these two parts of feature maps to achieve the effect of simulating ordinary convolution.  
Taking \(k\times k\) ordinary convolution as an example, when the number of input feature channels is C and the output feature size is \(H\times W\times N\), the computational cost is:  
\[C\times k\times k\times N\times H\times W \tag{1}\]  
Assuming the number of output feature channels in the first step of the Ghost module is m, \(s=N/m\) there are \((s-1)\times m\) linear transformations in the second step, and the size of the convolution kernel is the same \(k\times k\). The computational cost is:  
\[C\times k\times k\times m\times H\times W+(s-1)\times k\times k\times m\times H\times W \tag{2}\]  
Figure 2: The Ghost convolution process.  
As can be seen, the ratio of computational cost of the model is:  
\[r_{s}=\frac{C\times k\times k\times N\times H\times W}{(C+s-1)\times k\times k \times m\times H\times W}=\frac{C\times s}{C+s-1}\approx s \tag{3}\]  
The ratio of model size is:  
\[r_{c}=\frac{C\times k\times k\times N}{C\times k\times k\times m+(s-1)\times k \times k\times m}=\frac{C\times s}{C+s-1}\approx s \tag{4}\]  
Compared to regular convolution, both the parameter and computational cost compression ratios of the Ghost module are S, which can effectively reduce the size of the model and improve detection speed. In this paper, S is set to 2.  
The bottleneck structure composed of Ghost modules consists of two cases: The G-Bottleneck-1 structure has a stride of 1, consisting of two Ghost modules. The first module expands the channel number of the convolution, the second module reduces the channel number, and the input and output are added through a residual edge, as shown in Figure 3a. The G-Bottleneck-2 structure contains two Ghost modules and a depth-wise separable convolution module, in which the stride of the depth-wise separable convolution is 2, thus compressing the width and height of the feature layer, as shown in Figure 3b. Using G-Bottleneck-1 and G-Bottleneck-2 to construct the lightweight feature extraction network GhostNet, and replacing the original backbone network in YOLOv5, can effectively reduce the volume and computing power of the model, as shown in the network structure in Figure 1.