--- title: AgriVision AI emoji: ๐ŸŒฟ colorFrom: green colorTo: blue sdk: gradio sdk_version: "5.34.2" python_version: "3.10" app_file: app.py pinned: false --- # ๐ŸŒฟ AgriVision AI โ€” Plant Disease Detection using Deep Learning AgriVision AI is an end-to-end Deep Learning + Computer Vision project that detects plant diseases from leaf images using Transfer Learning with EfficientNetB0. The system predicts 38 different plant disease categories with high accuracy and provides: * Disease Prediction * Confidence Scores * Grad-CAM Visualization * Disease Description * Symptoms * Prevention Methods * Cure Suggestions Built using TensorFlow, OpenCV, EfficientNet, and Gradio. --- # ๐Ÿš€ Features โœ… Plant Disease Detection using AI โœ… 38 Disease Categories โœ… Transfer Learning with EfficientNetB0 โœ… Fine-Tuned Deep Learning Model โœ… Leaf Segmentation for Better Predictions โœ… Grad-CAM Explainability Visualization โœ… Top-3 Predictions with Confidence Bars โœ… Disease Information & Cure Suggestions โœ… Interactive Gradio Web Application โœ… Real-Time Image Prediction System --- # ๐Ÿง  Problem Statement Plant diseases significantly reduce agricultural productivity and crop quality. Traditional disease identification: * requires expert knowledge * is time-consuming * may delay treatment AgriVision AI helps farmers and researchers instantly identify plant diseases using leaf images. --- # ๐ŸŒฑ Why This Project Matters This project combines: * Artificial Intelligence * Agriculture * Deep Learning * Computer Vision * Explainable AI Applications: * Smart Farming * Precision Agriculture * AI-Based Crop Monitoring * Agricultural Decision Support Systems --- # ๐Ÿ—๏ธ Project Workflow ```text Leaf Image โ†“ Leaf Segmentation โ†“ Image Preprocessing โ†“ EfficientNetB0 Model โ†“ Disease Prediction โ†“ Grad-CAM Visualization โ†“ Disease Information & Cure Suggestions ``` --- # ๐Ÿ› ๏ธ Tech Stack ## Programming Language * Python ## Deep Learning Frameworks * TensorFlow * Keras ## Computer Vision * OpenCV * Grad-CAM ## Deployment * Gradio ## Image Processing * NumPy * Pillow * rembg --- # ๐Ÿ“‚ Dataset ## PlantVillage Dataset * 54,000+ Images * 38 Classes * Multiple Crops & Diseases Dataset Source: [https://www.kaggle.com/datasets/emmarex/plantdisease](https://www.kaggle.com/datasets/emmarex/plantdisease) --- # ๐Ÿ“Š Disease Categories The model supports 38 classes including: * Apple Diseases * Corn Diseases * Tomato Diseases * Potato Diseases * Grape Diseases * Strawberry Diseases * Peach Diseases * Pepper Diseases * Soybean Diseases * Healthy Leaf Detection --- # ๐Ÿงช Model Development Phases ## Phase 1 โ€” Dataset Preparation Performed: * Data Loading * Train/Validation Split * Image Augmentation Techniques: * Rotation * Zoom * Horizontal Flip * Rescaling --- ## Phase 2 โ€” Baseline CNN Model Built a custom CNN using: * Conv2D * MaxPooling * BatchNormalization * Dropout * Dense Layers Purpose: * Establish baseline performance * Understand CNN workflow --- ## Phase 3 โ€” Transfer Learning Used: ### EfficientNetB0 Advantages: * Better Feature Extraction * Higher Accuracy * Fewer Parameters * Faster Training Initially froze pretrained layers. --- ## Phase 4 โ€” Fine Tuning Unfroze upper EfficientNet layers and retrained using: * Low Learning Rate * Additional Epochs Result: โœ… Significant performance improvement --- # ๐Ÿ“ˆ Final Results | Metric | Value | | ------------------- | ---------------- | | Validation Accuracy | 96% | | Model | EfficientNetB0 | | Classes | 38 | | Dataset Size | 54K+ Images | | Framework | TensorFlow/Keras | --- # ๐Ÿ” Explainable AI with Grad-CAM Grad-CAM highlights regions of the image influencing model predictions. Benefits: * Improves transparency * Helps visualize model focus * Makes predictions explainable --- # โœ‚๏ธ Leaf Segmentation Implemented background removal using: ### rembg Benefits: * Reduces background noise * Improves internet image prediction * Better real-world generalization --- # ๐ŸŒ Web Application Built using: ### Gradio Features: * Upload Leaf Image * View Top Predictions * Confidence Bars * Grad-CAM Heatmap * Disease Information * Cure Suggestions --- # ๐Ÿ“ Project Structure ```bash Plant_Disease/ โ”‚ โ”œโ”€โ”€ app.py โ”œโ”€โ”€ README.md โ”œโ”€โ”€ requirements.txt โ”œโ”€โ”€ .gitignore โ”‚ โ”œโ”€โ”€ utils/ โ”‚ โ”œโ”€โ”€ predict.py โ”‚ โ”œโ”€โ”€ gradcam.py โ”‚ โ”œโ”€โ”€ segmentation.py โ”‚ โ””โ”€โ”€ disease_info.py โ”‚ โ”œโ”€โ”€ sample_images/ โ”‚ โ””โ”€โ”€ notebooks/ ``` --- # โš™๏ธ Installation ## 1. Clone Repository ```bash git clone YOUR_GITHUB_REPO_LINK cd Plant_Disease ``` --- ## 2. Create Virtual Environment ```bash python -m venv venv ``` --- ## 3. Activate Environment ### Windows ```bash venv\Scripts\activate ``` ### Mac/Linux ```bash source venv/bin/activate ``` --- ## 4. Install Dependencies ```bash pip install -r requirements.txt ``` --- # ๐Ÿ“ฅ Download Trained Model Due to GitHub file size limitations, the trained model is hosted externally. Download Model Here: [_Click_HERE](https://drive.google.com/file/d/1gPvOvKM3Ri8UEPHdqoFIQmN0MqZbX_cf/view?usp=sharing) After downloading, place the model inside: ```bash Plant_Disease/ โ”‚ โ”œโ”€โ”€ final_agrivision_model.keras โ”œโ”€โ”€ app.py โ””โ”€โ”€ utils/ ``` --- # โ–ถ๏ธ Run Application ```bash python app.py ``` Application runs at: ```bash http://127.0.0.1:7860 ``` --- # ๐Ÿ“ฆ Required Libraries ```txt tensorflow opencv-python gradio numpy pillow matplotlib rembg onnxruntime ``` --- # ๐Ÿง  Key Learnings Through this project I learned: * Transfer Learning * EfficientNet Architecture * CNN Fundamentals * Fine Tuning * Grad-CAM Explainability * Leaf Segmentation * Deep Learning Deployment * Real-World Image Challenges * Domain Shift Problems * Model Generalization --- # โš ๏ธ Real-World Challenges The model performs strongly on PlantVillage-style images. Challenges with internet images include: * Complex backgrounds * Different lighting conditions * Blurry images * Domain shift * Real-world variability Future improvements: * Real farm dataset training * Lesion segmentation * Higher resolution models * Advanced explainability techniques --- # ๐Ÿš€ Future Improvements * Mobile App Deployment * Multi-Language Support * Real-Time Webcam Detection * Cloud Deployment * Disease Severity Estimation * PDF Report Generation * Advanced Explainability Methods * Farmer Advisory System --- # ๐Ÿ‘จโ€๐Ÿ’ป Author Mohd Faizanullah AI/ML Enthusiast | Deep Learning | Computer Vision | Generative AI --- # โญ Support If you like this project, give it a star โญ on GitHub.