A ResNet50-DCBAM Framework for Plant Disease Classification on the PlantVillage Dataset
This repository provides a reproducible implementation of a deep learning framework for plant disease classification.
The project investigates an architecture based on a pretrained ResNet50 backbone enhanced with DCBAM (Dual Channel & Spatial Attention Module) for image-based plant disease recognition.
The main objective is to improve discriminative feature learning by combining:
- ImageNet pretrained feature extraction
- ResNet50 hierarchical feature representation
- Channel and spatial attention refinement using DCBAM
- Flexible multi-level feature selection
- Efficient classification using global average pooling
The framework is designed for controlled experiments and reproducible research.
Overview of the proposed ResNet50-DCBAM framework for plant disease classification.
- ResNet50 backbone with pretrained ImageNet weights
- DCBAM attention integration
- Channel attention
- Spatial attention
- Flexible feature-level selection (
c2,c3,c4,c5) - PlantVillage dataset support
- Official train/test split support
- Data augmentation during training
- Automatic checkpoint management
- Validation-based model selection:
- Best Validation Loss
- Best Validation Accuracy
- Classification report generation
- Normalized confusion matrix visualization
- Experiment directory organization
Plant-Disease-Classification/
│
├── data/
│ └── PlantVillage/
│ ├── raw/
│ └── splits/
│
├── docs/
│ ├── figures/
│ │ └── architecture_overview.png
│ │
│ └── project_structure.md
│
├── experiments/
│ ├── checkpoints/
│ ├── logs/
│ ├── plots/
│ └── results/
│
├── src/
│ ├── config/
│ │ └── config.py
│ │
│ ├── datasets/
│ │ └── plant_dataset.py
│ │
│ ├── models/
│ │ ├── attention/
│ │ │ └── dcbam.py
│ │ │
│ │ ├── backbone/
│ │ │ └── resnet_dcbam.py
│ │ │
│ │ ├── classifier.py
│ │ └── plant_model.py
│ │
│ ├── training/
│ │ ├── train.py
│ │ └── test.py
│ │
│ └── utils/
│ ├── plot_logs.py
│ └── export_requirements.py
│
├── README.md
├── requirements.txt
├── LICENSE
└── .gitignore
The experiments use the public PlantVillage dataset.
Dataset access: PlantVillage Dataset
The dataset contains plant leaf images from multiple crop species and disease categories.
The project uses official split files:
data/
└── PlantVillage/
├── raw/
│ └── color/
│
└── splits/
├── color_train.txt
└── color_test.txt
Each split file contains relative image paths:
raw/color/Tomato___Late_blight/image_name.JPG
Clone the repository:
git clone https://github.com/AhmadJeddi/Plant-Disease-Classification.git
cd Plant-Disease-ClassificationInstall dependencies:
pip install -r requirements.txtRecommended environment:
- Python >= 3.10
- PyTorch >= 2.5
All experiments are controlled through:
src/config/config.py
Main configurable parameters:
- Dataset paths
- Image size
- Batch size
- Learning rate
- Training epochs
- Weight decay
- Early stopping patience
- Feature extraction level
- Pretrained backbone option
- Experiment directories
Example:
IMAGE_SIZE = 224
FEATURE_LEVEL = "c5"
PRETRAINED = True
BATCH_SIZE = 32The proposed model consists of three main components:
Input Image
|
v
ResNet50 Backbone
|
+--> DCBAM Attention Refinement
|
v
Feature Selection (c2/c3/c4/c5)
|
v
Global Average Pooling
|
v
Linear Classifier
|
v
Disease Class Prediction
The backbone extracts hierarchical visual representations:
- c2
- c3
- c4
- c5
The selected feature map is passed to the classifier.
DCBAM improves feature representation through:
- Channel attention:
- Adaptive average pooling
- Adaptive max pooling
- Shared MLP transformation
- Spatial attention:
- Channel-wise average pooling
- Channel-wise max pooling
- Convolution-based spatial refinement
Run training:
python src/training/train.pyTraining includes:
- Cross Entropy Loss
- Adam optimizer
- Data augmentation
- Validation monitoring
- Early stopping
- Automatic checkpoint saving
- Training curve visualization
Generated checkpoints:
experiments/
└── checkpoints/
├── best_loss.pth
└── best_acc.pth
Run evaluation:
python src/training/test.pyEvaluation provides:
- Classification report
- Precision
- Recall
- F1-score
- Normalized confusion matrix
- Saved experiment results
Results are stored in:
experiments/
└── results/
Visualizations:
experiments/
└── plots/
Two checkpoints are evaluated:
Selected based on minimum validation loss.
Selected based on maximum validation accuracy.
Both checkpoints are evaluated using the identical test protocol.
The final model was evaluated on the PlantVillage test split containing 10,709 images across 38 plant disease classes.
| Metric | Score |
|---|---|
| Accuracy | 99.79% |
| Macro F1-score | 99.69% |
| Weighted F1-score | 99.79% |
Both best-loss and best-accuracy checkpoints achieved identical test performance.
The project provides:
- Fixed random seed
- Centralized configuration
- Deterministic experiment structure
- Saved checkpoints
- Automated result logging
This project builds upon the ResNet50-DCBAM implementation from:
The original implementation was integrated into this framework with improved documentation, project-specific organization, and adaptation for the Plant Disease Classification task.
This project is licensed under the MIT License.
© Ahmad J. Zahed — Please keep the copyright notice and attribution when using or modifying this code. For full details, see the LICENSE file.
