## 3 Materials and Methods
### Improved YOLOv586 Yarn Hairiness Structure  
The YOLOv586-Yarn Hairiness deep neural network was designed with selected modules to detect and classify yarn hairiness. The improvements implemented were  
1. **The integration of the C2f Module of the YOLOv8 advanced version:** the addition of the Cross-Stage Partial Networks Fusion (C2f) module enhances feature fusion at different stages, significantly improving the detection of fine details in yarn images, crucial for identifying hairiness types. 2. **Bot-Transformer modules in the neck:** these modules, using multi-head self-attention mechanisms, allow the model to focus on relevant features in complex yarn images, improving accuracy in detecting loops and protruding fibers. 3. **GeLU activation function:** Gaussian Error Linear Unit (GeLU) activation functions were used in certain layers to replace ReLU or SiLU, increasing the model's sensitivity to detect loop and protruding fibers. 4. **Optimization of hyperparameters:** The anchor_t value was set to 5.0 to prioritize larger anchors, enhancing the model's ability to detect varying sizes of hairiness in  
Figure 4: Network structure for YOLOv586 ((**A**): The complete structure with backbone, neck, and head modules. (**B,C**): Two unique variations of CSP blocks (C3); (**D**): CBS—Convolutional Batch Normalization layer and SILU activation function; (**E**): Other blocks with CBS; (**F**)—Two distinct bottleneck blocks) [45; 46; 47]. high-resolution images. Additionally, the scale factor was adjusted to 2.0, allowing the neural network to resize images and capture more details, making smaller features like loop and protruding fibers more detectable. The YOLOv5s6 architecture was used among the available versions of YOLOv5 and YOLOv8. Several basic tests were performed, and this model was the one that gave the best overall results compared to other variants of the algorithm. Due to the remarkable performance of the YOLOv5s6 in hairiness detection, an improved YOLOv5s6 network called YOLOv5s6-Yarn Hairiness incorporating a Bot transformer, a C2f module, and a Gaussian Error Linear Unit (GeLU) activation function was developed, as shown in Figure 5.  
When analyzing loop and protruding fibers in yarns using the YOLOv5s6 model, each block enhances the detection of these hairiness types:  
Figure 5: Improved architecture of YOLOv5s6-Yarn Hairiness Algorithm [(**A**): The complete structure with backbone, neck, and head modules; (**B**): Module CBG in the optimized YOLOv5s6-Yarn Hairiness (**C3**); (**C**): Module CBG used in other blocks; (**D**): Module CBG used in other two different types of bottleneck blocks; (**E**): Two distinct types of CSP blocks (C3) [45; 46; 47]; (**F**): C2f module (bottom); (**G**): The architecture of Bot-transformer block. (**a**) BottleneckTransformer*x means there are x number of BottleneckTransformer blocks stacked, and each BottleneckTransformer is showed in (**b**) [48; 49; 50]. 1. Backbone * **Function**: extracts relevant features from yarn images, capturing edges, textures, and patterns. * **Impact**: an efficient backbone improves the accuracy of detecting distinctive features of loop and protruding fibers. 2. NECK * **Function:** combines information at different scales, supporting the detection of objects of varying sizes. * **Impact**: As loop and protruding fibers can vary in size, the Neck helps the model capture contextual information at multiple scales. This is especially useful for detecting smaller or more diffuse hairiness, improving accuracy by considering the context around these features. 3. HEAD * **Function:** responsible for object detection, including generating predictions for bounding boxes and object classes. * **Impact:** The Head enables the model to accurately locate and classify fibers. Bounding box predictions define the position and size of hairiness, while class predictions differentiate between loop and protruding fibers. Each block contributes critically to the detection process.