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.
| 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).
python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
pip install -r requirements.txtIf 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/.
- Open the notebook in VS Code or Jupyter and select the
.venvas the kernel. - Edit
SegConfigandClsConfigin the CONFIG cell. At minimum, set the four dataset paths and confirm thatplantvillage_class_mapandplantdoc_class_mapmatch your folder names. - Run the cells from top to bottom.
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.
- InceptionV3 is left out of the default
models_to_trainbecause it needs at least 299x299 input and would fail at the default 224x224image_size. To use it, setCLS_CFG.image_size = (299, 299)and add"inceptionv3"back to the list. run_cross_validationandrun_repeated_seedsdefault toFalse. Set them toTruefor the full 5-fold cross-validation and repeated-seed tables. This increases training time by roughly 5 to 10 times.KEEP_BN_FROZEN_DURING_FINETUNEkeeps BatchNorm layers frozen during Phase 2 fine-tuning. The recommended default isTrue.- 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.
Python 3.10+, PyTorch 2.2+ with CUDA, torchvision 0.17+. See requirements.txt.
MIT. See the LICENSE file.