Vivek Vishwakarma commited on
Commit
a9c42b1
ยท
verified ยท
1 Parent(s): babd968

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +459 -3
README.md CHANGED
@@ -1,3 +1,459 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ๐ŸŒฑ Crop Disease Detection AI
2
+
3
+ [![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg)](https://python.org)
4
+ [![PyTorch](https://img.shields.io/badge/PyTorch-2.1.0-red.svg)](https://pytorch.org)
5
+ [![Streamlit](https://img.shields.io/badge/Streamlit-1.28.0-red.svg)](https://streamlit.io)
6
+ [![Hugging Face Spaces](https://img.shields.io/badge/๐Ÿค—%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces)
7
+ [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+
9
+ An AI-powered crop disease detection system using deep learning to identify diseases in pepper, potato, and tomato crops from leaf images. The system provides accurate disease classification, risk assessment, visual explanations, and treatment recommendations.
10
+
11
+ > **๐Ÿš€ Now Ready for Deployment**: This project is optimized for Hugging Face Spaces deployment with Streamlit and Docker. All components have been tested and verified for production use.
12
+
13
+ ## ๐ŸŽฏ Project Overview
14
+
15
+ This project implements a comprehensive crop disease detection pipeline that:
16
+ - **Detects 15 different diseases** across pepper, potato, and tomato crops
17
+ - **Provides visual explanations** using Grad-CAM heatmaps
18
+ - **Offers treatment recommendations** from an integrated knowledge base
19
+ - **Calculates risk levels** based on confidence and environmental factors
20
+ - **Supports multiple interfaces**: Streamlit web app, CLI tool, and training notebooks
21
+ - **๐Ÿš€ Deployment Ready**: Optimized for Hugging Face Spaces with Docker support
22
+
23
+ ### ๐Ÿ† Key Features
24
+
25
+ - **๐Ÿค– AI Model**: ResNet50-based transfer learning with 26.1M parameters
26
+ - **๐Ÿ“Š Disease Classes**: 17 classes including healthy variants for each crop
27
+ - **๐ŸŽจ Visual Explanations**: Grad-CAM heatmaps highlighting infected regions
28
+ - **๐Ÿ“š Knowledge Base**: Comprehensive disease information with symptoms and treatments
29
+ - **โšก Real-time Processing**: Fast inference with GPU/CPU support
30
+ - **๐ŸŒ Web App**: Streamlit interface optimized for Hugging Face Spaces
31
+ - **๐Ÿ–ฅ๏ธ CLI Tool**: Command-line interface for batch processing
32
+ - **๏ฟฝ Training Pipeline**: Complete model training and evaluation system
33
+
34
+ ## ๐Ÿ“ Project Structure
35
+
36
+ ```
37
+ AiCropDiseasesDetection/
38
+ โ”œโ”€โ”€ ๐Ÿ“‚ api/ # FastAPI backend
39
+ โ”‚ โ”œโ”€โ”€ main.py # API server with endpoints
40
+ โ”‚ โ”œโ”€โ”€ requirements.txt # API dependencies
41
+ โ”‚ โ””โ”€โ”€ __init__.py # Package marker
42
+ โ”œโ”€โ”€ ๐Ÿ“‚ data/ # Dataset (train/val/test splits)
43
+ โ”‚ โ”œโ”€โ”€ train/ # Training images
44
+ โ”‚ โ”œโ”€โ”€ val/ # Validation images
45
+ โ”‚ โ””โ”€โ”€ test/ # Test images
46
+ โ”œโ”€โ”€ ๐Ÿ“‚ knowledge_base/ # Disease information
47
+ โ”‚ โ””โ”€โ”€ disease_info.json # Symptoms, treatments, prevention
48
+ โ”œโ”€โ”€ ๐Ÿ“‚ models/ # Trained model weights
49
+ โ”‚ โ”œโ”€โ”€ crop_disease_v3_model.pth # Latest V3 model (recommended)
50
+ โ”‚ โ””โ”€โ”€ README.txt # Model information
51
+ โ”œโ”€โ”€ ๐Ÿ“‚ notebooks/ # Jupyter notebooks
52
+ โ”‚ โ””โ”€โ”€ train_resnet50.ipynb # Training notebook
53
+ โ”œโ”€โ”€ ๐Ÿ“‚ outputs/ # Results and visualizations
54
+ โ”‚ โ”œโ”€โ”€ heatmaps/ # Grad-CAM visualizations
55
+ โ”‚ โ””โ”€โ”€ *.json # Evaluation results
56
+ โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Core source code
57
+ โ”‚ โ”œโ”€โ”€ dataset.py # Data loading and preprocessing
58
+ โ”‚ โ”œโ”€โ”€ model.py # ResNet50 architecture
59
+ โ”‚ โ”œโ”€โ”€ train.py # Training pipeline
60
+ โ”‚ โ”œโ”€โ”€ evaluate.py # Model evaluation
61
+ โ”‚ โ”œโ”€โ”€ explain.py # Grad-CAM explanations
62
+ โ”‚ โ”œโ”€โ”€ risk_level.py # Risk assessment logic
63
+ โ”‚ โ””โ”€โ”€ predict_cli.py # CLI predictor
64
+ โ”œโ”€โ”€ ๐Ÿ“‚ tests/ # Unit tests
65
+ โ”œโ”€โ”€ crop_disease_gui.py # Tkinter GUI application
66
+ โ”œโ”€โ”€ requirements.txt # Main dependencies
67
+ โ””โ”€โ”€ TRAINING_REPORT.md # Performance analysis
68
+ ```
69
+
70
+ ## ๐Ÿ› ๏ธ Technology Stack
71
+
72
+ ### Core Technologies
73
+ - **Deep Learning**: PyTorch 2.1.0, torchvision 0.16.0
74
+ - **Model Architecture**: ResNet50 with transfer learning
75
+ - **Web Framework**: Streamlit 1.28.0+
76
+ - **Computer Vision**: OpenCV, PIL/Pillow
77
+ - **Visualization**: Grad-CAM, matplotlib
78
+
79
+ ### Dependencies
80
+ - **Core ML**: PyTorch, torchvision, numpy
81
+ - **Image Processing**: OpenCV-Python, Pillow
82
+ - **Web Interface**: Streamlit
83
+ - **Visualization**: matplotlib, grad-cam
84
+ - **Utilities**: requests, tqdm, pydantic
85
+
86
+ ### Development Tools
87
+ - **Environment**: Python 3.9+ (Docker: python:3.9-slim)
88
+ - **Notebooks**: Jupyter/Google Colab support
89
+ - **Deployment**: Docker + Hugging Face Spaces
90
+ - **Version Control**: Git
91
+ - **Local Development**: Optimized for Windows PowerShell
92
+
93
+ ## ๐Ÿš€ Installation & Setup
94
+
95
+ ### Prerequisites
96
+ - Python 3.8 or higher
97
+ - pip package manager
98
+ - (Optional) CUDA-compatible GPU for faster training
99
+
100
+ ### 1. Clone Repository
101
+ ```bash
102
+ git clone https://github.com/vivek12coder/AiCropDiseasesDetection.git
103
+ cd AiCropDiseasesDetection
104
+ ```
105
+
106
+ ### 2. Create Virtual Environment
107
+ ```powershell
108
+ # Windows PowerShell (recommended)
109
+ python -m venv .venv
110
+ .\.venv\Scripts\Activate.ps1
111
+
112
+ # Alternative for Command Prompt
113
+ python -m venv .venv
114
+ .venv\Scripts\activate.bat
115
+
116
+ # macOS/Linux
117
+ python -m venv .venv
118
+ source .venv/bin/activate
119
+ ```
120
+
121
+ ### 3. Install Dependencies
122
+ ```powershell
123
+ # Install main dependencies
124
+ pip install -r requirements.txt
125
+
126
+ # For API development (optional)
127
+ pip install -r api/requirements.txt
128
+ ```
129
+
130
+ ### 4. Pre-trained Model
131
+ The repository includes the latest pre-trained model:
132
+ - `models/crop_disease_v3_model.pth` - Latest V3 model (recommended)
133
+
134
+ > **Note**: Older model versions have been removed to keep the project clean. Only the latest, best-performing model is included.
135
+
136
+ ### 5. Verify Installation
137
+ ```bash
138
+ python -c "import torch; print(f'PyTorch: {torch.__version__}')"
139
+ python -c "import torchvision; print(f'TorchVision: {torchvision.__version__}')"
140
+ ```
141
+
142
+ ## ๐Ÿ“– Usage Guide
143
+
144
+ ### ๐ŸŒ Streamlit Web App (Recommended)
145
+
146
+ The easiest way to use the system:
147
+
148
+ ```powershell
149
+ streamlit run app.py
150
+ ```
151
+
152
+ **Features:**
153
+ - ๏ฟฝ **Image Upload**: Drag & drop or browse for crop leaf images
154
+ - ๐Ÿ” **AI Analysis**: One-click disease detection with confidence scores
155
+ - ๐Ÿ“Š **Visual Explanations**: Grad-CAM heatmaps showing AI focus areas
156
+ - ๐Ÿ“š **Disease Information**: Detailed symptoms, treatments, and prevention
157
+ - ๐ŸŽฏ **Risk Assessment**: Environmental risk level calculation
158
+ - โš™๏ธ **Settings**: Customizable analysis options
159
+
160
+ **Supported Image Formats**: JPG, JPEG, PNG, BMP
161
+
162
+ ### ๐Ÿ“Š Model Training & Evaluation
163
+
164
+ Train and evaluate your own model with custom data:
165
+
166
+ ```powershell
167
+ # Evaluate existing model
168
+ python -m src.evaluate
169
+
170
+ # Train new model
171
+ python -m src.train
172
+
173
+ # Generate visual explanations
174
+ python -m src.explain
175
+ ```
176
+
177
+ ### ๐Ÿ” CLI Prediction Tool
178
+
179
+ Quick single-image prediction via command line:
180
+
181
+ ```powershell
182
+ # Predict disease for a single image
183
+ python -m src.predict_cli -i test_leaf_sample.jpg -m models\crop_disease_v3_model.pth
184
+
185
+ # With custom class names file
186
+ python -m src.predict_cli -i your_image.jpg --classes custom_classes.json
187
+ ```
188
+
189
+ ### ๐Ÿ”ฌ Jupyter Notebooks
190
+
191
+ Explore the training process interactively:
192
+
193
+ ```powershell
194
+ jupyter notebook notebooks/train_resnet50.ipynb
195
+ ```
196
+
197
+ ## ๐Ÿ’ก Usage Examples
198
+
199
+ ### Python Usage Example
200
+
201
+ ```python
202
+ # For programmatic use
203
+ import sys
204
+ sys.path.append('src')
205
+
206
+ from src.model import CropDiseaseResNet50
207
+ from src.dataset import preprocess_image
208
+ import torch
209
+ from PIL import Image
210
+
211
+ # Load model
212
+ model = CropDiseaseResNet50(num_classes=15)
213
+ checkpoint = torch.load('models/crop_disease_v3_model.pth', map_location='cpu')
214
+ model.load_state_dict(checkpoint)
215
+ model.eval()
216
+
217
+ # Make prediction
218
+ image = Image.open('your_leaf_image.jpg')
219
+ input_tensor = preprocess_image(image)
220
+ with torch.no_grad():
221
+ prediction = model(input_tensor)
222
+ confidence = torch.softmax(prediction, dim=1).max().item()
223
+
224
+ print(f"Prediction confidence: {confidence:.2%}")
225
+ ```
226
+
227
+ ### Command Line Usage
228
+
229
+ ```powershell
230
+ # Evaluate model performance
231
+ python -m src.evaluate
232
+
233
+ # Single image CLI prediction
234
+ python -m src.predict_cli -i test_leaf_sample.jpg -m models\crop_disease_v3_model.pth
235
+ ```
236
+
237
+ ### GUI Application Workflow
238
+
239
+ 1. **Launch Application**: `python crop_disease_gui.py`
240
+ 2. **Upload Image**: Click "๐Ÿ“ Select Image" button
241
+ 3. **Analyze**: Click "๐Ÿ” Analyze Disease" button
242
+ 4. **View Results**: See detailed analysis in results panel
243
+
244
+ ## ๐ŸŽฏ Model Performance
245
+
246
+ ### Current Performance (V3 Model)
247
+ - **Model Architecture**: ResNet50 with custom classifier layers
248
+ - **Parameters**: 26.1M total parameters
249
+ - **Input Size**: 224x224 RGB images
250
+ - **Classes**: 15 disease classes across 3 crops
251
+ - **Inference Speed**: ~0.1 seconds per image on CPU
252
+
253
+ ### Supported Disease Classes
254
+
255
+ **Pepper Diseases:**
256
+ - Bell Pepper Bacterial Spot
257
+ - Bell Pepper Healthy
258
+
259
+ **Potato Diseases:**
260
+ - Early Blight
261
+ - Late Blight
262
+ - Healthy
263
+
264
+ **Tomato Diseases:**
265
+ - Target Spot
266
+ - Tomato Mosaic Virus
267
+ - Tomato Yellow Leaf Curl Virus
268
+ - Bacterial Spot
269
+ - Early Blight
270
+ - Late Blight
271
+ - Leaf Mold
272
+ - Septoria Leaf Spot
273
+ - Spider Mites (Two-spotted)
274
+ - Healthy
275
+
276
+ > **Note**: The model has been trained on limited data. For production use, consider collecting more training samples per class.
277
+
278
+ ## ๐Ÿ”ง Configuration
279
+
280
+ ### Environment Variables
281
+ ```powershell
282
+ # Optional: Set device preference
283
+ $env:TORCH_DEVICE="cuda" # or 'cpu'
284
+
285
+ # Optional: Set model path
286
+ $env:MODEL_PATH="models/crop_disease_v3_model.pth"
287
+ ```
288
+
289
+ ### API Configuration
290
+ Edit `api/main.py` for production settings:
291
+ - CORS origins
292
+ - Authentication
293
+ - Rate limiting
294
+ - Logging levels
295
+
296
+ ## ๐Ÿš€ Deployment
297
+
298
+ ### ๐Ÿค— Hugging Face Spaces (Recommended)
299
+
300
+ The project is ready for one-click deployment on Hugging Face Spaces:
301
+
302
+ 1. **Fork/Clone** this repository
303
+ 2. **Create a new Space** on [Hugging Face Spaces](https://huggingface.co/spaces)
304
+ 3. **Select "Docker" SDK** when creating the Space
305
+ 4. **Upload the project files** or connect your Git repository
306
+ 5. **Wait for build** (5-10 minutes) and your app will be live!
307
+
308
+ **๐Ÿ“– Detailed Instructions**: See [DEPLOY_INSTRUCTIONS.md](DEPLOY_INSTRUCTIONS.md)
309
+
310
+ ### ๐Ÿ–ฅ๏ธ Local Streamlit App
311
+
312
+ ```powershell
313
+ # Install dependencies
314
+ pip install -r requirements.txt
315
+
316
+ # Run Streamlit app
317
+ streamlit run app.py
318
+
319
+ # Open browser to: http://localhost:8501
320
+ ```
321
+
322
+ ### ๐Ÿณ Docker Deployment
323
+
324
+ ```powershell
325
+ # Build image
326
+ docker build -t crop-disease-ai .
327
+
328
+ # Run container
329
+ docker run -p 7860:7860 crop-disease-ai
330
+
331
+ # Open browser to: http://localhost:7860
332
+ ```
333
+
334
+ ### Local Development
335
+ ```powershell
336
+ # GUI Application
337
+ python crop_disease_gui.py
338
+
339
+ # API Server
340
+ python -m api.main
341
+
342
+ # CLI Prediction
343
+ python -m src.predict_cli -i test_leaf_sample.jpg
344
+ ```
345
+
346
+ ### Local (Non-Docker) Quick Start
347
+
348
+ Use these steps on Windows PowerShell to run locally without Docker:
349
+
350
+ ```powershell
351
+ python -m venv .venv
352
+ .\.venv\Scripts\Activate.ps1
353
+ pip install -r requirements.txt
354
+ # Optional: API extras
355
+ pip install -r api/requirements.txt
356
+
357
+ # Evaluate model
358
+ python -m src.evaluate
359
+
360
+ # Run API
361
+ python -m api.main
362
+
363
+ # Single-image CLI prediction
364
+ python -m src.predict_cli -i test_leaf_sample.jpg -m models\crop_disease_v3_model.pth
365
+ ```
366
+
367
+ ### Cloud Deployment
368
+ The API is ready for deployment on:
369
+ - **AWS**: EC2, Lambda, ECS
370
+ - **Google Cloud**: Cloud Run, Compute Engine
371
+ - **Azure**: Container Instances, App Service
372
+ - **Heroku**: Container deployment
373
+
374
+ ## ๐Ÿค Contributing
375
+
376
+ ### Development Setup
377
+ 1. Fork the repository
378
+ 2. Create feature branch: `git checkout -b feature/new-feature`
379
+ 3. Make changes and test thoroughly
380
+ 4. Submit pull request with detailed description
381
+
382
+ ### Contribution Guidelines
383
+ - Follow PEP 8 style guidelines
384
+ - Add unit tests for new features
385
+ - Update documentation for API changes
386
+ - Ensure backward compatibility
387
+
388
+ ### Areas for Contribution
389
+ - **Data Collection**: Expand disease image dataset
390
+ - **Model Improvements**: Experiment with new architectures
391
+ - **Feature Enhancement**: Add new crops/diseases
392
+ - **Performance Optimization**: Speed and accuracy improvements
393
+ - **Documentation**: Tutorials and examples
394
+
395
+ ## ๐Ÿ“„ License
396
+
397
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
398
+
399
+ ## ๐Ÿ‘ฅ Authors & Acknowledgments
400
+
401
+ **Project Team:**
402
+ - **Lead Developer**: [Your Name]
403
+ - **AI/ML Engineer**: [Team Member]
404
+ - **Data Scientist**: [Team Member]
405
+
406
+ **Acknowledgments:**
407
+ - PlantVillage dataset for training data
408
+ - PyTorch team for deep learning framework
409
+ - FastAPI team for web framework
410
+ - Open source community for various tools
411
+
412
+ ## ๐Ÿ“ž Support & Contact
413
+
414
+ ### Getting Help
415
+ - **Documentation**: Check this README and code comments
416
+ - **Issues**: Create GitHub issue for bugs/feature requests
417
+ - **Discussions**: Use GitHub discussions for questions
418
+
419
+ ### Contact Information
420
+ - **GitHub Repository**: https://github.com/vivek12coder/AiCropDiseasesDetection
421
+ - **Issues**: Create GitHub issue for bugs/feature requests
422
+ - **Project Owner**: @vivek12coder
423
+
424
+ ## ๐Ÿ”ฎ Future Roadmap
425
+
426
+ ### Phase 1: Data Enhancement (Weeks 1-2)
427
+ - [ ] Collect 1000+ images per disease class
428
+ - [ ] Implement advanced data augmentation
429
+ - [ ] Create balanced train/val/test splits
430
+
431
+ ### Phase 2: Model Optimization (Weeks 3-4)
432
+ - [ ] Experiment with EfficientNet, MobileNet
433
+ - [ ] Implement ensemble methods
434
+ - [ ] Add uncertainty estimation
435
+
436
+ ### Phase 3: Feature Expansion (Weeks 5-6)
437
+ - [ ] Add more crop types (rice, wheat, etc.)
438
+ - [ ] Implement real-time video processing
439
+ - [ ] Mobile app development
440
+
441
+ ### Phase 4: Production Enhancement (Weeks 7-8)
442
+ - [ ] Cloud deployment with auto-scaling
443
+ - [ ] Monitoring and logging system
444
+ - [ ] User analytics and feedback system
445
+
446
+ ---
447
+
448
+ ## ๐Ÿ“Š Quick Start Checklist
449
+
450
+ - [ ] Install Python 3.8+
451
+ - [ ] Clone repository
452
+ - [ ] Install dependencies: `pip install -r requirements.txt`
453
+ - [ ] Test GUI: `python crop_disease_gui.py`
454
+ - [ ] Test API: `python -m api.main`
455
+ - [ ] Test CLI: `python -m src.predict_cli -i test_leaf_sample.jpg`
456
+ - [ ] Upload test image and verify results
457
+ - [ ] Explore API documentation at http://127.0.0.1:8000/docs
458
+
459
+ **๐ŸŽ‰ Ready to detect crop diseases with AI!**