# A Visual Fault Detection Algorithm of Substation Equipment Based on Improved YOLOv5
## 2 Framework
### YOLOv5 Algorithm Improvements
#### 2.1.2 Feature Network Improvements  
Neck is commonly used in models for better feature fusion and image feature extraction, reducing redundant information by reducing the dimension of feature maps and enhancing feature representation capabilities by fusing features at different levels. As shown in Figure 7a, an efficient PANet method is proposed and adopted for the first time in YOLOv5, which proves the effectiveness of the bidirectional fusion scheme by performing quadratic feature fusion from the bottom up. However, in this paper, BiFPN achieves better results as a complex cross-level and cross-scale bidirectional fusion method, as shown in Figure 7b. Due to the small number of individual type pixels of defect images in the past dataset, the backbone network can effectively identify some shallow features defects, and when it comes to difficult to identify defects, deeper features may produce a large number of feature maps due to the complexity and depth of the network, containing rich information but also containing some redundant or irrelevant information. Through BiFPN, the information transfer and fusion between different levels of the feature pyramid introduces more connections and backpropagation, which can better capture targets at different scales.  
Figure 5: Traditional CSP module.  
Figure 6: Improved CSP module.  
In the feature network design, BiFPN changes the feature extraction and feature fusion methods on the basis of PANet and adds upsampling between different levels to enable the feature map to transmit and fuse information between different scales. This fusion method is not a simple series or superposition, but an adaptive fusion weight calculation method, which can automatically adjust the weight according to the resolution of the feature map to improve the fusion effect. On top of PANet, if the original input feature and the output feature are expressed at the same level, BiFPN does not add extra edges between them to fuse more features and therefore does not add too much extra computation. In this paper, BiFPN adjusts and optimizes the network by using the adaptive weighted fusion strategy of fast normalization fusion.  
Fast normalized fusion and softmax-based fusion share similar learning methods and accuracy, as shown in the following equation:  
\[O=\sum_{i}\frac{w_{i}}{\mathcal{E}+\sum_{j}w_{j}}I_{i} \tag{7}\]  
where \(w_{i}\) is a learnable weight, \(w_{i}\) > 0 is passed after the ReLU, and each normalization weight is between 0 and 1.  
As a specific example, the fusion of two features shown in the sixth layer of Figure 7b can be described as follows:  
\[p_{6}^{td}=Conv(\frac{w_{1}P_{6}^{in}+w_{2}Resize(P_{7}^{in})}{w_{1}+w_{2}+ \mathcal{E}}) \tag{8}\]  
\[p_{6}^{out}=Conv(\frac{w_{1}^{\prime}P_{6}^{in}+w_{2}^{\prime}P_{6}^{id}+w_{3} ^{\prime}Resize(P_{5}^{out})}{w_{1}^{\prime}+w_{2}^{\prime}+w_{3}^{\prime}+ \mathcal{E}}) \tag{9}\]  
where \(P_{6}^{td}\) is the intermediate feature of level 6 in the up and down path, and \(p_{6}^{out}\) is the output feature of level 6 in the bottom-up path, \(\overrightarrow{p^{in}}=(p_{1}^{in},p_{1}^{in},\ldots,p_{l}^{in})\), \(\overrightarrow{p^{in}}\) represents the input multiscale feature list, \(\overrightarrow{p^{in}}\) represents the input feature of horizontal \(l_{i}\), \(\overrightarrow{p^{in}}=(p_{l}^{id},p_{l}^{td},\ldots,p^{id})\) represents the intermediate feature list on the path, and \(\overrightarrow{p^{in}}\) outputs a new \(p^{out}\) by aggregating a series of different characteristics.