Skip to content

Repository files navigation

AgriHealth Corn Disease Detection

AgriHealth is a corn leaf disease classification project designed for measurable baseline performance and practical robustness checks. The current pipeline classifies images into:

  • Blight
  • Common_Rust
  • Gray_Leaf_Spot
  • Healthy

The project uses a local, testable pipeline with stratified validation, class-specific analysis, augmentation, background stress tests, and single-image prediction support.

Current Status

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.

Why This Pipeline

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 Blight vs Gray_Leaf_Spot.

The current system keeps a working, measurable baseline while leaving room to test a future transfer-learning CNN separately.

Dataset Layout

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

Pipeline Design

The script is:

copy_of_corn_and_plant_disease_detection_model.py

The pipeline:

  1. Load images from class folders.
  2. Split paths into train/validation/test with stratification.
  3. Apply augmentation to training images only.
  4. Extract RGB-based image features:
    • HOG shape/edge features
    • HSV color histograms
    • Local Binary Pattern texture features
    • brightness/saturation statistics
  5. Train one of several classifiers:
    • SVM
    • Random Forest
    • Extra Trees
    • Hybrid model
  6. Evaluate on validation/test sets.
  7. Save metrics, classification report, confusion matrix, and model artifact.
  8. Run robustness tests for rotations, lighting, zoom, and synthetic field backgrounds.

Hybrid Model

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.

Augmentation Modes

Available training augmentation levels:

none
light
strong
field

light includes:

  • horizontal flip
  • -15 and +15 degree rotations
  • darker/brighter images
  • higher contrast

strong includes:

  • flip
  • rotations from -30 to +30 degrees
  • 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

Synthetic Field Backgrounds

The field augmentation is generated procedurally, not with an image generator.

The code:

  1. Estimates a rough leaf mask from color/saturation.
  2. Generates noisy soil/green/mixed textures from hand-picked color palettes.
  3. Adds random pixel noise and a light gradient.
  4. Composites the leaf pixels over the synthetic background.

Demo:

Background augmentation 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.

Robustness Results

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.

Orientation Handling

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.

Installation

Create an environment and install dependencies:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

If you are using Anaconda, install the packages from requirements.txt in your environment.

Local UI

Run the dashboard:

python3 app.py --port 8000

Then 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.

Training

Train the current clean/strong hybrid model:

python3 copy_of_corn_and_plant_disease_detection_model.py \
  --model hybrid \
  --augmentation-level strong \
  --leaf-preprocess none

Train the field-background model:

python3 copy_of_corn_and_plant_disease_detection_model.py \
  --model hybrid \
  --augmentation-level field \
  --leaf-preprocess none

The script saves outputs to:

model_outputs/

Prediction

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_angles

Predict 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_angles

Optional leaf preprocessing:

--leaf-preprocess crop
--leaf-preprocess mask

crop is less aggressive. mask can help reduce background, but it may erase disease regions if the mask is poor.

Model Artifacts and GitHub

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 .gitattributes

The dataset is also not committed by default. Keep it local or publish it separately through a dataset hosting service.

Recommended Next Steps

  1. Build a real labeled field_test/ set with messy backgrounds.
  2. Compare the clean model and field model on real field photos.
  3. Add a transfer-learning CNN in a separate file, not as a replacement until it beats this baseline.
  4. Consider a leaf detector or segmentation model if field photos contain multiple leaves, soil, hands, or heavy clutter.
  5. Treat uncertain vote splits as low-confidence predictions.

Important Limitations

  • This model is trained on one dataset.
  • Synthetic background augmentation helps, but real field photos are more diverse.
  • Gray_Leaf_Spot remains 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.

References

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.

About

AgriHealth is a corn leaf disease classification project designed for measurable baseline performance and practical robustness checks.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages