In natural environments, green walnuts often experience occlusion by branches and leaves, fruit overlap, and varying lighting conditions. To
In natural environments, green walnuts often experience occlusion by branches and leaves, fruit overlap, and varying lighting conditions. To address the issues of low detection accuracy, missed detections, and false positives in the YOLO model, this study proposes an improved YOLOv8n-based detection and counting model for green walnuts, named YOLOv8n-RBP. First, a receptive field-concentrated attention module (RFCBAM) is integrated into the backbone network to enhance feature extraction capabilities. Second, a BiFPN-GLSA module is introduced to replace the Path Aggregation Network (PANet) in the neck, improving the fusion of feature layers from the backbone and Neck networks and enhancing the model’s ability to capture both global and local spatial features. Lastly, to address the weak generalization and slow convergence issues of the CIoU loss function in detection tasks, the PIoUv2 loss function is employed to accelerate bounding box regression and improve detection performance. Experimental results demonstrate that the YOLOv8n-RBP model excels across multiple evaluation metrics. Specifically, the model achieves a mean average precision (mAP@0.5) of 82.2% and a recall rate of 72.4%, with a model size of only 4.65 MB, 2.2 million parameters, and 8.3 GFLOPs. Compared to the original YOLOv8n model, the recall rate and mAP@0.5 improve by 2.7% and 2.5%, respectively, while the number of parameters, FLOPs, and model size decrease by 26.7%, 0.6%, and 22.0%, respectively. Further deployment on the NVIDIA Jetson Xavier NX demonstrates the model’s robust performance under natural conditions, indicating its suitability for orchard operations.