AgriHealth is a corn leaf disease classification project designed for measurable baseline performance and practical robustness checks. The current pipeline classifies images into:
BlightCommon_RustGray_Leaf_SpotHealthy
The project uses a local, testable pipeline with stratified validation, class-specific analysis, augmentation, background stress tests, and single-image prediction support.
Best clean-image baseline:
| Model | Augmentation | Validation Accuracy | Test Accuracy | Gray Leaf Spot Recall |
|---|---|---|---|---|
| Hybrid | strong | 0.9268 | 0.9221 | 0.7209 |
Field-background model:
| Model | Augmentation | Validation Accuracy | Test Accuracy | Gray Leaf Spot Recall |
|---|---|---|---|---|
| Hybrid | field | 0.9252 | 0.9189 | 0.7209 |
The field model loses a small amount of clean accuracy, but performs much better on synthetic background stress tests.
An earlier baseline used a small Sequential CNN trained from scratch on grayscale images. It had several issues:
- It used environment-specific paths.
- TensorFlow was not available locally during development.
- It converted RGB leaf images to grayscale, losing disease color cues.
- It did not use stratified splitting.
- It did not measure robustness to orientation, lighting, zoom, or background changes.
- It struggled with close classes, especially
BlightvsGray_Leaf_Spot.
The current system keeps a working, measurable baseline while leaving room to test a future transfer-learning CNN separately.
Expected local dataset structure:
data/
Blight/
Common_Rust/
Gray_Leaf_Spot/
Healthy/
Current dataset counts:
| Class | Images |
|---|---|
| Blight | 1146 |
| Common_Rust | 1306 |
| Gray_Leaf_Spot | 574 |
| Healthy | 1162 |
Gray_Leaf_Spot has fewer images than the other classes and remains the most difficult class.
Dataset source: Corn or Maize Leaf Disease Dataset
The script is:
copy_of_corn_and_plant_disease_detection_model.py
The pipeline:
- Load images from class folders.
- Split paths into train/validation/test with stratification.
- Apply augmentation to training images only.
- Extract RGB-based image features:
- HOG shape/edge features
- HSV color histograms
- Local Binary Pattern texture features
- brightness/saturation statistics
- Train one of several classifiers:
- SVM
- Random Forest
- Extra Trees
- Hybrid model
- Evaluate on validation/test sets.
- Save metrics, classification report, confusion matrix, and model artifact.
- Run robustness tests for rotations, lighting, zoom, and synthetic field backgrounds.
The best-performing model is a hybrid:
Random Forest broad classifier
+
specialist Blight vs Gray_Leaf_Spot classifier
The broad classifier handles all four classes. The specialist re-checks examples predicted as Blight or Gray_Leaf_Spot, because that is the most confused class pair.
This improved the difficult class without sacrificing overall performance.
Available training augmentation levels:
none
light
strong
field
light includes:
- horizontal flip
-15and+15degree rotations- darker/brighter images
- higher contrast
strong includes:
- flip
- rotations from
-30to+30degrees - brightness changes
- contrast changes
- zoom in/out
field includes all strong transforms plus synthetic background augmentation:
- fake soil background
- fake green field background
- mixed soil/green background
- zoomed-out leaf on field-like backgrounds
The field augmentation is generated procedurally, not with an image generator.
The code:
- Estimates a rough leaf mask from color/saturation.
- Generates noisy soil/green/mixed textures from hand-picked color palettes.
- Adds random pixel noise and a light gradient.
- Composites the leaf pixels over the synthetic background.
Demo:
The goal is not perfect realism. The goal is to prevent the classifier from assuming that every image has a clean dataset-style background.
Clean strong model:
| Stress Test | Accuracy | Gray Leaf Spot Recall |
|---|---|---|
| darker | 0.9253 | 0.7326 |
| brighter | 0.9221 | 0.7093 |
| very dark | 0.9205 | 0.7209 |
| zoom in | 0.9078 | 0.6860 |
| zoom out | 0.9046 | 0.6395 |
| rotate 90 | 0.8537 | 0.3023 |
| rotate 270 | 0.8506 | 0.2791 |
| field soil | 0.6439 | 0.2791 |
| field green | 0.8299 | 0.1512 |
| field mixed | 0.7266 | 0.2326 |
Field-background model:
| Stress Test | Accuracy | Gray Leaf Spot Recall |
|---|---|---|
| field soil | 0.8537 | 0.5116 |
| field green | 0.8792 | 0.4186 |
| field mixed | 0.8633 | 0.3837 |
The field model is clearly better for background clutter, but Gray_Leaf_Spot remains the most fragile class.
The model is not expected to magically understand every possible scan orientation. For prediction, the script can use orientation voting:
original
90 degrees
180 degrees
270 degrees
Each transformed image is predicted, then votes are combined. If there is a tie, the original image prediction is preferred.
This is safer than bloating training with every possible extreme rotation.
Create an environment and install dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtIf you are using Anaconda, install the packages from requirements.txt in your environment.
Run the dashboard:
python3 app.py --port 8000Then open:
http://127.0.0.1:8000
The UI reads saved metrics and charts from model_outputs/. Live image prediction is enabled when model_outputs/hybrid_corn_disease_model.joblib exists.
Train the current clean/strong hybrid model:
python3 copy_of_corn_and_plant_disease_detection_model.py \
--model hybrid \
--augmentation-level strong \
--leaf-preprocess noneTrain the field-background model:
python3 copy_of_corn_and_plant_disease_detection_model.py \
--model hybrid \
--augmentation-level field \
--leaf-preprocess noneThe script saves outputs to:
model_outputs/
Predict one image with the default hybrid model:
python3 copy_of_corn_and_plant_disease_detection_model.py \
--predict-image "path/to/image.jpg" \
--prediction-orientations right_anglesPredict with the field-background model:
python3 copy_of_corn_and_plant_disease_detection_model.py \
--predict-image "path/to/image.jpg" \
--model-file model_outputs/field_hybrid_corn_disease_model.joblib \
--prediction-orientations right_anglesOptional leaf preprocessing:
--leaf-preprocess crop
--leaf-preprocess maskcrop is less aggressive. mask can help reduce background, but it may erase disease regions if the mask is poor.
The trained model files are large:
hybrid_corn_disease_model.joblib: about 224 MB
field_hybrid_corn_disease_model.joblib: about 313 MB
GitHub regular Git rejects files larger than 100 MB. Use Git LFS if you want to store trained models:
git lfs install
git lfs track "*.joblib"
git add .gitattributesThe dataset is also not committed by default. Keep it local or publish it separately through a dataset hosting service.
- Build a real labeled
field_test/set with messy backgrounds. - Compare the clean model and field model on real field photos.
- Add a transfer-learning CNN in a separate file, not as a replacement until it beats this baseline.
- Consider a leaf detector or segmentation model if field photos contain multiple leaves, soil, hands, or heavy clutter.
- Treat uncertain vote splits as low-confidence predictions.
- This model is trained on one dataset.
- Synthetic background augmentation helps, but real field photos are more diverse.
Gray_Leaf_Spotremains the weakest class.- The rough leaf mask is not a real segmentation model.
- The current model is a strong baseline, not a final production-grade field diagnosis system.
Singh D, Jain N, Jain P, Kayal P, Kumawat S, Batra N. PlantDoc: a dataset for visual plant disease detection. In Proceedings of the 7th ACM IKDD CoDS and 25th COMAD; 2020 Jan 5. p. 249-253.
J, Arun Pandian; Gopal, Geetharamani. Data for: Identification of Plant Leaf Diseases Using a 9-layer Deep Convolutional Neural Network. Mendeley Data. 2019; V1. doi: 10.17632/tywbtsjrjv.1.
