# A Strawberry Ripeness Detection Method Based on Improved YOLOv8
## 2 Materials and Methods
### Network Model Architecture for Strauberry Ripeness Detection
#### 2.3.1 Channel Attention  
To address the issue of feature redundancy during the extraction of ripe strawberry image features, this study introduces a CA mechanism into the model architecture. The attention mechanism enables the neural network to focus more effectively on the color features of ripe strawberries, enhancing the extraction of relevant information while suppressing background noise and other irrelevant content. Specifically, the CA mechanism analyzes channel-wise information within the feature map and dynamically adjusts the corresponding channel weights. This process strengthens the network's response to critical features and improves its overall feature representation capability. In real-world environments, the color of unripe strawberries is often similar to that of surrounding leaves, while under varying lighting conditions, the color of ripe strawberries may closely resemble that of semi-ripe ones. To address these challenges, this study incorporates a CA mechanism, which captures correlations between different spatial regions and channel information in strawberry images, thereby enhancing the model's ability to distinguish strawberries in different ripening stages. Moreover, the CA mechanism effectively suppresses background noise and irrelevant information, further improving detection accuracy. The detailed structure of the CA module is illustrated in Figure 4.  
Figure 3: YOLOv8 network structure diagram. In order to circumvent the compression of all spatial information into the channel dimension, the CA attention mechanism does not utilize global average pooling. In order to effectively capture long-range spatial interactions with precise positional information, a decomposition of the global average pooling operation is performed, as detailed below. In the CA mechanism, the global average pooling operation is decomposed into two separate one-dimensional feature encoding processes along the spatial height and width dimensions. For each channel \(c\), the height-wise pooled feature \(c_{h}^{z}(h)\) is computed by averaging the input feature map \(x_{c}\) over the width dimension \(W\), as formulated by [25]:  
\[c_{h}^{z}(h)=\frac{1}{W}\sum_{0<i<W}x_{c}(h,i) \tag{1}\]  
Figure 4: Detailed design of the CA module. The core concept of the CA mechanism is to decompose the channel attention into two one-dimensional feature encoding processes, which aggregate features along the horizontal and vertical directions, respectively. This design enables the model to capture long-range dependencies along one spatial axis while preserving precise positional information along the other. Specifically, the CA module first applies two one-dimensional global pooling operations--horizontal and vertical--to extract direction-aware feature maps. These feature maps are then passed through a sequence of operations, including convolution, batch normalization, and activation functions, to generate attention weight maps for both directions. The resulting attention maps are multiplied with the original feature maps to produce enhanced feature representations, effectively refining the input features. The CA mechanism offers the advantage of jointly considering both channel-wise and spatial information with minimal computational overhead, making it highly suitable for deployment on mobile and edge devices. Its flexibility and efficiency also make it a powerful component for enhancing the performance of existing neural network architectures. In the context of strawberry ripeness detection, the CA mechanism has demonstrated a significant ability to enhance model performance. Accurate ripeness classification depends on the precise analysis of subtle color transitions and surface texture characteristics of strawberries. By aggregating channel-wise information and incorporating spatially directional feature encoding, the CA mechanism effectively captures key ripeness-related features, thereby improving classification accuracy.