# A Lightweight Method for Detecting Sewer Defects Based on Improved YOLOv5
## 2 Lightweight YOLOv5 Sewer Defect Detection Model
### Improving the Feature Fusion Network  
In the process of feature extraction, shallow features usually contain detailed spatial information, deep features contain rich semantic information, and single-scale features often have limited representation capabilities. Therefore, effective fusion of features of different scales is crucial for object detection tasks.  
Traditional FPN networks only have one top-down information fusion path. In order to improve its one-way structure, PANet adds a bottom-up path based on FPN, which improves the fusion effect between high-level semantic information and low-level spatial information. However, this method also has a larger computational cost and does not consider the contribution of different input features. Therefore, based on the idea of weighted feature fusion and feature residual connection in BiFPN, this paper constructs a new feature fusion network called WR-PANet, as shown in Figure 4.  
Figure 3: G-Bottleneck network structure. (**a**) G-Bottleneck-1; (**b**) G-Bottleneck-2.  
As shown in Figure 4, compared with the PANet network, in order to improve the efficiency of feature fusion, BiFPN ignores nodes with only one input edge. Secondly, BiFPN adds a residual connection between feature layers of the same scale, which can fuse more features and improve the positioning ability of defect targets without increasing computational cost.  
Since different input features have different scales and different contribution levels compared to the nodes in feature fusion, BiFPN adopts a weighted feature fusion method and adds additional weight parameters for different input features. Weighted feature fusion uses a fast normalization calculation method, as shown in Formula (5).  
\[O=\sum_{i}\frac{\omega_{i}\times I_{i}}{\epsilon+\sum\limits_{j}\omega_{j}} \tag{5}\]  
In the equation, \(\omega_{i}\) is the weight of different input features, by network training, \(I_{i}\) is the input feature, and \(\epsilon\) is the initial learning rate.  
\[\begin{split} P4^{td}=Conv\Big{(}\frac{\omega_{1}\times P4^{it} +\omega_{2}\timesresize(P5^{it})}{\omega_{1}+\omega_{2}+\epsilon}\Big{)}\\ P4^{out}=Conv\bigg{(}\frac{\omega_{1}^{\prime}\times P4^{it} +\omega_{2}^{\prime}\times P4^{it}+\omega_{3}^{\prime}\timesresize(P5^{out}) }{\omega_{1}^{\prime}+\omega_{2}^{\prime}+\omega_{3}^{\prime}+\epsilon}\Big{)} \end{split} \tag{6}\]  
The process of feature fusion is shown as Formula 6. In the equation, \(P4^{td}\) and \(P4^{out}\) are the intermediate feature and output characteristic of the fourth layer, \(P5^{it}\) is the input feature of the fifth layer, \(P3^{out}\) is the output feature of the third layer, resize is the up sampling and down sampling operation, and \(Conv\) represents the convolution operation.  
On the other hand, because defects such as cracks are usually small, as the network deepens, the backbone network inevitably loses more detailed information during the down sampling process, which leads to poor performance in detecting small targets. Unlike deep networks that contain rich semantic information, shallow networks contain more spatial position information and are more helpful in determining the accurate location of targets. Therefore, this paper transfers the features extracted from a shallow layer to the neck network for fusion, and adds a prediction head for detecting small targets to improve the detection ability of small defects.