# Leather Defect Detection Based on Improved YOLOv8 Model
## 4 Improved YOLOv8-AGE Algorithm
### Ema  
In the development of attention mechanisms, both channel attention and spatial attention have been shown to be highly effective in producing more discriminative features. However, channel attention primarily focuses on the channel dimension and may overlook important spatial information. On the other hand, spatial attention requires more computational resources. To address this, an Efficient Multi-scale Attention mechanism (EMA) was introduced in this study. To address the interference of background texture in defective samples, the attention mechanism can better focus on key regions in the image, thereby improving defect detection accuracy. The structure of the EMA is shown in Figure 8.  
Figure 7: GSBottleneck module and VoV-GSCSP architecture. The EMA consists of three parallel paths: two 1 \(\times\) 1 convolutional branches and one 3 \(\times\) 3 convolutional branch. The 1 \(\times\) 1 and 3 \(\times\) 3 branches in the EMA module collaborate to enhance feature representation. The 1 \(\times\) 1 branch encodes channel information across two spatial dimensions using two 1D global averaging pooling operations and then merges the features through 1 \(\times\) 1 convolution to aggregate channel attention maps, enhancing cross-channel interactions among different subfeatures. Conversely, the 3 \(\times\) 3 branch captures local cross-channel interactions using a 3 \(\times\) 3 convolutional kernel, expands the feature space, and focuses on multi-scale feature representations to enhance detail perception. The cross-space learning approach further aggregates the outputs of the 1 \(\times\) 1 and 3 \(\times\) 3 branches, encodes global spatial information through 2D global average pooling, and fuses spatial information at different scales using matrix dot product operations. Finally, it generates spatial attention maps that capture pixel-level pairwise relationships and highlight the global context, thereby improving the model's accuracy in detecting regions of interest. Compared to SE, EMA not only captures channel information but also takes into account direction-related positional information, which aids the model in better localization and recognition of targets. Additionally, EMA is flexible and lightweight enough to be easily integrated into the core structure of mobile networks and can serve as a pre-trained  
Figure 8: Structure of EMA (* stands for Re-weight). model for various tasks, such as detection and segmentation, where it demonstrates performance improvements. In contrast to CBAM, EMA achieves performance enhancement while maintaining a low additional computational cost, with a design that considers computational efficiency. It employs global pooling and simple convolutional operations, enabling performance improvements without incurring excessive computational expenses. Additionally, the C2f module within the Yolov8 Backbone is capable of processing and transforming the features of input data, generating outputs with enhanced representational power, thereby improving the network's performance and representational capabilities. The C2f module extracts and transforms the features of input data through operations such as feature transformation, branch processing, and feature fusion. It first passes the input data through a convolutional layer, then segments the results according to a specified size, storing them in a list. Subsequently, these segments are further processed through a Bottleneck module, and finally concatenated along dimension 1. The concatenated results are then passed through another convolutional layer to obtain the final output. This design enables the C2f module to effectively extract features and enhance the model's detection capabilities for objects of varying scales. In summary, the EMA module enhances feature representation, while the C2f module provides robust feature fusion capabilities. The combination of these two modules can more effectively extract and utilize the interdependencies among features, thereby improving the accuracy of feature extraction.