# Steel Surface Defect Detection Based on YOLOv8-TLC
## 3 YOLOv8-TLC Algorithm
### Large Selective Kernal-Attention  
For steel surface defect images, the dataset consists of grayscale images, which results in unclear boundaries between defects and the background, causing them to blend together. This makes it difficult to distinguish between defect targets and the background, while also presenting a significant size variation among the targets. To address these issues, we introduce LSK-Attention into the feature fusion network to fully explore and integrate the spatial structural information needed for defect detection, further enhancing feature fusion. Traditional spatial attention mechanisms have a relatively narrow range of background information when extracting spatial features, which does not guarantee the extraction of ideal spatial characteristics. The adaptive attention mechanism helps the model focus on important areas, thereby improving the accuracy and robustness of target detection. The LSK model adapts to the varying requirements for background information based on different types of targets by transforming larger convolution kernels into a sequence of different kernels, dynamically selecting relevant feature maps for spatial combination. This not only reduces the computational load but also enhances the model's adaptability to targets of different sizes, making it more efficient. The main idea of LSK-Attention is to effectively weigh and spatially fuse features across different receptive fields by utilizing spatial information at various scales, integrating both global and local features, thus better consolidating information and improving feature representation capability. The structure of LSK-Attention is shown in Figure 3. \begin{table}
\begin{tabular}{c c c c} \hline
**Detecting Feature Map Size** & **80 \(\times\) 80** & **40 \(\times\) 40** & **20 \(\times\) 20** & **10 \(\times\) 10 (Additional)** \\ \hline Receptive fields & Small & Medium & Large & Extra Large \\ \hline \end{tabular}
\end{table} 
Table 1: Added dimensions of the detection layer. Figure 2: Structure diagram of YOLOv8-TLC model. The main process of LSK-Attention [35] is as follows: it utilizes convolution kernels with varying receptive fields to extract rich background features from different regions of the input data X.  
\[\mathrm{U}_{0}=\mathrm{X},\mathrm{U}_{1}=F^{5*5}(\mathrm{U}_{0}),\mathrm{U}_{2}=F ^{7*7}(\mathrm{U}_{1}) \tag{1}\]  
In this context, \(F^{5*5}\) represents the depth convolution operation with a kernel size of 5 and a dilation rate of 1, while \(F^{7*7}\) denotes the depth convolution operation with a kernel size of 7 and a dilation rate of 3. To accommodate the contextual information of different target types, LSK-Attention dynamically adjusts the receptive field to better match various targets and backgrounds. Additionally, it dynamically selects suitable convolution kernels based on the local information of the input feature maps. After each convolution operation, a 1 \(\times\) 1 convolution layer is used to achieve channel fusion of the spatial feature vectors. \[\widetilde{\mathrm{U}}_{i}=F_{i}^{1*1}(\mathrm{U}_{i}) \tag{2}\]  
Then, the feature maps from different receptive fields are concatenated using Formula (3). \[\widetilde{\mathrm{U}}=[\widetilde{\mathrm{U}}_{1};\ldots\ldots;\widetilde{ \mathrm{U}}_{i}] \tag{3}\]  
Next, channel-level average pooling \(P_{avg}\) and maximum pooling \(P_{max}\) are employed to extract spatial relationships. \[\mathrm{SA}_{avg}=P_{avg}(\widetilde{\mathrm{U}}),\mathrm{SA}_{max}=P_{max}( \widetilde{\mathrm{U}}) \tag{4}\]  
Here, \(\mathrm{SA}_{avg}\) and \(\mathrm{SA}_{max}\) represent the spatial feature descriptors obtained from average pooling and maximum pooling, respectively. Subsequently, convolution layer \(F^{2\to N}\) is used to transform these descriptors into a spatial attention map, facilitating information interaction between the spatial descriptors.