GreenGuard is a mobile-centric project that uses computer vision and deep learning to detect plant diseases from images captured by a smartphone camera. The system is robust, efficient, and accurate, aiming to help farmers and researchers identify diseases quickly and take timely action. Below is a detailed breakdown of the entire workflow, from planning to deployment.
- Project Overview
- Dataset and Preprocessing
- Project Phases
- Project Structure
- Installation & Usage
- Future Enhancements
- License
GreenGuard leverages a deep learning model (MobileNetV2) to classify plant images into various crop-disease categories. It is designed for mobile use, ensuring low-latency inference and on-device processing using TensorFlow Lite.
- Accurate Disease Detection: Achieve high classification accuracy using preprocessed images.
- Efficient On-Device Inference: Deploy a lightweight TFLite model for real-time predictions on smartphones.
- User-Friendly Mobile App: Provide an intuitive Flutter interface that allows farmers to capture images and receive instant feedback.
Dataset: PlantVillage
- We curated a subset of 10–15 crops with multiple diseases each.
- Images were resized to
224×224pixels and normalized for consistency. - Annotations were stored in
data/annotations/annotations.csv.
Preprocessing Steps:
- Curating & Cleaning: Filenames standardized (
<crop>_<disease>_<id>.jpg). - Resizing & Denoising: Using OpenCV’s
fastNlMeansDenoisingColored. - Annotations: Created a combined label (
crop_disease) to simplify classification.
- Define Objectives & Success Criteria:
- Target accuracy ≥ 90%, inference time < 1 second on a mid-range smartphone.
- Identify Crops & Diseases:
- Chose relevant crops from PlantVillage and major diseases for each.
- Hardware & Software Selection:
- MobileNetV2 for the model.
- Flutter for the front-end.
- TFLite for on-device inference.
- Data Gathering & Filtration:
- Raw images in
data/raw/. - Removed poor-quality images or unknown labels.
- Raw images in
- Preprocessing Pipeline:
preprocessing.pyscript resizes, denoises, and saves images todata/processed/.
- Annotation Generation:
annotations.csvcreated, combiningcropanddiseaseas the final class.
- Model Selection:
- MobileNetV2 for a lightweight, efficient solution.
- Training Script (
train_recognition.py):- Splits data into train/validation (85/15).
- Uses
ImageDataGeneratorfor augmentation. - Compiles and trains the model, saving
final_model.h5.
evaluate_model.pyloadsfinal_model.h5, runs validation or test sets, and prints accuracy/loss.- Ensures the model meets performance goals (accuracy, speed).
convert_to_tflite.pyconvertsfinal_model.h5tomodel.tflite, enabling mobile deployment.- Optional optimization (quantization) can further reduce size and improve speed.
- The
mob_app/folder contains a Flutter project. model.tfliteis placed inassets/.- Using the
tflite_flutterpackage, the mobile app loads the model, preprocesses the captured image, and performs inference in real time.
GreenGuard/
├── data/
│ ├── raw/ # Raw images
│ ├── processed/ # Preprocessed images
│ └── annotations/ # Annotations (CSV, JSON)
├── models/
│ └── recognition/
│ ├── final_model.h5 # Trained model
│ ├── model.tflite # TFLite model for mobile
├── src/
│ ├── preprocessing.py # Data preprocessing script
│ ├── train_recognition.py # Model training script
│ ├── evaluate_model.py # Model evaluation
│ ├── convert_to_tflite.py # TFLite conversion
│ └── app.py # (Optional) Flask API or server integration
├── mob_app/
│ ├── pubspec.yaml # Flutter dependencies
│ ├── android/lib/
│ │ ├── main.dart # Main entry point for Flutter
│ │ ├── home_page.dart # UI for capturing and inferring images
│ └── assets/
│ ├── model.tflite # TFLite model
│ └── sample_image.jpg # Sample image
├── venv/
├── requirements.txt
└── README.md
git clone https://github.com/FAbdullah17/GreenGuard.git
cd GreenGuardpython -m venv venv
source venv/bin/activate # On Linux/macOS
venv\Scripts\activate # On Windows
pip install -r requirements.txtpython src/preprocessing.pypython src/train_recognition.pypython src/evaluate_model.pypython src/convert_to_tflite.pycd mob_app
flutter pub get
flutter run- Real-Time Camera Integration
- Fine-Tuning & Unfreezing Layers
- GPU Delegates & Quantization
- Backend/Cloud Integration
- Multi-Language Support
This project is licensed under the MIT License. Feel free to modify and distribute as needed.
Enjoy using GreenGuard! If you have questions, please open an issue or contact the maintainers.