Abstract:
To address the problem of low accuracy in existing object detection models under complex conditions, particularly the challenges of pear blossoms being easily obscured, complex backgrounds, and varying lighting conditions and target distances in natural environments, this paper proposes an improved pear blossom recognition algorithm based on the YOLOv7 model. Firstly, a P2 small-object layer was added to increase the capability of feature extraction and multi-scale fusion of the model, so that the improved model can capture the obscured targets better. Secondly, a CBAM (convolutional block attention module) attention mechanism was introduced at the end of the output detection layer. CBAM can improve the context understanding ability of the model and the performance of YOLOv7 in various scenarios (different lighting conditions, complex backgrounds, etc.). Lastly, the CIoU (complete intersection over union) loss function was optimized to the NWD (normalized weighted distance) loss function. NWD can accurate bounding box regression which performed for targets with different shapes. improve the detection accuracy of the model for complex background targets and distant targets.Additionally, a dataset was created by photographing pear blossoms from different angles, backgrounds, lighting conditions, and distances during the peak blooming period. A total of 3,240 photos of Ya Pear blossoms, 1,582 photos of Golden Pear blossoms, and 2,184 photos of New Pear No. 7 blossoms were collected. Due to the large number of Ya Pear samples and their rich background elements, Ya Pear images were used to create a complex environment dataset for pear blossoms. Images of the three pear varieties were used to create a dataset for different varieties. The improved YOLOv7 model was trained and tested using the complex environment dataset. Randomly selected images of Ya Pear blossoms under different lighting conditions, occlusions, backgrounds, and distances were used to compare the original YOLOv7 model with the improved YOLOv7 model. The results showed that the improved YOLOv7 model had better detection performance and higher confidence levels. Ablation experiments were conducted to validate the effectiveness of the three improvements, and the results indicated that these improvements significantly enhanced the original YOLOv7 model, increasing the detection accuracy of pear blossom targets. Analysis of the detection heatmaps of the improved and original models showed that the heatmap values of the improved YOLOv7 model were closer to the actual pear blossom regions, with a focus on extracting pear blossom edge features. The improved YOLOv7 model was trained and tested using different pear blossom datasets, demonstrating good adaptability and robustness. Comparative experiments with mainstream algorithms were conducted to evaluate the performance of the improved YOLOv7 model. The results showed that compared to the original model, the precision, recall, mAP, and F1-score of the improved YOLOv7 model increased by 2.1, 1.2, 1.9 and 0.6 percentage points respectively, reaching 99.4%, 99.6%, 96.4% and 89.8%. Compared to Faster R-CNN,SSD, YOLOv3, YOLOv4, YOLOv5, YOLOv8,YOLOv9 and YOLOv10 models, the improved YOLOv7 model also showed advantages in all evaluation metrics. Model applicability performance evaluation experiments were conducted, and the results showed that the mAP of the improved YOLOv7 was 3.9 and 3.7 percentage points higher than that of YOLOv7 when training close and distant datasets, respectively; When training the forward and backward light datasets, the mAP of improved YOLOv7 was 4.4 and 1.6 percentage points higher than YOLOv7, respectively; Improved the mAP of YOLOv7 by 1.8, 1.4, and 1.5 percentage points compared to the YOLOv7 model in the ground, sky, and pear blossom backgrounds. The study indicates that this algorithm achieves high detection accuracy for pear blossom recognition in complex environments with varying backgrounds, distances, occlusions, and lighting conditions. The research results can provide support for accurate identification of pear blossoms in the natural environment of pear orchards.