# A Visual Fault Detection Algorithm of Substation Equipment Based on Improved YOLOv5
## 2 Framework
### YOLOv5 Algorithm Improvements
#### 2.1.1 Fusion-Deformable Convolutional Modules  
In order to enhance the semantic distinguishability of the YOLOv5 model for substation equipment defect detection, we propose an improvement measure, which is the introduction of deformable convolutions. Traditional convolution operations can only sample the input feature maps in a fixed manner and cannot handle variations in target shape. However, in substation equipment defect detection, targets with different scales and shapes may coexist at different positions within the same feature layer, which limits the flexibility of object detection. To address this issue, we introduce deformable convolutions. Deformable convolutions can adaptively learn the sampling positions and shapes to better accommodate the shape variations of the targets. It transforms the sampling point positions in traditional convolutions into learnable forms, enabling the network to learn more expressive feature representations. In the improved YOLOv5 detection model, we incorporate deformable convolutions into the backbone network. This allows for better  
Figure 2: Improved YOLOv5 framework. feature extraction and small object detection in substation equipment defect detection, thus improving the performance of the model. Figure 4 shows a schematic diagram of a 3 \(\times\) 3 deformable convolution. In deformable convolutions, the convolution layer can calculate offsets relative to the input feature map and use these offsets to sample the input feature map. This allows for modeling transformations of the targets. The deformable convolution kernel is distributed spatially in the same layer as the current convolution layer, with offset size matching that of the input feature map. These offsets can be directly applied to each pixel in the input feature map for position shifting and adjustment. Figure 3: Algorithm flowchart. In previous work [40], the convolution operation was performed using a fixed-size matrix R to sample the input feature map. This approach had limitations in terms of receptive field size and dilation. Subsequently, convolutional kernel weighting was applied to the sampled points. \[R=\left[ \begin{array}{ccc}(-1,-1)&(-1,0)&(-1,1)\\ (0,-1)&(0,0)&(0,1)\\ (1,-1)&(1,0)&(1,1)\end{array} \right] \tag{1}\]  
For each position \(P_{n}\) in the output feature map, its expression is as follows:  
\[y(p_{0})=\sum w(p_{n})x(p_{0}+p_{n}) \tag{2}\]  
where \(p_{n}\) represents an unknown enumeration listed in R.  
In the operation of deformable convolution, a regular network is used to convolve and sample the input feature map. The collection of sampled positions is shifted by combining the offset with the predicted weight \(\triangle m_{n}\) for each sampling point. It can be represented as:  
\[y(p_{0})=\sum_{p_{n}\in R}w(p_{n})x(p_{0}+p_{n}+\triangle p_{n})\triangle m_{n} \tag{3}\]  
where \(\triangle p_{n}=1,2,\ldots,N\) represents the offsets, \(p_{n}+\triangle p_{n}\)is the sampling point after the offset, and \(\triangle p_{n}\) is typically a fractional value that cannot accurately obtain the pixel value of that position. Therefore, the pixel value of x can be calculated using bilinear interpolation as follows:  
\[g(a,b)=max(0,1-|a-b|) \tag{4}\]  
\[G(q,p)=g(q_{x},p_{x})\times g(q_{y},p_{y}) \tag{5}\]  
\[x(p)=\sum_{q}G(q,p)\times x(q) \tag{6}\]  
where \(p=p_{0}+p_{n}+\triangle p_{n}\) is the offset position, \(x(q)\) is the pixel value of the four known neighboring pixels in the feature map, and G(\(\cdot\),\(\cdot\)) represents the weights corresponding to the four coordinates. The traditional Cross-Stage Partial (CSP) module divides the feature map into two branches to extract features and then merges them hierarchically, reducing computational  
Figure 4: Schematic diagram of 3 \(\times\) 3 deformable convolution. complexity while maintaining accuracy.