Skip to content

Repository files navigation

ADDC: Apple Disease Detection, Segmentation, Classification and Severity Estimation

A PyTorch pipeline for apple leaf disease analysis. It combines pixel-level disease segmentation, disease classification, and infection severity estimation into one workflow. Models are trained on PlantVillage and validated on PlantDoc as an external, real-field set.

Pipeline overview

Stage Task Models
1 Pixel-level disease segmentation U-Net (VGG16 encoder), DeepLabV3+ (ResNet50 backbone)
2 Disease classification MobileNetV2, DenseNet121, ResNet50, VGG16 (InceptionV3 optional, see notes)
3 Integrated inference Segmentation + classification + severity % in a single call
4 Ablation study (Table 6) Transfer learning, segmentation-guided ROI, mask supervision

All outputs are written under ./ADDC_project/ (models, figures, tables, predictions, history, metrics, exports, checkpoints, latex, reports).

Setup

python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
pip install -r requirements.txt

If pip install torch does not pick up GPU support automatically, install the CUDA build of PyTorch that matches your driver from https://pytorch.org/get-started/locally/.

Usage

  1. Open the notebook in VS Code or Jupyter and select the .venv as the kernel.
  2. Edit SegConfig and ClsConfig in the CONFIG cell. At minimum, set the four dataset paths and confirm that plantvillage_class_map and plantdoc_class_map match your folder names.
  3. Run the cells from top to bottom.

Expected dataset layout

PlantVillage/
  images/  Apple___healthy/, Apple___Apple_scab/, Apple___Black_rot/, Apple___Cedar_apple_rust/
  masks/   (same filename stems as the images)
PlantDoc/
  images/  (real-field validation)
  masks/   (optional, skipped automatically if absent)

The datasets are not included in this repository (see .gitignore). Download PlantVillage and PlantDoc separately and point the CONFIG paths at them.

Notes and configurable options

  • InceptionV3 is left out of the default models_to_train because it needs at least 299x299 input and would fail at the default 224x224 image_size. To use it, set CLS_CFG.image_size = (299, 299) and add "inceptionv3" back to the list.
  • run_cross_validation and run_repeated_seeds default to False. Set them to True for the full 5-fold cross-validation and repeated-seed tables. This increases training time by roughly 5 to 10 times.
  • KEEP_BN_FROZEN_DURING_FINETUNE keeps BatchNorm layers frozen during Phase 2 fine-tuning. The recommended default is True.
  • Mixed precision (AMP) is enabled by default on CUDA. Disable it with configure_gpu(use_mixed_precision=False).
  • estimate_leaf_mask() is a lightweight HSV heuristic used for the severity estimate. Replace it with a learned leaf-segmentation model for production use.

Requirements

Python 3.10+, PyTorch 2.2+ with CUDA, torchvision 0.17+. See requirements.txt.

License

MIT. See the LICENSE file.

About

PyTorch pipeline for apple leaf disease segmentation, classification and severity estimation on PlantVillage and PlantDoc.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages