How saribx/plant-disease-detection-aihws works
1. Repository purpose
- This is a plant disease detection system for potato leaves.
- It combines an ML training/evaluation pipeline with a FastAPI-based inference web app.
2. Main architectural split
- The repo is divided into two clear paths:
- Offline ML workflows: dataset loading, model training, and evaluation.
- Online serving/UI: the web app that accepts an image and returns a prediction.
- The saved .keras model files in models/ are the handoff point between these two worlds.
3. Modeling approach
- The project maintains three separate CNN models for different input modalities:
- model_color.keras
- model_grayscale.keras
- model_segmented.keras
- This implies the inference layer selects a model based on how the uploaded leaf image is represented or preprocessed.
4. Data layer
- The dataset is organized under data/ into three parallel variants:
- plant_color/
- plant_grayscale/
- plant_segmented/
- Each variant contains the same class folders:
- Potato___Early_blight
- Potato___Late_blight
- Potato___healthy
- This structure is important because it shows the training pipeline is class-based and modality-specific.
5. Training subsystem
- src/train.py is the offline entry point for building the models.
- src/data_loader.py likely centralizes dataset ingestion and preprocessing.
- src/model.py likely defines the CNN architecture used for all or most modalities.
- src/utils.py probably contains shared helpers used across training and evaluation.
6. Evaluation subsystem
- src/evaluate.py is a separate offline step for measuring model performance.
- The presence of evaluation_results.pdf indicates evaluation outputs are generated as a report artifact, not just printed to console.
- This makes evaluation a distinct batch process from serving.
7. Web application layer
- src/app.py is the runtime server entry point.
- src/templates/index.html plus files in src/static/ indicate a server-rendered UI with client-side enhancement.
- script.js, history.js, and style.css are the browser-facing pieces of the app.
8. Client/server interaction
- The browser likely handles image preview locally before upload, while the server handles actual inference.
- The README says the history sidebar uses LocalStorage, so user history is kept on the client rather than in a backend database.
- There is no evidence of a persistent application database or external storage service.
9. Inference/runtime boundary
- The app serves predictions from pre-trained Keras models rather than training on demand.
- The README describes lazy-loading models by modality, which suggests the server loads model files only when needed to reduce startup and memory overhead.
- That makes the inference path lightweight compared with the training path.
10. Technology stack that matters
- FastAPI is the web runtime.
- Keras/TensorFlow is the model format/runtime implied by the .keras files.
- uv is used for dependency management and launching the app, which affects reproducibility and local setup.
- The UI is plain HTML/CSS/JavaScript rather than a heavyweight frontend framework.
11. Operational flow
- Typical lifecycle is:
1. prepare dependencies,
2. train the CNNs from data/,
3. evaluate and generate the PDF report,
4. run the FastAPI app using the saved models.
- The trained artifacts in models/ are the production inputs for the serving layer.
12. Key architecture boundaries for a diagram
- Draw three boxes: dataset + preprocessing, training/evaluation, and web inference UI/server.
- Show the models/ directory as the artifact bridge between training and serving.
- Show LocalStorage as a browser-side store separate from any server persistence.
- Show the static/templates assets as part of the web UI boundary, not the ML pipeline.
Main entry points: app.py FastAPI app · train.py Train · evaluate.py Evaluate · data_loader.py Loader
Components 17
Data
Modality-specific training datasets grouped by representation.
- Color data · Color image training set for potato leaf classes.
data/plant_color - Gray data · Grayscale image training set for potato leaf classes.
data/plant_grayscale - Segmented data · Segmented leaf training set for potato leaf classes.
data/plant_segmented
Offline ML
Training, model definition, and evaluation pipeline.
- Loader · Central dataset ingestion and preprocessing logic.
src/data_loader.py - CNN model · Shared CNN definition used for the disease classifiers.
src/model.py - Train · Offline training entry point for building models.
src/train.py - Evaluate · Offline evaluation step that measures model performance.
src/evaluate.py
Artifacts
Saved models and generated evaluation outputs.
- Color model · Saved Keras model for the color modality.
models/model_color.keras - Gray model · Saved Keras model for the grayscale modality.
models/model_grayscale.keras - Segmented model · Saved Keras model for the segmented modality.
models/model_segmented.keras - Report · Generated evaluation output artifact.
evaluation_results.pdf
Serving UI
FastAPI runtime plus browser-facing templates and static assets.
- FastAPI app · Runtime inference entry point and HTTP API.
src/app.py - Index page · Server-rendered landing page for image upload and results.
src/templates/index.html - Script · Client-side upload, preview, and interaction logic.
src/static/script.js - History · Client-side prediction history and local persistence.
src/static/history.js - Styles · Presentation styling for the web UI.
src/static/style.css - LocalStorage · Client-side history store with no backend database.
Connections 21
- Loader → Color data: reads · Loads color modality training data.
- Loader → Gray data: reads · Loads grayscale modality training data.
- Loader → Segmented data: reads · Loads segmented modality training data.
- Train → Loader: uses · Training depends on centralized loading and preprocessing.
- Train → CNN model: builds · Constructs the CNN architecture for training.
- Train → Color model: writes · Produces the color model artifact.
- Train → Gray model: writes · Produces the grayscale model artifact.
- Train → Segmented model: writes · Produces the segmented model artifact.
- Evaluate → Color model: loads · Evaluates the trained color model.
- Evaluate → Gray model: loads · Evaluates the trained grayscale model.
- Evaluate → Segmented model: loads · Evaluates the trained segmented model.
- Evaluate → Report: exports · Generates the PDF evaluation report.
- FastAPI app → Color model: serves · Uses the color model for inference when needed.
- FastAPI app → Gray model: serves · Uses the grayscale model for inference when needed.
- FastAPI app → Segmented model: serves · Uses the segmented model for inference when needed.
- FastAPI app → Index page: renders · Serves the UI shell to the browser.
- FastAPI app → Script: serves · Exposes client-side interaction logic.
- FastAPI app → History: serves · Exposes prediction history behavior.
- FastAPI app → Styles: serves · Exposes UI styling assets.
- Script → LocalStorage: stores · Keeps client-side prediction history in the browser.
- History → LocalStorage: reads · Restores prior history from browser storage.