Abstract:
Accurate detection of mulberry ripeness is often required for mechanical harvesting and grading. However, field images are confined to dense fruit clusters, mutual occlusion, large variations in illumination, and subtle appearance differences between adjacent ripeness stages. Feature representation can be weakened causing missed detections or category confusion, especially for small and medium-sized fruits. In this study, an improved real-time detection transformer (RT-DETR) model was developed to detect four-stage mulberry ripeness in complex field environments. A dataset of 1,585 valid images was collected at different distances under various lighting and occlusions. The mulberries were annotated as unripe, turning, ripe, or overripe. The image datasets were divided into 1,268 training images and 317 test images. After data augmentation, the training set contained 4,068 images and 20,017 bounding-box annotations. Four complementary improvements were introduced into the baseline network. (1) A spatial edge-enhanced feedforward network (SEEFN) was designed to combine spatial, local, and edge information, thereby strengthening the representation of fruit boundaries and fine textures. (2) Soft nearest neighbor interpolation (SNI) was applied during upsampling to reduce feature distortion for the high consistency of information transferred across scales. (3) Grouped shuffle convolution enhanced (GSConvE) was introduced during downsampling to promote feature interaction with the lightweight structure. (4) A detail-preserving contextual fusion (DPCF) module was used to combine fine local features with high-level contextual information. These modules formed a multiscale feature enhancement and fusion framework intended to improve the detection of small, overlapping, and partially occluded mulberries. The improved model was evaluated to compare with representative object detectors using ablation experiments. Field tests were conducted under lighting interference and dense occlusion. Precision-recall curves, detection visualizations, and attention heatmaps were collected after the test. On the complete test set, RT-DETR-MR achieved an average precision at an intersection-over-union threshold of 0.50 (AP50) of 89.4% and an average precision over intersection-over-union thresholds from 0.50 to 0.95 (AP50-95) of 65.9%, which outperformed the baseline RT-DETR by 2.7 and 1.9 percentage points, respectively. The average precisions reached 33.8% and 61.4% for small and medium-sized objects, indicating improvements of 3.4 and 2.5 percentage points over the baseline. Ablation results confirmed that the best overall performance was achieved using the four improvements in boundary enhancement, multiscale information transfer, and feature fusion. Compared with YOLOv11m, AP50-95 and the average precision of RT-DETR-MR improved by 2.0 and 0.9 percentage points, respectively, for small objects. The improved model contained 21.2 million parameters and 58.8 billion floating-point operations. An inference speed of 127.4 frames per second was achieved with high accuracy without a substantial increase in computational cost. Under lighting interference, RT-DETR-MR achieved AP50 and AP50-95 values of 90.6% and 68.3%, respectively. Under dense occlusion, the corresponding values were 85.9% and 64.2%, respectively. In both scenarios, the improved model outperformed the baseline RT-DETR and YOLOv11m. The detection and attention heatmaps showed that RT-DETR-MR focused more consistently on mulberry regions, thus suppressing interference from leaves, branches, highlights, and cluttered backgrounds. Missed detections were reduced for the densely distributed small fruits. It also alleviated confusion between ripe and overripe mulberries with similar colors. The feature enhancement and fusion strategy improved the accuracy and stability of four-stage mulberry ripeness detection with real-time performance. RT-DETR-MR therefore provided a feasible technical approach for mulberry growth monitoring, mechanical harvesting, and grading in complex field environments, particularly for subsequent deployment on agricultural edge devices.