# lakshmir2802/ai-waste-segregation architecture

> Architecture diagram of the GitHub repository lakshmir2802/ai-waste-segregation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lakshmir2802/ai-waste-segregation
- Repository: https://github.com/lakshmir2802/ai-waste-segregation

## Overview

##### Project type and purpose
- This is an AI-powered embedded automation system combining a computer-vision model, real-time inference on a Raspberry Pi, and a servo-motor–driven physical sorting mechanism. Its purpose is to classify waste (organic, recyclable, non-recyclable) and actuate bin flaps accordingly.

##### File structure
- Top-level artifacts:
- Jupyter notebooks (“Fine Tuning MobileNetV2.ipynb”, “Webcam integration.ipynb”) → model training and inference workflows
- Python script (“servo_motor_control.py”) → hardware control logic for servos
- Demo videos (.mp4) → illustrative system behavior
- README.md & LICENSE → project documentation
- No separate “src” or “backend” folders; code is organized by function (training vs inference vs actuation).

##### README for additional insights
- Three main sub-systems: model training, real-time classification, physical sorting mechanism
- Hardware stack: Raspberry Pi, webcam, RPi.GPIO, servo motors
- Software stack: Python, TensorFlow/Keras, OpenCV

a. Main components
1. Model Training Environment
- Jupyter notebook
- MobileNetV2 base + custom dataset + data-augmentation
- Output: Saved model artifact (e.g., .h5 or TensorFlow SavedModel)
2. Inference Engine on Raspberry Pi
- Webcam captures frames → OpenCV preprocessing → load model → classify frame
- Service layer (could be simple Python script or notebook) emitting classification events
3. Sorting Actuator
- Servo-motor controller module (servo_motor_control.py)
- RPi.GPIO interface → physical servos → bin flaps
4. Physical Bins
- Three compartments (organic, recyclable, non-recyclable)
5. (Optional) Data Store/Logging
- Logging classifications and actuator actions (could be a simple text file or database)

b. Relationships and interactions
- Training → produces model file → deployed to Pi’s inference directory
- Inference component pulls live frames from webcam → runs model → outputs label
- (Optional) Every classification + action logged for later analysis

c. Architectural patterns & design principles
- Modular separation: training vs. inference vs. actuation
- Clear “data flow” pipeline: raw image → preprocessor → model → decision → actuator
- Hardware abstraction in servo_motor_control.py for easy reuse/improvements

d. Key technologies/frameworks
- TensorFlow/Keras (MobileNetV2)
- OpenCV (frame capture & preprocessing)
- RPi.GPIO (servo control)
- Jupyter notebooks for experimentation and demos

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Offline Training Layer
    subgraph "Offline Training Layer (Desktop)"
        NotebookTraining["Model Training Notebook\n(Fine Tuning MobileNetV2.ipynb)\nTensorFlow 2.x"]:::software
        DataAug["Data Augmentation & Dataset"]:::software
        ModelArtifact["Trained Model Artifact\n(.h5 / SavedModel)"]:::model
    end

    %% Edge Inference Layer
    subgraph "Edge Inference Layer (Raspberry Pi)"
        InferenceNotebook["Inference Notebook\n(Webcam integration.ipynb)\nPython 3.7+"]:::software
        Webcam["Webcam Capture\n(OpenCV)"]:::hardware
        Preprocessor["Image Preprocessor\n(OpenCV)"]:::software
        ModelLoader["Model Loader\nTensorFlow Lite"]:::software
        Classifier["Classifier Service\nPython 3.7+"]:::software
        Logging["Logging Service\nText File / CSV"]:::software
    end

    %% Actuation Layer
    subgraph "Actuation Layer (Hardware)"
        ServoController["Servo Motor Controller\n(servo_motor_control.py)\nRPi.GPIO"]:::software
        Servos["Servo Motors"]:::hardware
        Bins["Physical Bins:\nOrganic, Recyclable, Non-Recyclable"]:::hardware
    end

    %% Documentation & Assets
    subgraph "Documentation & Assets"
        README["README.md"]:::docs
        LICENSE["LICENSE"]:::docs
        Demo1["Demonstration of running waste classifier AI.mp4"]:::docs
        Demo2["Simulation of Waste Segregator.mp4"]:::docs
    end

    %% Connections
    NotebookTraining -->|"trains"| ModelArtifact
    ModelArtifact -->|"deployed model"| ModelLoader

    InferenceNotebook --> Webcam
    Webcam -->|"frame"| Preprocessor
    Preprocessor -->|"preprocessed frame"| Classifier
    Classifier -->|"label"| ServoController
    Classifier -->|"log entry"| Logging
    ModelLoader --> Classifier

    ServoController -->|"GPIO signal"| Servos
    Servos -->|"moves flap"| Bins

    %% Click Events
    click NotebookTraining "https://github.com/lakshmir2802/ai-waste-segregation/blob/main/Fine Tuning MobileNetV2.ipynb"
    click InferenceNotebook "https://github.com/lakshmir2802/ai-waste-segregation/blob/main/Webcam integration.ipynb"
    click ServoController "https://github.com/lakshmir2802/ai-waste-segregation/blob/main/servo_motor_control.py"
    click README "https://github.com/lakshmir2802/ai-waste-segregation/blob/main/README.md"
    click LICENSE "https://github.com/lakshmir2802/ai-waste-segregation/tree/main/LICENSE"
    click Demo1 "https://github.com/lakshmir2802/ai-waste-segregation/blob/main/Demonstration of running waste classifier AI.mp4"
    click Demo2 "https://github.com/lakshmir2802/ai-waste-segregation/blob/main/Simulation of Waste Segregator.mp4"

    %% Styles
    classDef software fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef model fill:#98FB98,stroke:#333,stroke-width:1px
    classDef hardware fill:#FFA500,stroke:#333,stroke-width:1px
    classDef docs fill:#D3D3D3,stroke:#333,stroke-width:1px
```
