# An Improved YOLOv8 Model for Strip Steel Surface Defect Detection
## 2 Improved YOLOv8 Detection Principle
### Polarized Self-Attention Mechanism  
PSA combines polarization filtering and enhancement design to improve pixel-wise regression, enabling the model to handle defect information more accurately. The PSA mechanism was introduced to optimize information transfer and suppress background noise, aiming to enhance the model's robustness in complex scenarios. Existing studies have shown that this mechanism can effectively improve detection accuracy. For instance, [PERSON] et al. [37] integrated the PSA mechanism into the YOLOv8 model for underwater target recognition, enhancing feature polarization across both channel and spatial dimensions, improving pixel-level prediction accuracy, and enabling lightweight edge deployment.  
Figure 5: RFB structure diagram.  
Figure 6: Structure diagram of SCRD.  
Similarly, [PERSON] and [PERSON] [38] applied the polarized self-attention mechanism during feature extraction in a photovoltaic cell defect detection system, combining spatial and semantic features with the original input to enhance the network's feature representation capability. These studies provide strong support for the effectiveness of the PSA mechanism in improving model performance.  
The structure of the PSA is shown in Figure 7. In the channel attention module, 1\(\times\)1 convolution is used to convert feature X into Q and V. The Q channel is fully compressed, and the operator \(F_{SM}\) is used to enhance the Q information, while the V channel still maintains the number of \(C/2\) channels. After matrix multiplication of Q and K, the dimension is raised to \(C\) by 1 \(\times\) 1 convolution and normalization layer. Finally, the parameters are calculated by using the activation function. The channel branch weights \(A^{ch}(X)\) are calculated as follows, where \(W_{q}\), \(W_{k}\), \(W_{v}\) are 1 \(\times\) 1 convolutional layers, \(F_{GP}\) is the global pooling operation, \(\sigma_{1}\), \(\sigma_{2}\) are two tensor reshape operators, and \(\times\) is the matrix dot-product operation:  
\[A^{ch}(X)=F_{SG}\Big{\{}W_{z|\theta_{1}}((\sigma_{1}(W_{v}(X))\times F_{SM}( \sigma_{2}(W_{q}(X))))\Big{\}} \tag{2}\]  
where \(X\) represents the input features, \(F_{SG}\) denotes the nonlinear activation function, \(W_{z}\) is the learnable weight matrix, and \(\theta_{1}\) is the associated hyperparameter of this weight matrix. \(W_{v}(X)\) represents a linear transformation of X, where \(W_{v}\) is the weight matrix. \(F_{SM}\) stands for the Softmax function, and \(W_{q}(X)\) generates a representation of \(X\) that is related to the query.  
Similarly, in the spatial attention module, 1 \(\times\) 1 convolution is used to transform features into Q and V. For Q, global pooling is used to compress the spatial dimension, and then, the Softmax operator is used to enhance Q, and V remains unchanged. The spatial branch computes the weight \(A^{sp}(X)\) as follows, and \(\sigma 3\) is the tensor reshape operator. \(F_{SG}\) represents the nonlinear activation function, \(\sigma_{1}\), \(\sigma_{2}\), and \(\sigma_{3}\) are activation functions for processing linear transformations, \(F_{GP}\) denotes the global pooling operation, and \(W_{q}(X)\) and \(W_{v}(X)\) are linear transformation matrices:  
\[A^{sp}(X)=F_{SG}\big{\{}\sigma_{3}(F_{SM}(\sigma_{1}(F_{GP}(W_{q}(X))))\times \sigma_{2}(W_{v}(X)))\big{\}} \tag{3}\]  
Figure 7: Structure diagram of PSA.  
\(PSA_{p}(X)\) is obtained by parallel fusion of the above two branch outputs, where \(ch\) is a channel-wise multiplication operator.  
\[PSA_{p}(X)=A^{ch}(X)\odot^{ch}X+A^{sp}(X)\odot^{sp}X \tag{4}\]