TMAF-YOLO: A Lightweight Model for In Situ Detection of Tomato Maturity and Defective Fruits in Greenhouses
Abstract
1. Introduction
- (1)
- A lightweight tomato maturity detection model was constructed for complex greenhouse scenarios. Inspired by the low-cost feature generation strategy in GhostNet, an LGhostConv module was designed and embedded in key positions of the Backbone and Neck [20]. This design reduces the number of parameters and computational cost while maintaining detection performance.
- (2)
- A tomato maturity-aware aggregation fusion module, termed TMAF, was proposed. This module was designed to address continuous color transitions between adjacent maturity stages, weak local texture differences, and insufficient feature representation caused by occlusion and overlap. By integrating local texture enhancement and channel-spatial recalibration, TMAF strengthens maturity-related feature representation.
- (3)
- MA-CB Focal Loss was developed to improve learning under class imbalance and hard-sample conditions. By combining class-balanced weights with the Focal Loss modulation term, the loss enhances learning for minority and difficult samples, including defective fruits and adjacent maturity stages.
2. Materials and Methods
2.1. Overall Method Design
2.2. Dataset Construction and Annotation
2.3. Construction of the TMAF-YOLO Model
2.3.1. TMAF-YOLO: An Improved YOLOv8n Model
2.3.2. Lightweight Feature Extraction Module: LGhostConv
2.3.3. Tomato Maturity-Aware Aggregation Fusion Module: TMAF
2.3.4. Loss Function Optimization: MA-CB Focal Loss
2.4. Experimental Settings and Evaluation Metrics
2.4.1. Hardware and Software Environment
2.4.2. Training Hyperparameters
2.4.3. Evaluation Metrics
3. Results and Discussion
3.1. Training Process and Final Detection Result Analysis
3.1.1. Training Loss Curve Analysis
3.1.2. Validation mAP50 Curve Analysis
3.1.3. Precision–Recall Curve Analysis
3.1.4. Confusion Matrix Analysis

3.2. Model Performance and Visualization Analysis
3.3. Ablation Study





3.4. Discussion
3.4.1. Methodological Significance and Practical Implications
3.4.2. Limitations and Potential Improvements
4. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
References
- Wang, Z.; Ling, Y.; Wang, X.; Meng, D.; Nie, L.; An, G.; Wang, X. An improved Faster R-CNN model for multi-object tomato maturity detection in complex scenarios. Ecol. Inform. 2022, 72, 101886. [Google Scholar] [CrossRef]
- Zeng, T.; Li, S.; Song, Q.; Zhong, F.; Wei, X. Lightweight tomato real-time detection method based on improved YOLO and mobile deployment. Comput. Electron. Agric. 2023, 205, 107625. [Google Scholar] [CrossRef]
- Rong, J.; Zhou, H.; Zhang, F.; Yuan, T.; Wang, P. Tomato cluster detection and counting using improved YOLOv5 based on RGB-D fusion. Comput. Electron. Agric. 2023, 207, 107741. [Google Scholar] [CrossRef]
- Mu, Y.; Chen, T.-S.; Ninomiya, S.; Guo, W. Intact detection of highly occluded immature tomatoes on plants using deep learning techniques. Sensors 2020, 20, 2984. [Google Scholar] [CrossRef] [PubMed]
- Rahim, U.F.; Mineno, H. Tomato flower detection and counting in greenhouses using faster region-based convolutional neural network. J. Image Graph. 2020, 8, 107–113. [Google Scholar] [CrossRef]
- Carion, N.; Massa, F.; Synnaeve, G.; Usunier, N.; Kirillov, A.; Zagoruyko, S. End-to-end object detection with transformers. In Computer Vision—ECCV 2020; Vedaldi, A., Bischof, H., Brox, T., Frahm, J.-M., Eds.; Springer International Publishing: Cham, Switzerland, 2020; pp. 213–229. [Google Scholar] [CrossRef]
- Zhang, H.; Li, F.; Liu, S.; Zhang, L.; Su, H.; Zhu, J.; Ni, L.M.; Shum, H.-Y. DINO: DETR with improved denoising anchor boxes for end-to-end object detection. In Proceedings of the International Conference on Learning Representations, Kigali, Rwanda, 1–5 May 2023. [Google Scholar]
- Zhao, Y.; Lv, W.; Xu, S.; Wei, J.; Wang, G.; Dang, Q.; Liu, Y.; Chen, J. DETRs beat YOLOs on real-time object detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition; IEEE: Piscataway, NJ, USA, 2024; pp. 16965–16974. [Google Scholar] [CrossRef]
- Wang, S.; Jiang, H.; Yang, J.; Ma, X.; Chen, J.; Li, Z.; Tang, X. Lightweight tomato ripeness detection algorithm based on the improved RT-DETR. Front. Plant Sci. 2024, 15, 1415297. [Google Scholar] [CrossRef] [PubMed]
- Wu, M.; Qiu, Y.; Wang, W.; Su, X.; Cao, Y.; Bai, Y. Improved RT-DETR and its application to fruit ripeness detection. Front. Plant Sci. 2025, 16, 1423682. [Google Scholar] [CrossRef] [PubMed]
- Chen, W.; Liu, M.; Zhao, C.; Li, X.; Wang, Y. MTD-YOLO: Multi-task deep convolutional neural network for cherry tomato fruit bunch maturity detection. Comput. Electron. Agric. 2024, 216, 108533. [Google Scholar] [CrossRef]
- Li, Y.; Li, J.; Luo, L.; Wang, L.; Zhi, Q. Tomato ripeness and stem recognition based on improved YOLOX. Sci. Rep. 2025, 15, 1924. [Google Scholar] [CrossRef] [PubMed]
- Yang, S.; Wang, W.; Gao, S.; Deng, Z. Strawberry ripeness detection based on YOLOv8 algorithm fused with LW-Swin Transformer. Comput. Electron. Agric. 2023, 215, 108360. [Google Scholar] [CrossRef]
- Appe, S.N.; Arulselvi, G.; Balaji, G.N. CAM-YOLO: Tomato detection and classification based on improved YOLOv5 using combining attention mechanism. PeerJ Comput. Sci. 2023, 9, e1463. [Google Scholar] [CrossRef]
- Sun, H.; Zheng, Q.; Yao, W.; Wang, J.; Liu, C.; Yu, H.; Chen, C. An improved YOLOv8 model for detecting four stages of tomato ripening and its application deployment in a greenhouse environment. Agriculture 2025, 15, 936. [Google Scholar] [CrossRef]
- Dong, Y.; Qiao, J.; Liu, N.; He, Y.; Li, S.; Hu, X.; Yu, C.; Zhang, C. GPC-YOLO: An improved lightweight YOLOv8n network for the detection of tomato maturity in unstructured natural environments. Sensors 2025, 25, 1502. [Google Scholar] [CrossRef] [PubMed]
- Touko Mbouembe, P.L.; Liu, G.; Park, S.; Kim, J.H. Accurate and fast detection of tomatoes based on improved YOLOv5s in natural environments. Front. Plant Sci. 2024, 14, 1292766. [Google Scholar] [CrossRef] [PubMed]
- Lin, T.-Y.; Goyal, P.; Girshick, R.; He, K.; Dollár, P. Focal loss for dense object detection. IEEE Trans. Pattern Anal. Mach. Intell. 2020, 42, 318–327. [Google Scholar] [CrossRef] [PubMed]
- Cui, Y.; Jia, M.; Lin, T.-Y.; Song, Y.; Belongie, S. Class-balanced loss based on effective number of samples. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition; IEEE: Piscataway, NJ, USA, 2019; pp. 9268–9277. [Google Scholar] [CrossRef]
- Han, K.; Wang, Y.; Tian, Q.; Guo, J.; Xu, C.; Xu, C. GhostNet: More features from cheap operations. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition; IEEE: Piscataway, NJ, USA, 2020; pp. 1580–1589. [Google Scholar] [CrossRef]






| Dataset Subset | Images | Immature | Semi-Mature | Mature | Defective | Total Instances |
|---|---|---|---|---|---|---|
| training | 503 | 916 | 628 | 243 | 206 | 1993 |
| validation | 63 | 136 | 83 | 29 | 19 | 267 |
| test | 63 | 118 | 77 | 32 | 18 | 245 |
| total | 629 | 1170 | 788 | 304 | 243 | 2505 |
| Predicted/True | Immature | Semi-Mature | Mature | Defective | Background | |
|---|---|---|---|---|---|---|
| (a) YOLOv8n | immature | 0.87 | 0.03 | 0.00 | 0.06 | 0.43 |
| semi-mature | 0.06 | 0.86 | 0.14 | 0.00 | 0.23 | |
| mature | 0.00 | 0.05 | 0.79 | 0.02 | 0.12 | |
| defective | 0.00 | 0.01 | 0.02 | 0.89 | 0.20 | |
| background | 0.07 | 0.06 | 0.05 | 0.03 | 0.00 | |
| (b) TMAF-YOLO | immature | 0.91 | 0.03 | 0.00 | 0.03 | 0.47 |
| semi-mature | 0.02 | 0.91 | 0.10 | 0.00 | 0.20 | |
| mature | 0.00 | 0.04 | 0.86 | 0.04 | 0.08 | |
| defective | 0.00 | 0.00 | 0.02 | 0.90 | 0.25 | |
| background | 0.07 | 0.02 | 0.02 | 0.03 | 0.00 |
| Model | Precision | Recall | mAP50 | mAP50-95 | Params (M) | FLOPs (G) | FPS | Inference Time (ms) |
|---|---|---|---|---|---|---|---|---|
| YOLOv8n | 0.858 | 0.836 | 0.916 | 0.744 | 3.012 | 8.2 | 154.012 | 6.493 |
| YOLOv11n | 0.818 | 0.848 | 0.909 | 0.750 | 2.591 | 6.5 | 199.481 | 5.013 |
| YOLOv12n | 0.838 | 0.824 | 0.897 | 0.728 | 2.569 | 6.5 | 140.763 | 7.107 |
| DETR | 0.787 | 0.875 | 0.872 | 0.607 | 41.556 | 77.1 | 23.937 | 41.777 |
| DINO | 0.859 | 0.834 | 0.899 | 0.704 | 47.393 | 218.6 | 30.164 | 33.152 |
| Faster R-CNN | 0.846 | 0.871 | 0.882 | 0.661 | 41.364 | 61.7 | 24.696 | 40.493 |
| Grid R-CNN | 0.859 | 0.873 | 0.870 | 0.673 | 64.700 | 154.0 | 19.388 | 51.577 |
| Libra R-CNN | 0.867 | 0.828 | 0.872 | 0.654 | 41.270 | 62.4 | 24.960 | 40.065 |
| Cascade R-CNN | 0.856 | 0.861 | 0.885 | 0.693 | 69.161 | 89.5 | 18.875 | 52.980 |
| Dynamic R-CNN | 0.822 | 0.885 | 0.862 | 0.641 | 41.364 | 61.7 | 24.539 | 40.751 |
| TMAF-YOLO | 0.889 | 0.873 | 0.954 | 0.776 | 2.647 | 7.3 | 209.030 | 4.784 |
| Model | Precision | Recall | mAP50 | mAP50-95 | Params (M) | FLOPs (G) | FPS | Inference Time (ms) |
|---|---|---|---|---|---|---|---|---|
| YOLOv8n | 0.858 | 0.836 | 0.916 | 0.744 | 3.012 | 8.2 | 154.012 | 6.493 |
| YOLOv8n + LGhostConv | 0.868 | 0.820 | 0.920 | 0.749 | 2.729 | 7.7 | 226.283 | 4.419 |
| YOLOv8n + TMAF | 0.875 | 0.855 | 0.941 | 0.762 | 2.930 | 7.8 | 194.175 | 5.150 |
| YOLOv8n + LGhostConv + TMAF | 0.880 | 0.861 | 0.949 | 0.768 | 2.647 | 7.3 | 207.340 | 4.823 |
| TMAF-YOLO | 0.889 | 0.873 | 0.954 | 0.776 | 2.647 | 7.3 | 209.030 | 4.784 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Huang, C.; He, L.; Huang, W.; Zhang, X. TMAF-YOLO: A Lightweight Model for In Situ Detection of Tomato Maturity and Defective Fruits in Greenhouses. Sensors 2026, 26, 4950. https://doi.org/10.3390/s26154950
Huang C, He L, Huang W, Zhang X. TMAF-YOLO: A Lightweight Model for In Situ Detection of Tomato Maturity and Defective Fruits in Greenhouses. Sensors. 2026; 26(15):4950. https://doi.org/10.3390/s26154950
Chicago/Turabian StyleHuang, Chenxiao, Linran He, Wentao Huang, and Xiaoshuan Zhang. 2026. "TMAF-YOLO: A Lightweight Model for In Situ Detection of Tomato Maturity and Defective Fruits in Greenhouses" Sensors 26, no. 15: 4950. https://doi.org/10.3390/s26154950
APA StyleHuang, C., He, L., Huang, W., & Zhang, X. (2026). TMAF-YOLO: A Lightweight Model for In Situ Detection of Tomato Maturity and Defective Fruits in Greenhouses. Sensors, 26(15), 4950. https://doi.org/10.3390/s26154950

