# Research on Seamless Fabric Defect Detection Based on Improved YOLOv8n
## 3 Improved YOLOv8n Seamless Fabric Detection Algorithm
### Modify the CARAFE Upsampling Method  
YOLOv8 uses the nearest neighbor interpolation method for feature map enlargement during the upsampling stage. Nearest neighbor interpolation achieves size expansion by copying the values of adjacent pixels. Still, due to its simple interpolation method, it is prone to generating jagged distortions at the edges of the image, resulting in noticeable visual artifacts. When dealing with complex tasks, preserving the high-precision texture  
Figure 4: SPPF_LSKA structure.  
Figure 3: Convolution Processing of LSKA.  
and detail information of the image is difficult, which may have a certain impact on the detection precision.  
To solve the above problems, YOLOv8 introduces CARAFE technology [23], an efficient feature recombination module performing well in visual tasks. CARAFE can significantly reduce information loss during feature reconstruction by adaptively learning the correlation between each pixel in the feature map, thereby preserving more image details, especially when dealing with complex textures and small object detection.  
CARAFE relies on adaptively generated convolution kernels to accurately capture subtle defects in fabric images, such as stains, folds, or color differences, thus meeting the detection needs of different colors and textures and having strong generalization ability. This technology can flexibly recombine features at different resolutions and feature scales, enabling the detection model to perceive the target area more comprehensively and improve detection precision. In addition, CARAFE has high scalability and compatibility. It can be integrated into existing deep learning frameworks without requiring significant changes to the backbone network or other structures, significantly enhancing the model's performance. The specific workflow of CARAFE can be divided into two main steps: Kernel Prediction: adaptively predicting a recombinant convolution kernel for the target pixel position in each feature map, dynamically generating feature distributions that adapt to different regions based on the content of the target area. Feature Reassembly: By utilizing generated adaptive convolution kernels to recombine input features, the ability to preserve image details and local textures is improved through more flexible feature fusion, which helps to detect small defects more accurately. Overall, the introduction of CARAFE in YOLOv8 not only improves the detection precision and stability of the model but also enhances its adaptability to small targets and complex textures, making it more suitable for high-precision seamless fabric defect detection tasks.  
For an input feature map with a size of H \(\times\) W \(\times\) C and an upsampling ratio of \(\sigma\), CARAFE will generate a new feature map with a size of \(\sigma\) H \(\times\)\(\sigma\) W \(\times\) C. The kernel prediction module generates convolution kernels for specific positions based on the content of input features, and then the content-aware recombination module uses these convolution kernels to complete feature recombination. The recombination formula is:  
\[X^{\prime}_{l^{\prime}}=\sum_{n=-r}^{r}\sum_{m=-r}^{r}W_{l^{\