Spaces:
Sleeping
A newer version of the Gradio SDK is available: 6.20.0
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
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
π 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
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
git clone YOUR_GITHUB_REPO_LINK
cd Plant_Disease
2. Create Virtual Environment
python -m venv venv
3. Activate Environment
Windows
venv\Scripts\activate
Mac/Linux
source venv/bin/activate
4. Install Dependencies
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
After downloading, place the model inside:
Plant_Disease/
β
βββ final_agrivision_model.keras
βββ app.py
βββ utils/
βΆοΈ Run Application
python app.py
Application runs at:
http://127.0.0.1:7860
π¦ Required Libraries
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.