# YOLO-PGC: A Tomato Maturity Detection Algorithm Based on Improved YOLOv11
## 3 Methods
### Global Horizontal--Vertical Context Module  
Occlusion poses a significant challenge in tomato ripeness detection, especially when fruits are hidden by foliage, soil, or adjacent objects. Traditional CNNs struggle to accurately capture target features in such situations. To overcome this limitation, we introduce the GHVC module. This module features an innovative Self-Calibrated Attention (SCA) mechanism that helps the model focus more on salient regions of features and effectively suppress background interference. The architectural structure of the GHVC module is shown in Figure 4. Based on the Cross-Stage Partial (CSP) framework, the GHVC architecture adopts a multi-branch parallel computing strategy to extract features efficiently. The core SCM (self-calibrated attention mechanism) module combines a rectangular SCA mechanism with depthwise separable convolutions and global adaptive pooling operations. This combination shows excellent performance in multiscale feature extraction. This module also enhances the dynamic adjustment of local features through adaptive convolution operations, effectively overcoming the performance limitations of traditional convolutions in complex environmental scenarios.  
The SCM module implements a sequential processing pipeline, initiating with depthwise convolution for local information extraction. As depicted in Figure 4, this process is mathematically formulated as follows:  
\[X_{\text{local}}=X*K_{\text{dw}} \tag{11}\]  
where \(X\in\mathbb{R}^{C\times H\times W}\) represents the input feature map with channel dimension \(C\), height \(H\), and width \(W\), while \(K_{\text{dw}}\) denotes the depthwise convolution kernel, which operates independently on each channel to capture local spatial dependencies. The resulting feature map \(X_{\text{local}}\) preserves the original channel dimension while emphasizing local feature interactions.  
Subsequently, an adaptive pooling operation is applied to perform spatial feature fusion, enabling the extraction of global contextual information:  
\[X_{\text{global}}=\text{Adaptive Pooling}(X_{\text{local}}) \tag{12}\]  
where \(X_{\text{global}}\in\mathbb{R}^{C\times 1\times 1}\) represents the globally pooled feature representation used for aggregating spatial information across the entire feature map to enhance long-range dependencies.  
Finally, the module employs convolution activation operations to refine the feature representations through global feature calibration and target region response enhancement, ensuring robust feature extraction even in occluded environments. This design maintains effective feature capture by dynamically adjusting to variations in object scale and occlusion patterns:  
\[X_{\text{calibrated}}=\sigma(X_{\text{global}}*K_{\text{conv}}) \tag{13}\]  
where \(X_{\text{calibrated}}\) denotes calibrated attention features, \(\sigma\) represents the sigmoid activation function, and \(K_{\text{conv}}\) indicates the convolution kernel.  
The self-adaptive attention mechanism of the GHVC module substantially improves feature extraction capabilities in occluded and complex background scenarios. By implementing multiscale feature modeling, this module achieves robust performance in classifying tomato ripeness across various stages while maintaining detection stability un der partial occlusion. Lightweight 1 \(\times\) 1 convolution operations are integrated to optimize computational efficiency without compromising performance integrity.  
To further optimize computational resources, GHVC utilizes an innovative bottleneck structure for dynamic channel compression and expansion. This design reduces feature dimensionality through 1 \(\times\) 1 convolutions, then enhances features via the SCM module before applying subsequent convolutions, enabling efficient multiscale feature fusion. Empirical evaluation confirms superior performance in tomato ripeness detection tasks, demonstrating especially strong robustness in challenging environmental conditions.