## 2 YOLOv7 Network and Improvement Methods
### SE Block  
The original YOLOv7 network uses direct splicing when merging channels, ignoring the relationship between channels, resulting in a large amount of redundant information  
Figure 1: Original structure of YOLOv7.  
and inaccurate recognition of the contour of the crop pests and diseases with blurred boundaries [14; 15]. This paper models the interdependence between channels, adaptively readjusts the weights of each channel, and selectively strengthens features containing useful information and suppresses useless features through global information. To address channel redundancy, this study introduces the SE module into the SPPCSPC neck. By compressing global spatial information and recalibrating channel weights, the SE module enhances discriminative feature representation, particularly for small lesions with low contrast.  
The Squeeze-and-Excitation module adaptively recalibrates channel-wise feature responses. As shown in the activation heatmap, SE focuses attention on lesion regions by suppressing background noise and enhancing discriminative channels. This improves bounding box localization in YOLOv7, evident by a 2.1% increase in [EMAIL_ADDRESS] compared to the baseline model.  
The channel attention module, originating from the Squeeze-and-Excitation Block introduced in the seminal work \"Squeeze-and-Excitation Networks\" by [PERSON] et al. [14], comprises a squeeze block and an excitation block. Its structure is depicted in Figure 2.  
For the feature extraction process: the input \(X\in R^{H\times W\times C}\) is converted into a feature map \(U\in R^{H\times W\times C}\) via a convolution operation. Let \(U=[u_{1},u_{2},\cdots,u_{c}]\) represent the output feature map, and \(V=[v_{1},v_{2},\cdots,v_{c}]\) denote the learned filter kernel set. The calculation is defined as:  
\[u_{c}=v_{c}*X=\sum_{s=1}^{C}v_{c}^{s}*x^{s} \tag{1}\]  
In Equation (1), the operator \(*\) signifies the convolution operation. \(V_{c}^{s}\) acts as the two-dimensional spatial kernel, meaning a single channel of \(v_{c}\) operates on the corresponding channel of X.  
Next, the squeeze operation is applied to the obtained feature map. Specifically, a global average pooling operation is performed on U, compressing the dimension from \(H\times W\times C\) to \(1\times 1\times C\). This step compresses global spatial information into the channel dimension, where H, W, and C represent the height, width, and channel number, respectively. The formula for this operation is elaborated as follows:  
\[z_{c}=F_{sq}(u_{c})=\frac{1}{H\times W}\sum_{i=1}^{H}\sum_{j=1}^{W}u_{c}(i,j) \tag{2}\]  
Finally, the squeeze result is input into \(F_{ex}\), which consists of a ReLU activation function, two fully connected layers, and a Sigmoid function, to obtain the importance of each channel. Finally, different weights are assigned to each channel through the excitation module \(F_{scale}\) to capture the interdependence between channels. The calculation process is summarized as:  
\[s=F_{ex}(z_{c},W)=\sigma(W_{2}(\text{ReLU}(W_{1}z_{c}))) \tag{3}\]  
\[X_{c}^{*}=F_{scale}(u_{c},s_{c})=s_{c}u_{c} \tag{4}\]  
Figure 2: SE module schematic.  
\(F_{scale}(u_{c},s_{c})\) is the channel-wise multiplication between the scalar \(S_{c}\) and the feature map \(u_{c}\in R^{H\times W}\).  
The modified YOLOv7 structure is shown in Figure 3.  
To address the challenge of class imbalance in pest detection, the YOLOv7 backbone was modified by incorporating a SE module into the neck region. This addition introduces channel-wise attention mechanisms that adaptively recalibrate feature responses based on inter-channel relationships. The SE module improves the model's ability to focus on minority pest classes, such as cucumber downy mildew, by suppressing background-dominated channels. Ablation studies confirmed that this modification improved [EMAIL_ADDRESS] by 1.8% compared to the baseline YOLOv7 architecture.