Abstract green and black wavy pattern

AI Plant Doctor

Blog post description about AI Plant Doctor

PROJECT DETAILS

6/12/20263 min read

a close up of a green fabric on a black background

PLANT DISEASE DETECTION

Deep Learning Crop Disease Diagnosis — From Leaf Photo to Treatment Plan in Seconds

38 Diseases • 14 Crops • ResNet50 Transfer Learning • Dosage Calculator • Smart Farm Advisory

What It Is

Plant Disease Detection is a deep learning system that diagnoses 38 plant diseases across 14 crops from a single leaf photograph — and then goes where other classifiers stop: it tells the farmer exactly which product treats the disease, calculates the precise dosage for their field size, explains how and when to spray, and provides prevention strategies for the next season. A built-in advisory layer can additionally factor in live weather forecasts, satellite vegetation indices, and local AI-generated agronomy advice.

It is the difference between an ML demo that says 'Tomato — Late Blight, 94% confidence' and a tool a farmer can actually act on.

The Problem It Solves

Crop disease destroys an estimated 20 to 40 percent of global agricultural production every year. For a smallholder farmer, the diagnostic chain is broken at every link: identifying a disease requires an agronomist who may be days away, misdiagnosis leads to spraying the wrong chemical, and even a correct diagnosis leaves the farmer guessing at dosage — overdosing wastes money and poisons soil, underdosing lets the disease win anyway.

This system collapses that entire chain into one photo: diagnosis, treatment selection, exact dosage for the farmer's field area, application instructions, and prevention guidance — in seconds, from a phone-quality image.

Coverage

The model classifies 38 disease and health states across 14 crops: Apple, Blueberry, Cherry, Corn, Grape, Orange, Peach, Bell Pepper, Potato, Raspberry, Soybean, Squash, Strawberry, and Tomato. Coverage spans fungal diseases (apple scab, black rot, late blight, leaf mold), bacterial infections, viral diseases (tomato mosaic virus, yellow leaf curl), pest damage (spider mites), and healthy-leaf states for every crop.

The ML Engineering

ResNet50 Transfer Learning With a Deep Custom Head

The production model builds on ResNet50 pre-trained on ImageNet, with a custom classification head: four dense blocks (1024, 512, 256 units) with batch normalization and progressively tuned dropout from 0.6 down to 0.3, ending in a 38-class softmax. This architecture leverages millions of images of general visual knowledge and specializes it for leaf pathology.

Two-Phase Fine-Tuning Strategy

Training runs in two deliberate phases: first the ResNet50 backbone is frozen and only the custom head learns (20 epochs); then the deeper backbone layers are unfrozen and the entire network fine-tunes at a reduced learning rate, with early stopping and learning-rate reduction on plateau. This staged approach prevents catastrophic forgetting of the pre-trained features — a standard mistake in naive transfer learning that this pipeline explicitly avoids.

Aggressive, Field-Realistic Data Augmentation

Real farmers do not photograph leaves in laboratories. The augmentation pipeline simulates field conditions: 40-degree rotations, 30% spatial shifts and zooms, horizontal and vertical flips, brightness swings from 0.7x to 1.3x, and color jittering across contrast, saturation, and hue. The model learns the disease, not the photography.

Mixed Precision Training and Proper Evaluation

Training uses TensorFlow mixed-precision (float16 compute with float32 stability) for GPU speed. Evaluation is rigorous: per-class precision, recall, and F1 scores, top-5 accuracy, a full 38x38 confusion matrix heatmap, and CSV classification reports — the model's weaknesses are measured and visible, not hidden behind a single accuracy number.

Deployment-Ready Model Export

The model exports in two forms: a full checkpoint with optimizer state for continued training, and a lightweight 25 MB inference-only version — small enough for affordable cloud hosting or edge deployment.

Beyond Diagnosis — The Treatment Layer

Every one of the 38 diagnoses maps to a curated treatment entry built on Tata Agri's product range:

• Specific fungicide, insecticide, or bactericide product recommendation per disease

• Step-by-step usage instructions — dosage, spray schedule, application method

• Prevention strategies — resistant varieties, sanitation, cultural practices

• Expert tips — application timing, temperature windows, safety precautions

Automatic Dosage Calculation

The farmer enters their field area in hectares. The system parses the dosage specification from the treatment instructions, applies the standard 500 liters-per-hectare water requirement, and computes the exact quantity of product to purchase. A session shopping cart accumulates the calculation — connecting diagnosis directly to procurement.

The Smart Advisory Layer

The advanced build elevates the tool from classifier to farm decision-support system:

• Weather integration — 7-day temperature, humidity, and rainfall forecasts from NASA's POWER API, requiring no API key

• Satellite vegetation health — optional Sentinel Hub NDVI indices for field-level crop monitoring

• Local AI agronomist — an Ollama-hosted LLM synthesizes the diagnosis, weather forecast, and field data into contextual advice: whether to spray before the rain arrives, how crop maturity changes the treatment, what to watch for next

• Market price hooks — stubbed integration points ready for regional commodity price APIs

A diagnosis that knows rain is coming tomorrow gives fundamentally better advice than one that does not.

Technology Stack

• TensorFlow 2.19 + Keras 3 — model training and inference

• ResNet50 — ImageNet transfer learning backbone

• Streamlit — interactive web application UI

• OpenCV + Pillow — image preprocessing

• NASA POWER API — free weather data, no key required

• Ollama — local LLM advisory, zero API cost

• Plotly / Matplotlib / Seaborn — evaluation visualizations

Current Stage

The ML core is complete and rigorously evaluated: training pipeline, two-phase fine-tuning, full per-class metrics, and exported production models. The Streamlit application works end-to-end — photo to diagnosis to dosage to cart. The advanced weather-and-AI advisory build is functional, and a cloud-deployment variant for Hostinger exists. Remaining productionization work: configuration externalization, containerization, and mobile packaging for true in-field use.

Most plant disease models stop at a label.

This one finishes the job — diagnosis, treatment, dosage, and a weather-aware plan the farmer can act on today.