# Fabric Defect Detection Based on Improved Lightweight YOLOv8n
## 3 Result and Discussion
### Comparison Experiments  
#### 3.5.1 Attention Mechanism SimAM Comparison Experiments  
To address the issue of background noise affecting the model's accuracy in detecting small fabric defects, this study incorporates SimAM into the end of the YOLOv8n backbone to enhance the network's capability of extracting global features. The attention mechanism module can be added to various parts of the YOLOv8 network, such as the backbone and feature extraction networks. To verify the impact of SimAM on algorithm performance when positioned differently within YOLOv8n, SimAM is embedded at the end of the backbone and within the neck network for comparative experiments with the original YOLOv8n model. \"YOLOv8n+backbone\" indicates SimAM embedded at the end of the backbone, while \"YOLOv8n+neck\" denotes SimAM embedded within the neck network. The experimental results are shown in Table 4.  
As shown in Table 4, when SimAM is embedded at the end of the backbone network, the AP values for three types of detection targets--fiber breaks, holes, and loose fibers--are the highest. Compared to the original YOLOv8 and the version with SimAM added to the neck network, the [EMAIL_ADDRESS] shows the best performance. Specifically, the AP values for holes and loose fibers are improved by 2.8% and 1.6%, respectively, over the YOLOv8 model. In summary, embedding the SimAM attention mechanism at the end of the backbone network significantly enhances the network's feature extraction capability, improving both the accuracy and robustness of target detection.  
To verify the advantages of the parameter-free attention module SimAM, this study added a Deformable Attention Transformer (DAttention), Bi-Level Routing Attention (BiFormer), Mixed Local Channel Attention (MLCA), and Convolutional Block Attention Module (CBAM) to the same position in the YOLOv8 network. These four commonly used attention mechanisms were compared with SimAM in the experiments. The experimental results are shown in Table 5.  
Table 5 experimental results show that introducing attention mechanisms at the end of the backbone network improves both Recall (R) and mean Average Precision at 0.5 ([EMAIL_ADDRESS]), thereby enhancing the model's ability to recognize defect features. Among the four mainstream attention mechanisms, SimAM achieved the highest improvement in FPS, indicating that SimAM helps the model extract and utilize features more efficiently, reducing redundant computations during inference and thereby increasing inference speed. Although CBAM performed best in terms of [EMAIL_ADDRESS], its Recall and FPS performance were average. In contrast, SimAM demonstrated superior overall performance across all metrics.  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline \multirow{2}{*}{**Model**} & \multicolumn{6}{c}{**AP/\%**} \\ \cline{2-7}  & **Float** & **Skips** & **Pilling** & **Hole** & **Pulling Out Yarn** & **Stain** & **[EMAIL_ADDRESS]/\%** \\ \hline YOLOv8n+backbone & 98.73 & 99.33 & 99.36 & 99.50 & 98.60 & 93.42 & 98.16 \\ YOLOv8n+neck & 98.95 & 98.52 & 99.50 & 96.60 & 97.66 & 93.21 & 97.41 \\ YOLOv8n & 99.30 & 98.80 & 99.30 & 96.70 & 97.00 & 94.90 & 97.70 \\ \hline \hline \end{tabular}
\end{table}
Table 4: Comparative experiments of different positions of attention in SimAM.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Model** & **GFLOPs/G** & **R/\%** & **FPS/(Frame-s-1)** & **[EMAIL_ADDRESS]/\%** \\ \hline YOLOv8 (base) & 8.1 & 94.80 & 239.6 & 97.70 \\ YOLOv8+ DAttention & 8.3 & 95.27 & 227.0 & 98.04 \\ +BiFormer & 8.4 & 95.99 & 260.7 & 97.97 \\ +MLCA & 8.1 & 95.71 & 288.1 & 97.89 \\ +CBAM & 8.1 & 95.12 & 280.3 & 98.45 \\ +SimAM & 8.1 & 95.31 & 301.5 & 98.16 \\ \hline \hline \end{tabular}
\end{table}
Table 5: Comparative experiments of different attention mechanisms.