DAAL-YOLOv12n: A Method for Detecting Common Forest Pests Incorporating Dynamic Attention and Adaptive Lightweight Modules
Songnan Chen, Xuelin Chen, Yun PanVariable illumination, severe occlusion, and the small scale of pest instances in complex forest environments significantly compromise the accuracy of automated forest pest detection. Existing deep learning-based detection models often face challenges in achieving an optimal trade-off among detection accuracy, model lightweightness, and training stability. To achieve efficient and intelligent monitoring of forest pests, we propose a novel detection framework named DAAL-YOLOv12n by improving the lightweight YOLOv12n baseline with two specifically designed modules for complex forest scenarios. To overcome the limited feature adaptability caused by fixed convolutional branches and conventional residual connections in the original A2C2f block, a DynamicA2C2f dynamic attention module is introduced. This module employs dynamic gating weights and adaptive residual adaptation modulation to achieve directional feature enhancement and improved cross-channel compatibility. Furthermore, to reduce the computational redundancy of the conventional C3/C2f block and alleviate abnormal optimization errors in the exponential moving average (EMA) caused by persistently stored dynamic tensors, an AdaptiveC3K2 lightweight adaptation module is developed. Through shared convolution representations, temporary dynamic weight generation, and pre-residual adaptation strategies, the proposed module achieves model compression, flexible channel adaptation, and EMA-compatible optimization. Extensive experiments are conducted on a self-collected forest pest dataset comprising 16 common pest categories. Experimental results demonstrate that, compared with advanced detectors such as YOLOv12n, DAAL-YOLOv12n improves precision and recall by 10.5% and 11.1%, respectively, with only a marginal increase in model parameters. Furthermore, the proposed approach increases mAP@0.5 and mAP@0.5:0.95 by 10.2% and 18.0%, respectively, attaining an mAP@0.5 of 93.0% alongside a real-time inference throughput of 93 FPS. These results indicate that the proposed method offers a viable solution for deploying accurate and lightweight forest pest detection systems on edge devices, offering technical support for intelligent pest surveillance in the wild.