How madhan-oss/plant-disease-recognition-system works
Project type and purpose
• This is a full-stack, deep-learning web application (“Plant Disease Recognition System”) built with Flask for serving a pre-trained CNN model and offering a web UI for farmers or researchers to upload leaf images and receive disease predictions. It also includes a training pipeline (train_model.py) for model retraining on custom datasets.
File structure
• Top-level files/directories (from README):
• model/ ← stores pretrained model (.h5)
• static/ ← CSS, JavaScript, images (client-side assets)
• templates/ ← Jinja2 HTML pages (UI views)
• dataset/ ← optional folder with training images (organized by class)
• app.py ← Flask application (inference server)
• train_model.py ← training script (data loading, CNN definition, training loop, .h5 export)
• plant_disease.json← disease label mappings/config
• Build/config files: requirements.txt (dependency list), maybe .gitignore (not shown).
• Architectural pattern: monolithic Flask app with two main flows—inference (app.py) and training (train_model.py). No separate microservices.
README for additional insights
• Technology stack: Python, TensorFlow/Keras, OpenCV, Flask, HTML/CSS/JS
• Features: image upload → inference → display result + confidence; retraining option
• No external databases—model and JSON file serve as the “knowledge base.”
a. Main components
• Client (Web Browser) – UI in templates/, static assets
• Inference Server (Flask app.py)
• CNN Model (model/plant_disease_model.h5)
• Configuration Store (plant_disease.json)
• Training Pipeline (train_model.py + dataset/)
• (Optional) Local File Storage for uploaded images
b. Relationships and interactions
1. User → Browser UI (HTML in templates, JS/CSS in static/)
2. UI sends HTTP POST (image) → Flask app (app.py)
3. app.py reads the image (via OpenCV), loads JSON label map, loads model (.h5) into TensorFlow/Keras, runs inference
4. app.py returns prediction + confidence → UI
5. For retraining: train_model.py reads dataset/ (images & labels), trains CNN, writes new .h5 to model/
c. Architectural patterns / design principles
• Separation of concerns: static assets and templates separated from Python code
• Single-process monolith for simplicity (no message brokers or microservices)
• Reusable ML pipeline decoupled from serving logic
• Config stored externally in JSON for easy updates
d. Key technologies
• Flask (WSGI web server)
• TensorFlow/Keras (model loading & inference, training)
• OpenCV (image preprocessing)
• Jinja2 templates (dynamic HTML)
• plant_disease.json (label mapping)
Detailed capture of essential elements
• Be explicit about the two flows—inference (real-time serving) vs training (offline pipeline).
• Clearly separate front-end static/templates from back-end code.
• External dependencies (TensorFlow, OpenCV) as annotation notes on the serving and training components.
• Don’t overcomplicate: this is a monolithic app, so a single component block for the server is sufficient, with labeled sub-components.
• Annotations for ports (HTTP:5000) if desired.