# Research on an Insulator Defect Detection Method Based on Improved YOLOv5
## 3 Methodology
### Recursive Gated Convolutions (\(\rm{g^{n}Conv}\))
#### 3.3.2 Higher-Order Interactions for Recursive Gated Convolution  
After achieving an effective first-order spatial interaction with gConv, a recursive gated convolution-g\({}^{\text{n}}\)Conv is designed to further enhance the capacity of the algorithmic model by introducing higher-order interactions.  
We start with \(x\) after a higher-order linear projection to obtain the features \(p_{0}\) and \(\{q_{k}\}_{k=0}^{n-1}\) as shown in (9). Then, recursively executing the gated convolution, we can sequentially obtain \(p_{k+1}\) as shown in (10). Here the output is scaled to \(1/\alpha\) for stable training. \(\{f_{k}\}\) is a set of deep convolutional layers, and \(\{g_{k}\}\) is used for dimensional alignment at different orders of, as shown in (11).  
As shown in (10), the interaction order of \(p_{k}\) increases by \(1\) for each recursive order, and the output of the last recursive step \(q_{n}\) is input to the projection layer \(\phi_{out}\) to obtain the result of g\({}^{\text{n}}\)Conv, so g\({}^{\text{n}}\)Conv can perform spatial interaction of n orders.  
To ensure that higher-order interactions do not introduce a tremendous computational effort, the channel dimension of each order is set to (12); (12) indicates that higher-order spatial interactions will be performed in a coarse-to-acceptable manner, where lower orders are computed with fewer channels.  
g\({}^{\text{n}}\)Conv is not designed to mimic only the aspect of self-attention. It has the following three advantages: (1) Simplicity and efficiency: The convolution-based implementation avoids the secondary complexity of self-attentiveness. Performing spatial interactions progressively increases the channel width, allowing the model to achieve higher-order interactions with limited complexity; (2) Scalability: We use the second-order interactions in self-attention to extend to arbitrary orders, further improving the detection capability of the model; (3) g\({}^{\text{n}}\)Conv fully inherits the translational equivariance of standard convolution, introducing a functional inductive bias for current defect detection tasks and avoiding the asymmetry caused by local attention.  
Because the neck part of the YOLOv5 model is a further depth to the feature extraction, we applied the g\({}^{\text{n}}\)Conv recursive gate convolution to the neck part, replacing the original ordinary standard convolution, and obtained the best results through experiments, reflecting the efficiency of accurate recognition of defects in insulators. Figure 7 shows the network structure of the improved optimal model.  
\[\left[p_{0}^{HW\times C},q_{0}^{HW\times C}\right]=\phi_{in}(x)\in\mathbb{R}^ {HW\times 2C} \tag{7}\]  
\[p_{1}=f(q_{0})\odot p_{0}\in\mathbb{R}^{HW\times C},y=\phi_{out}(p_{1})\in \mathbb{R}^{HW\times C} \tag{8}\]  
\[\left[p_{0}^{HW\times C},q_{0}^{HW\times C},\cdots q_{n-1}^{HW\times C_{n-1}} \right]=\phi_{in}(x)\in\mathbb{R}^{HW\times(C_{0}+\sum_{\partial\leq\leq\pi-1}C _{k})} \tag{9}\]  
\[p_{k+1}=f_{k}(q_{k})\odot g_{k}(p_{k})/\alpha,k=0,1,\cdots,n-1 \tag{10}\]  
\[g_{k}=\left\{\begin{array}{c}\text{Identity}\quad\quad k=0\\ \text{Linear}(C_{k-1},C_{k})\quad 1\leq k\leq n-1\end{array}\right. \tag{11}\]