PlantAi is a CNN trained on PlantVillage to classify leaf images as healthy or diseased. This repository provides PyTorch training code and export tools (ONNX / TorchScript / TFLite) for deployment.
- Training-first: Config-driven PyTorch pipeline (dataloader, augmentation, logging, plotting).
- Exports: ONNX / TorchScript / TFLite for downstream deployment.
- Lightweight inference: Designed for CPU-friendly inference after export.
# from repo root
pip install -r requirements.txtPython 3.9+ recommended. Use a virtualenv/conda if preferred.
-
Dataset placement Download PlantVillage and place under
model/data/<DATASET_NAME>/in class‑subfolders (ImageFolder layout). -
Config Edit
model/config/plantai_resnet_18.yaml:DATASET.PATH: model/dataDATASET.NAME: <DATASET_NAME>OUTPUT_DIR: log/plant_ai_resnet18(or your choice)
-
Run
cd model
python train.py --config_file config/plantai_resnet_18.yamlCheckpoints/plots are written under model/log/....
Ensure
MODEL.WEIGHTSin the YAML points to your trainedbest_model.pth.
cd model
# ONNX
python export/export_to_onnx.py --config_file config/plantai_resnet_18.yaml
# TorchScript (Lite)
python export/export_to_torchscript.py --config_file config/plantai_resnet_18.yaml
# TensorFlow Lite
python export/export_to_tf_light.py --config_file config/plantai_resnet_18.yaml --output plantai_model.tflite- ~54,305 images of healthy/diseased leaves captured on plain backgrounds.
- 38 classes total (26 diseases + healthy across common crops).
- ~17 crop types (e.g., apple, grape, corn, tomato, potato, pepper, etc.).
- Public, widely used for supervised learning; ideal for compact models and mobile inference.
Source: https://github.com/spMohanty/PlantVillage-Dataset
- Accuracy: 93.14%
- Precision (weighted): 92.90%
- Recall (weighted): 93.14%
- F1 Score (weighted): 92.50%
ResNet-18 (PlantVillage) — Download weights
- Dataset: PlantVillage — https://github.com/spMohanty/PlantVillage-Dataset



