## 2 YOLOv7 Network and Improvement Methods  
### YOLOv7 Model Structure  
YOLOv7, introduced by [PERSON] et al. [13] in 2022, represents an independent evolution of the YOLO architecture, distinct from the YOLOv5 framework developed by Ultralytics. The model introduces an extended Efficient Layer Aggregation Network (ELAN) and adopts a compound scaling strategy based on tensor concatenation to balance model capacity and computational efficiency. Key innovations include multi-head training mechanisms and adaptive label assignment strategies, which enhance training robustness across diverse object scales.Within a certain range, the accuracy and response speed of YOLOv7 surpass most previous single-stage target detection algorithms, reaching a balance between detection speed and accuracy. For this reason, this article chooses to improve the YOLOv7 model.  
The structure diagram of YOLOv7 is shown in Figure 1. The YOLOv7 network is mainly composed of two parts: the backbone and head. The YOLOv7 backbone employsa C7_1-MP-ELAN architecture to efficiently aggregate multi-scale features: the ELAN module parallelizes convolutional branches and concatenates outputs to balance depth and computational efficiency while deepening the network's representational capacity without significantly increasing complexity--its multi-branch feature concatenation provides rich information for subsequent layers to learn complex image patterns; MP modules use max pooling to maintain channel consistency, downsizing feature maps by selecting maximum values in pooling windows, reducing spatial dimensions, retaining prominent features, and enhancing robustness against small input translations/distortions. Additionally, the parallel structure allows independent processing of different feature levels, cutting redundant computations to boost efficiency.  
The head module is mainly composed of SPPCSPC, C7_2, and MP modules. YOLOv7 incorporates the PAFPN structure, which plays a pivotal role in achieving the fusion of high-level and low-level features through information transfer. Unlike the Path Aggregation Network (PANet) used in YOLOv4, PAFPN makes significant improvements in the process of multi-scale feature fusion. In YOLOv4's PANet, the feature fusion mainly follows a bottom-up and then top-down path. The bottom-up path aggregates low-level features with high-level features to enrich the high-level feature representation. Subsequently, the top-down path refines the feature maps by propagating information from high level to low level. However, this approach may lead to a loss of some fine-grained information during the repeated upsampling and downsampling processes. PAFPN in YOLOv7 addresses this issue. It enhances the information flow by introducing a more direct and efficient connection mechanism. In PAFPN, it not only strengthens the bottom-up and top-down feature aggregation but also adds additional cross-scale connections. These cross-scale connections allow low-level fine-grained features to be more effectively integrated into high-level semantic features, and vice versa. This multi-scale information exchange helps the model better capture features at different scales, thereby improving the accuracy of object detection, especially for small objects. At the prediction layer, YOLOv7 employs adaptive anchor box allocation optimized by the improved PAFPN feature fusion framework. This mechanism dynamically adjusts anchor box scaling and aspect ratios based on multi-scale contextual features, enhancing localization accuracy for small lesions and irregularly shaped pests. Combined with non-maximum suppression optimized for overlapping instances, the improved strategy reduces redundant predictions by 15% compared to standard anchor-based methods, as validated in ablation studies [13].