# Research on an Insulator Defect Detection Method Based on Improved YOLOv5
## 3 Methodology
### Normalization-Based Attention Mechanism (NAM)  
The NAM serves as an efficient and lightweight attention mechanism [27]. Compared with other attention mechanisms, it does not require additional computations and parame  
Figure 3: IOU.  
ters such as full connectivity, convolution, etc. It adopts the modular integration of CBAM and redesign the attention submodules of channel and space.  
For the channel attention submodule, the scale factor in batch normalization (BN) is used to measure the variance of the channels and indicate their importance, as shown in (3).  
\(\mu_{\beta}\) and \(\sigma_{\beta}\) are the mean and variance, respectively, of the small batch and are the trainable affine transformation parameters. The channel sub-attention module is shown in Figure 4 and (4).  
\[B_{out}=BN(B_{in})=\gamma\frac{B_{in}-\mu_{\beta}}{\sqrt{\sigma_{\beta}^{2}+ \epsilon}}+\beta \tag{3}\]  
\[M_{c}=sigmoid(w_{r}(BN(F_{1}))) \tag{4}\]  
\[M_{s}=sigmoid(w_{\lambda}(BN_{s}(F_{1}))) \tag{5}\]  
\[Loss=\sum_{(x,y)}l(f(x,W),y)+p\sum g(\gamma)+p\sum g(\lambda) \tag{6}\]  
where \(M_{c}\) represents the output features, \(\gamma\) is the scaling factor of each channel, and \(F_{1}\) is the input feature with the weight \(w_{\gamma}=\gamma_{i}/\sum_{j=0}\gamma_{j}\), so we can obtain the weights of each channel.  
For its spatial attention submodule, the scale factor of BN is applied to the spatial dimension to measure the importance of pixels. It is called pixel normalization. The corresponding spatial attention submodule is shown in Figure 5 and (5).  
Figure 4: The channel attention module.  
Figure 5: Spatial attention module.  
where the output features are denoted as \(M_{\rm S}\). \(\lambda\) is the scaling factor. The weights are \(W_{\lambda}=\lambda_{i}/\sum_{j=0}\lambda_{j}\). To suppress the less significant weights, we add a regularization term to the loss function, as shown in (6), where x denotes the input; y is the output; W represents the network weight; \(\rm{l(\cdot)}\) is the loss function; \(\rm{g(\cdot)}\) is the \(\rm{l_{1}}\) parametric penalty function, and is the balance of \(\rm{g(\gamma)}\) and \(\rm{g(\lambda)}\) of the penalty. The loss value is denoted as (6).  
The effectiveness of the NAM attention mechanism varies with the additional position, and the depth of the module affects the insertion position of the attention. In this paper, the NAM module is integrated into the YOLOv5s model. Through continuous network training, the module is eventually inserted into the neck part of the upsampled position. The core of this is to use multiple pools of different sizes to sample the obtained feature maps (pooling) for feature extraction. We add the NAM attention mechanism behind this, which can reduce the weight of less essential features. This approach applies a sparse weight penalty to the attention module, which makes the computation of these weights more efficient. With this method, channel and spatial dimensions can be better integrated to reacquire channel features and spatial location information of insulator defect images, which not only extracts useful essential location information of insulator defects but also identifies the class of defects more quickly and accurately. It helps to improve the accuracy of network detection.