# πΎ Vision Transformer for Wheat Leaf Disease Classification
This repository implements a Vision Transformer (ViT) model for fine-grained classification of wheat leaf diseases using token-level supervision, as described in the research paper:
> **Vision Transformer-Based Fine-Grained Classification of Wheat Leaf Diseases with Token-Level Supervision**
---
## π§ Key Features
- Implements Vision Transformer with patch-based embeddings.
- Incorporates **token-level supervision** combining class and patch token loss.
- Preprocessing with data augmentation to increase generalization.
- Custom training loop using TensorFlow and Keras.
- Visualization of attention via **Grad-CAM** for model interpretability.
- Benchmarking against other CNN architectures.
---
## π Directory Structure
```
.
βββ data_loader.py # Load and split dataset into train/val/test
βββ preprocessing.py # Resize and augment images
βββ patch_embedding.py # Patch embedding layer for ViT
βββ vit_model.py # Vision Transformer architecture
βββ token_supervision.py # Custom loss: class token + patch token
βββ train.py # Custom training loop using token-level loss
βββ evaluate.py # Evaluate model and generate Grad-CAM
βββ README.md # Project documentation
βββ vit_token_supervised_model.h5 # (Generated after training)
```
---
## π¦ Requirements
Install the dependencies:
```bash
pip install tensorflow pandas scikit-learn matplotlib seaborn
```
---
## ποΈ Dataset
Use the **Wheat Disease Images Small Dataset** from:
π Zenodo Dataset -
doi.org
Organize it in the following structure:
```
dataset/
βββ Yellow Rust/
βββ Brown Rust/
βββ Septoria/
βββ Mildew/
βββ Healthy/
```
Update the dataset path in `train.py` and `evaluate.py`:
```python
dataset_path = "path_to_your_dataset"
```
---
## π Training
Run the training script:
```bash
python train.py
```
The model will be β¦