Single-class YOLO dataset and training pipeline for live leaf detection.
Open the training notebook in Colab:
The Colab notebook downloads the public Kaggle dataset automatically with KaggleHub when no cached dataset exists, so you should not need to upload files manually. It saves everything under:
MyDrive/leaf-object-detection/
It caches archive.zip, uploads the prepared YOLO dataset as
datasets/leaf_yolo_dataset.tar.gz, syncs run folders after each model, and
writes final ZIP/summary artifacts to artifacts/.
Fastest repeat setup: the notebook creates and reuses one compressed prepared dataset file:
MyDrive/leaf-object-detection/datasets/leaf_yolo_dataset.tar.gz
If you ever want to create it locally instead, use:
cd D:\Ken\leaf_detector
tar -czf leaf_yolo_dataset.tar.gz datasets\leaf_yoloThe notebook can detect the current loose Drive upload layout:
MyDrive/leaf-object-detection/datasets/archive/PlantVillage_for_object_detection/Dataset
but it no longer uses that loose folder automatically because mounted Google
Drive is too slow for 50k+ files. Use leaf_yolo_dataset.tar.gz or
automatic KaggleHub download for fast Colab prep.
- Prepared dataset, after running prep:
datasets/leaf_yolo - Class set:
nc: 1,names: ['leaf'] - Total images:
57,164 - Total leaf boxes:
63,225 - Empty-label hard negatives:
300 - Sources:
54,293images from the provided PlantVillage YOLO archive2,571public PlantDoc mixed-scene images converted from Pascal VOC to YOLO300synthetic no-leaf negatives
- Split:
- Train:
46,008images,51,905boxes - Val:
5,460images,5,432boxes - Test:
5,696images,5,888boxes
- Train:
The prepared dataset uses hardlinks for images, so it does not duplicate the full image storage on disk.
scripts/prepare_leaf_dataset.py: extracts, validates, merges, splits, and rewrites labels to class0scripts/validate_leaf_dataset.py: checks image-label pairing, YOLO box validity, and class IDsscripts/import_plantdoc_git.py: imports PlantDoc directly from Git blobs, including Windows-hostile filenamesscripts/generate_synthetic_negatives.py: creates temporary no-leaf negative imagesscripts/train_leaf_yolo.py: Colab A100 training, test evaluation, ONNX export, and TF.js exportdatasets/leaf_yolo/data.yaml: final YOLO dataset config, generated after prepdatasets/leaf_yolo/validation_report.json: latest validation report, generated after validationCOLAB_A100_STEPS.md: exact Colab commandsweb/: browser ONNX demo scaffold
python scripts\prepare_leaf_dataset.py `
--archive archive.zip `
--work-dir . `
--extra-yolo-dir public\plantdoc_yolo `
--hard-negatives-dir hard_negatives\synthetic `
--force
python scripts\validate_leaf_dataset.py `
--dataset datasets\leaf_yolo `
--write-reportFollow COLAB_A100_STEPS.md.
The smoke test trains yolo26s.pt for 20 epochs. The main run trains:
yolo26s.ptyolo26m.ptyolo26x.pt
Training uses pretrained weights, early stopping, cosine LR, fixed 640px main
training, mosaic closeout, HSV/geometry augmentation, mixup, and cutmix.
Multi-scale training is available with --multi-scale, but fixed sizing is the
default because it is more stable on ROCm/AMD GPUs. The main Colab run also
performs a lower-augmentation fine-tune stage from each candidate model's
best.pt. The final model should be chosen by test recall, mAP50-95, false
positives on no-leaf images, model size, and browser FPS.
Exported ONNX models can be tested in web/index.html after placing the chosen
model at:
leaf_detector/web/models/best.onnx
For a browser-first deployment, start with yolo26s or yolo26m. Keep yolo26x
only if the browser FPS is acceptable.
The original PlantVillage data is mostly centered 256x256 single-leaf imagery. The PlantDoc merge and hard negatives reduce that bias, but real webcam images from the final environment are still the best way to prove live performance.
The original PlantVillage object-detection dataset is hosted on Kaggle under CC BY-NC-SA 4.0. Check that license before any commercial deployment.