# Coffee Leaf Disease Classification Using Deep Learning ## ๐Ÿ“Œ Introduction This project introduces a robust AI-based system for classifying coffee leaf diseases using deep learning and hybrid classification models. The system is capable of detecting five types of leaf conditions: **miner, rust, healthy, phoma, and cercospora**. The main objective is to support early detection of diseases in coffee plants to enhance agricultural productivity and sustainability. ## ๐Ÿง  Models Used The following models and hybrid configurations were implemented and analyzed: - CNN1 (custom architecture) - CNN2 (alternative custom CNN) - VGG16 (transfer learning) - CNN1 + SVM - CNN1 + Random Forest - CNN2 + SVM - CNN2 + Random Forest - VGG16 + SVM - VGG16 + Random Forest - ResNet50 - EfficientNetB0 ## ๐Ÿ“‚ Dataset - **Total images:** 58,555 - **Categories:** - `miner` - `rust` - `healthy` - `phoma` - `cercospora` Images were resized, normalized, and split into training and testing sets. ## ๐Ÿงช Preprocessing & Feature Extraction To enhance feature representation and model accuracy, the following techniques were applied: - **Data Augmentation:** - Horizontal Flip - Vertical Flip - Rotation (20ยฐ) - Brightness Increase - Gaussian Blur - **Texture-Based Feature Extraction:** - **LBP (Local Binary Pattern)** - **XCS-LBP (Extended Center-Symmetric LBP)** These features were especially valuable for hybrid models like CNN + SVM or CNN + RF. ## ๐Ÿง  Model Explainability To improve interpretability and transparency, the following techniques were integrated into the workflow: - Grad-CAM - Grad-CAM++ - SHAP - LIME These methods visually demonstrate how each model makes its decisions. ## ๐Ÿ’ป Training Environment - **Platform:** Kaggle - **GPU:** Tesla T4 - **Framework:** TensorFlow 2.x / Keras - All models were trained using GPU acceleration ## ๐Ÿš€ Project Structure ``` coffee_disease_classification/ โ”œโ”€โ”€ data_preprocessing/ โ”‚ โ””โ”€โ”€ preprocess.py โ”œโ”€โ”€ feature_extraction/ โ”‚ โ”œโ”€โ”€ lbp_extraction.py โ”‚ โ””โ”€โ”€ xcs_lbp_extraction.py โ”œโ”€โ”€ models/ โ”‚ โ”œโ”€โ”€ cnn1_model.py โ”‚ โ”œโ”€โ”€ cnn2_model.py โ”‚ โ”œโ”€โ”€ vgg16_model.py โ”‚ โ”œโ”€โ”€ resnet50_model.py โ”‚ โ”œโ”€โ”€ efficientnet_model.py โ”‚ โ””โ”€โ”€ hybrid_models.py โ”œโ”€โ”€ evaluation/ โ”‚ โ”œโ”€โ”€ metrics.py โ”‚ โ””โ”€โ”€ roc_curve_plotter.py โ”œโ”€โ”€ explanations/ โ”‚ โ”œโ”€โ”€ gradcam.py โ”‚ โ”œโ”€โ”€ gradcampp.py โ”‚ โ””โ”€โ”€ shap_lime.py โ”œโ”€โ”€ main.py โ””โ”€โ”€ requirements.txt ``` ## ๐Ÿ”ง How to Run ### 1. Clone the Repository ```bash git clone https://github.com/your-repo/coffee-leaf-disease-classification.git cd coffee-leaf-disease-classification ``` ### 2. Install Dependencies ```bash pip install -r requirements.txt ``` ### 3. Prepare Dataset Ensure the dataset is placed in the following directory structure: ``` dataset/ โ”œโ”€โ”€ miner/ โ”œโ”€โ”€ rust/ โ”œโ”€โ”€ healthy/ โ”œโ”€โ”€ phoma/ โ””โ”€โ”€ cercospora/ ``` ### 4. Preprocess and Extract Features ```bash python data_preprocessing/preprocess.py python feature_extraction/lbp_extraction.py python feature_extraction/xcs_lbp_extraction.py ``` ### 5. Train the Models ```bash python models/cnn1_model.py # Or try other models like: # python models/vgg16_model.py ``` ### 6. Evaluate Performance ```bash python evaluation/metrics.py python evaluation/roc_curve_plotter.py ``` ### 7. Run Explainability Tools ```bash python explanations/gradcam.py python explanations/shap_lime.py ```