Abstract: With the rapid development of smart agriculture, intelligent detection of crop maturity has become an important research direction in precision agriculture. This paper designs and implements an intelligent tomato ripeness detection system based on the YOLOv8 deep learning model. The system collects tomato images and uses the YOLOv8 object detection algorithm to classify and identify tomato ripeness. Tomato ripeness is divided into four levels: unripe, turning, semi-ripe, and ripe.
Project Overview
Project Introduction
The system mainly consists of four core modules: image detection, video detection, real-time detection, and batch detection. It supports single-image upload, frame-by-frame video analysis, real-time camera monitoring, and large-scale automated processing. The graphical user interface is developed with PyQt5 and integrates multi-dimensional visualization tools, including a ripeness proportion pie chart, statistical data cards, and detailed detection result tables. These functions provide a comprehensive display of detection results and offer an integrated solution for intelligent tomato ripeness recognition.
Experimental results show that the YOLOv8-based tomato ripeness detection model achieves excellent detection performance on the self-built dataset. On the validation set, the precision reaches 81.05%, the recall reaches 70.65%, the mAP50 reaches 76.84%, and the mAP50-95 reaches 61.15%. With GPU acceleration, the detection speed reaches over 20 FPS, meeting the requirements of real-time detection. The system can provide technical support for agricultural automation equipment such as tomato harvesting robots and intelligent sorting systems, demonstrating strong practical value and promising application prospects.
System Architecture
The system uses PyQt5 to build the user interface and integrates the YOLOv8 deep learning model as the detection core. Through a multi-threaded asynchronous processing mechanism, it implements four detection modes: image detection, video detection, real-time detection, and batch detection. In addition, the system provides visual analysis tools to display detection results clearly and intuitively.

Figure 1 System Architecture Diagram
Technical Innovations
Innovation 1: Multimodal Fusion Detection Architecture
- Limitations of traditional methods: Traditional methods mostly focus on a single detection mode, which limits their application scenarios.
- Innovation of this system: This system builds a multi-mode detection framework to realize intelligent recognition and practical application of tomato ripeness detection.
Innovation 2: Four-level Fine-grained Ripeness Classification System
- Limitations of traditional methods: Traditional methods usually adopt binary classification or three-class classification, resulting in relatively coarse classification granularity.
- Innovation of this system: This system establishes a four-level ripeness classification system to achieve fine-grained recognition of the tomato ripening process from green to red.
Innovation 3: Multidimensional Visual Intelligent Analysis System
- Limitations of traditional methods: Existing systems lack statistical analysis and visual decision-support capabilities.
- Innovation of this system: This system constructs a multi-level visual analysis framework to intuitively display and analyze detection results.
Dataset and Training
Dataset Construction
This study uses a tomato ripeness detection dataset from the Roboflow Universe platform under the CC BY 4.0 license. The dataset contains 1,420 high-quality images and 11,158 annotated bounding boxes. It is divided into a training set, validation set, and test set according to a 7:2:1 ratio, including 993 training images, 284 validation images, and 143 test images.
The dataset adopts the standard YOLO annotation format and establishes a four-level fine-grained classification system: unripe, turning, semi-ripe, and ripe. This classification system covers the complete ripening process of tomatoes from green to red. Each image contains an average of 7.9 objects, realistically reflecting dense multi-object scenarios in agricultural production.
In terms of class distribution, the semi-ripe category accounts for the highest proportion at 49.6%, followed by the ripe category at 25.5%. The unripe category accounts for 16.5%, while the turning category accounts for 8.5%. This class distribution is consistent with the natural growth pattern of tomatoes and provides a solid foundation for training a high-precision ripeness detection model.

Figure 2 dataset distribution scaled
Training Results
In this study, the YOLOv8 model was trained on the tomato ripeness detection dataset for 150 epochs and achieved excellent detection performance on the validation set. During the training process, the bounding box loss (box_loss) gradually decreased from the initial value of 1.09 to 0.57, while the classification loss (cls_loss) decreased from 2.73 to 0.34, indicating that the model converged well.
The final model achieved a precision of 81.05% and a recall of 70.65% on the validation set. The mAP50 reached 76.84%, and the mAP50-95 reached 61.15%, demonstrating the model’s ability to accurately recognize the four ripeness categories.
The training process generated complete visualization results, including the P-R curve, F1 curve, and confusion matrix. The total training time was approximately 2,794 seconds, or about 46 minutes. The best weight file was saved in the weights directory and can be directly used for practical detection applications.
The model performs stably in dense multi-object scenarios and can effectively distinguish four categories: unripe, turning, semi-ripe, and ripe. This provides reliable technical support for intelligent tomato harvesting and grading.

Figure 3 results

Figure 4 BoxPR_curve

Figure 5 confusion_matrix-scaled
Quick Start
Run python mainwindow.py to start the system. After the system starts, log in with the default username and password (admin/admin123). Then click Model Loading and select the trained weight file weights/best.pt. After the model is loaded, the system can perform intelligent tomato ripeness recognition through four modes: Image Detection, Video Detection, Real-time Detection, and Batch Detection.
Environment Requirements
This system requires Python 3.8+. The core dependencies include PyTorch 2.0+ with CUDA 11.8+ support for GPU acceleration, ultralytics for YOLOv8, PyQt5 for the graphical user interface, OpenCV for image processing, Matplotlib for data visualization, and Pillow for image operations. It is recommended to use Anaconda to create a virtual environment and install all dependencies with the following command:pip install -r requirements.txt
Running Demo

Figure 6 Login-Page

Figure 7 Main-Window

Figure 8 Image-Detection-Result

Figure 9 Image-Detection-Result

Figure 10 Image-Detection-Result

Figure 11 Image-Detection-Result

Figure 12 Real-time-Object-Detection

Figure 13 Batch-Detection
Project Resources
Supporting Documents
Click to view:Intelligent Tomato Ripeness Detection System Based on YOLOv8 Deep Learning
Note: Additional purchase is required.
Supporting Files
The supporting files include the complete project source code, demonstration video, running screenshots, and other related resources. The project is ready to use out of the box.
Project Information
Author Information
Author: Bob (Zhang Jialiang)
Project ID: AI-1-EN
Originality Statement: This project is an original work.
Contact Information
Email: wesharecode2023@gmail.com
GitHub:https://github.com/7zcode
YouTube:https://www.youtube.com/@7zcode
Open Source License
This project is licensed under the AGPL-3.0 License. You may use, modify, and distribute the code, but derivative works must also remain open source under the same license. If the project is used to provide network services, the complete source code must be made available to users.
This project is for learning and research purposes only. Users are responsible for complying with local laws and regulations. If this project is helpful, citation and attribution are appreciated.


评论(0)