🍅 Tomato Ripeness Detection & Counting — complete pipeline (YOLO26s)
Two small models that find every tomato, grade its ripeness and count it once on a conveyor belt.
![]()
| File | Model | Task |
|---|---|---|
weights/detector_yolo26s_best.pt | YOLO26s, 640 px | detect every tomato (1 class) |
weights/ripeness_yolo26s-cls_best.pt | YOLO26s-cls, 160 px crops | raw (unripe) · half_ripe · ripe · rotten |
weights/rotten_check.npz | logistic regression on the classifier embedding | second opinion on every "rotten" call |
weights/thresholds.json | detection threshold from validation |
🧩 Model family
This repo is the complete pipeline. Each part is also published on its own:
| Repo | What it does | |
|---|---|---|
| 🍅 Complete | this repo | detection + ripeness + rotten check, ready for the tracking / counting app |
| 🔍 Component 1 | tomato-detector-yolo26s | find every tomato (1 class) |
| 🎨 Component 2 | tomato-ripeness-classifier-yolo26s | unripe / half-ripe / ripe / rotten + rotten check |
| 🗂️ Data | tomato-ripeness-detection | 8.5k images, 74k labelled tomatoes |
Code, tracking and the full pipeline: github.com/ParsaVictor/tomato-ripeness-detection
Results (images never seen in training)
| Test set | Recall | Precision | Count accuracy |
|---|---|---|---|
| Tomato Defects test | 99.0% | 93.3% | 93.8% |
| Conveyor holdout | 84.9% | 90.0% | 89.7% |
| sxsc7 holdout | 93.3% | 94.8% | 96.3% |
- Detector (Ultralytics val, Tomato Defects test): mAP50 0.988 · mAP50-95 0.919
- Ripeness: 4-class 80.8% · ripe / unripe / rotten 88.7% · sound vs rotten 98.6%
- Video counting with ByteTrack: 95–99% at normal belt speed
Quick use
from huggingface_hub import snapshot_download
from ultralytics import YOLO
path = snapshot_download("ParsaVictor/tomato-ripeness-yolo26")
det = YOLO(f"{path}/weights/detector_yolo26s_best.pt")
cls = YOLO(f"{path}/weights/ripeness_yolo26s-cls_best.pt")
r = det.predict("tomatoes.jpg", conf=0.25)[0]
for x1, y1, x2, y2 in r.boxes.xyxy.int().tolist():
crop = r.orig_img[y1:y2, x1:x2]
p = cls.predict(crop, imgsz=160, verbose=False)[0].probs
print(cls.names[p.top1], round(float(p.top1conf), 2))
For the full pipeline (10% crop padding, duplicate suppression, rotten check, tracking, dashboard) use tomato_app/run.py from the GitHub repo and put these files in its weights/ folder.
Training
- Data: ParsaVictor/tomato-ripeness-detection — 8,497 images, 74,486 boxes, from 6 CC BY 4.0 sources
- Detector: 5,783 train / 1,073 val images, 100 epochs on a Colab T4
- Classifier: 50,776 train crops, 60 epochs
Limitations
- Small, far or motion-blurred tomatoes on a conveyor are missed more often (recall ~85%).
- Ripeness labels come mostly from one dataset; half-ripe borders are subjective (most errors are between neighbouring stages).
License
AGPL-3.0 (trained with Ultralytics YOLO). For closed-source commercial use, an Ultralytics Enterprise license is required.