--- license: mit library_name: pytorch pipeline_tag: image-classification tags: - plant-disease - plantvillage - gan - computer-vision - sdg-2 --- # LeafGen AI - models Plant-disease classifier (ResNet18, **38 classes, 14 crops**) and a conditional DCGAN that generates synthetic leaf images (64x64). Built for a Generative-AI PBL project (SDG 2 - Zero Hunger). Dataset: PlantVillage (lab photos). **Research prototype.** Trained on plain-background lab photos; not reliable on real field photos, and it only knows these 14 crops. ## Files | File | What it is | |---|---| | `cnn_real.pt` | ResNet18 trained on real data only (**recommended**, best overall) | | `cnn_aug.pt` | Same CNN trained on real + GAN-synthetic images (experiment model) | | `generator.pt` | Conditional DCGAN generator (noise 100 + one-hot class -> 64x64 RGB) | | `classes.json` | The 38 class names (index = model output index) | | `rare.json` | Indices of the 6 "rare" classes used in the experiment | | `results.json`, `assets/*.png` | Experiment results, confusion matrices, real-vs-synthetic figure | | `onnx/*.onnx` | ONNX versions (if present): input `image` float (N,3,64,64) values 0-255 -> output `probs`; generator inputs `z` (N,100), `onehot` (N,38) -> `images` 0-255 | | `leafgen_model.py` | Ready-to-use loading + inference code | ## Quick start ```python from leafgen_model import load_classifier, classify, load_generator, generate clf = load_classifier() # recommended model print(classify(clf, rgb_image)) # top-3 [(class, prob), ...] gen = load_generator() imgs = generate(gen, "Apple___Cedar_apple_rust", n=8) ``` **Preprocessing matters:** resize to 64x64 (INTER_AREA), then CLAHE (clip 2.0, tile 4x4) on the L channel in LAB colour space. Skipping this hurts accuracy. ## Results (3 seeds, 8,146 real test images) | Metric | A: real only | B: real + synthetic | |---|---|---| | Macro-F1 (38 classes) | 0.9784 | 0.9708 | | Accuracy | 98.42% | 97.78% | | Mean recall on 6 rare classes (100 real train images each) | 93.56% | 94.02% | Synthetic images did **not** improve overall performance; the rare-class gain is within seed-to-seed noise. ## Limitations - PlantVillage = plain-background lab photos; one leaf appears in many photos, so random splits can inflate scores. - 64x64 resolution, one GAN architecture, 3 seeds. - Only 14 crops; any other plant will get a (wrong) answer from these 38 classes - use the confidence value (low = unsure). Dataset: Hughes & Salathe (2015), PlantVillage. Check the dataset licence before redistributing images.