Advanced plant disease detection system with explainable AI powered by ensemble deep learning models.
- Multi-Disease Detection: Identify multiple diseases in a single leaf image
- Explainable AI: Color-coded Grad-CAM visualizations showing affected areas
- Disease #1 → RED overlay
- Disease #2 → YELLOW overlay
- Disease #3 → BLUE overlay
- Ensemble Models: Combines 4 deep learning architectures
- ResNet50 (25% weight)
- DenseNet121 (30% weight)
- GhostNet (20% weight)
- AgriFusionNet (25% weight)
- Multi-Language Support: 11 Indian languages + English
- English, Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Punjabi, Malayalam, Kannada, Odia
- Image Quality Check: Validates image quality before prediction
- Real-Time Analysis: Instant AI-powered predictions
- Camera Support: Take photos directly or upload from gallery
- Framework: FastAPI (Python)
- Models: PyTorch-based ensemble
- Grad-CAM: DenseNet121 with custom color overlays
- Translation: Sarvam AI API for multilingual advice
- Framework: React + Vite
- Styling: TailwindCSS
- Features: Dark mode, responsive design, PWA support
cd backend
pip install -r requirements.txtKey Dependencies:
- fastapi
- uvicorn
- torch
- torchvision
- opencv-python
- pillow
- timm
- requests
cd frontend
npm installcd backend
# Create .env file
echo "SARVAM_API_KEY=your_api_key_here" > .env
# Start the backend server
uvicorn app:app --reload --host 0.0.0.0 --port 8000Backend will run on: http://127.0.0.1:8000
cd frontend
# Install dependencies
npm install
# Build for production
npm run build
# Preview production build
npm run previewFrontend will run on: http://localhost:4173
slmdd/
├── backend/
│ ├── app.py # FastAPI application
│ ├── gradcam.py # Grad-CAM visualization
│ ├── image_quality.py # Image quality checker
│ ├── utils.py # Utility functions
│ ├── sarvam_helper.py # Translation API helper
│ ├── requirements.txt
│ └── models/ # Model weights (.pth files)
│ ├── resnet_realistic.pth
│ ├── densenet_realistic.pth
│ ├── ghostnet_realistic.pth
│ └── agri_realistic.pth
├── frontend/
│ ├── src/
│ │ ├── App.jsx # Main React component
│ │ ├── translations.js # Multi-language translations
│ │ ├── CameraCapture.jsx # Camera component
│ │ └── index.css
│ ├── package.json
│ └── vite.config.js
├── train_resnet.py # Training scripts
├── train_densenet.py
├── train_ghostnet.py
├── train_agri.py
└── README.md
- Upload Image: User uploads or captures a leaf image
- Quality Check: System validates image quality
- Ensemble Prediction: 4 models predict diseases with confidence scores
- Grad-CAM Generation:
- DenseNet121 generates attention maps for each detected disease
- Each disease gets a unique color (RED, YELLOW, BLUE)
- 50/50 blend of original image and colored heatmap
- Visualization: Individual disease cards show affected areas
- Translation: Treatment advice translated to user's language
- Model: DenseNet121 (best performing in ensemble)
- Target Layer:
features.norm5 - Threshold: 0.4 (40% activation threshold)
- Blending: 50% original image + 50% colored heatmap
- Colors: Pure RGB (Red: 255,0,0 | Yellow: 255,255,0 | Blue: 0,0,255)
- Weighted average of model predictions
- Threshold: 0.5 confidence for disease detection
- Supports multiple simultaneous disease detection
Model weights are excluded from the repository due to size. To train models:
# Train ResNet50
python train_resnet.py
# Train DenseNet121
python train_densenet.py
# Train GhostNet
python train_ghostnet.py
# Train AgriFusionNet
python train_agri.pyNote: Place your dataset in dataset/ directory (excluded from git)
Predict diseases from an uploaded image.
Request:
{
"file": "<image_file>"
}Response:
{
"predictions": {...},
"detected_diseases": ["Disease1", "Disease2"],
"visualizations": [
{
"disease": "Disease1",
"color": "red",
"color_rgb": [255, 0, 0],
"image": "data:image/png;base64,..."
}
]
}Check image quality before prediction.
Translate text using Sarvam AI API.
- English (en)
- Hindi (hi)
- Bengali (bn)
- Tamil (ta)
- Telugu (te)
- Marathi (mr)
- Gujarati (gu)
- Punjabi (pa)
- Malayalam (ml)
- Kannada (kn)
- Odia (or)
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
arghaDEVIL
- GitHub: @arghaDEVIL
- PlantVillage Dataset
- PyTorch Team
- FastAPI Framework
- Sarvam AI for translation API
Note: Model files (.pth) and dataset are not included in the repository due to size constraints. Please train models or contact the author for pre-trained weights.