# abekek/cse398_project architecture

> Architecture diagram of the GitHub repository abekek/cse398_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abekek/cse398_project
- Repository: https://github.com/abekek/cse398_project

## Overview

##### Project Type & Purpose
- This project is a specialized assistive technology application that uses computer vision and deep learning techniques to facilitate eye-gaze based control for a keyboard interface.
- It involves real-time camera input processing, facial/eye landmark detection, neural network inference, and a user interface for keyboard interactions.
- The README clearly shows a training/inference pipeline as well as a demo interface, which means you need to capture both the perception (image processing/inference) and output (keyboard interaction) sides of the system.

##### File Structure for Architectural Clues
- Top-level Organization:
- The src Directory:
- Contains the main operational scripts (e.g., main.py) that likely tie together the system’s initialization, video capture, and inference operation.
- Contains multiple modules categorized by functionality:
▪ Detection Methods: Files such as CustomLandmarkDetection.py, FaceMeshMethod.py, and NNMethod.py hint at different algorithms or approaches for detecting eye landmarks.
▪ UI/Interaction: SelectionWindow.py suggests a GUI component enabling user interactions.
▪ Model Definitions: The models directory with eyenet.py, layers.py, and losses.py contains code for the neural network architecture involved in eye detection/prediction.
▪ Utility Functions: The util subdirectory (eye_prediction.py, gaze.py, softargmax.py, etc.) supports various computations essential for processing and interpreting eye movements.
▪ Notebooks: The notebooks folder, which contains Jupyter notebooks, indicates that part of the project’s development or exploratory data analysis also revolves around eye gaze and facial landmark detection.
▪ Model Conversion & Saved Models: Files like onnx_convert.py and the saved_models directory hold pre-trained models and conversion scripts, signifying that deployment also includes optimizing model representation.

##### Main Components
a. Input and Capture:
- External Camera: Capture of real-time video feed.
- Pre-Processing Module: Prepares the input (resizing, normalization) for detection.
b. Detection & Inference:
- Detection Modules: Include the various methodologies – CustomLandmarkDetection, FaceMeshMethod, and NNMethod – which compute facial/eye landmarks.
- Neural Network Models: Represent the deep learning component (depicted in models/eyenet.py, layers.py, and losses.py) that performs gaze estimation.
- Model Conversion & Deployment: ONNX conversion (onnx_convert.py) and saved models form a subcomponent highlighting production readiness.
c. User Interface & Output:
- Selection Window / Keyboard Interface: The module (SelectionWindow.py) responsible for mapping detected eye movements to keyboard actions.
- Feedback Loop: Visualization components (from public directory images) that show either real-time feedback on the screen or an example interface.
d. Utilities & Dependencies:
- Utility Scripts: Functions supporting gaze calculation and further signal processing found in src/util.
- Training/Inference Pipeline: As outlined in the README, include a component that addresses the training phase as well as the actual inference process.
e. External Dependencies & Environment:
- Environment Setup: The environment.yml signals dependency management (Conda environment).

##### Relationships and Interactions
- Data flow: Video feed from the camera flows into the pre-processing module then through one or more detection methods.
- Dependency: The main.py orchestrates the integration of all detection, model inference, and UI components.
- Feedback/Control: From the gaze detection output to the selection window that emulates a keyboard for user command.
- Conversion Flow: Show how models saved in various formats (.pth, .onnx, etc.) interact with the inference modules.

##### Architectural Patterns & Design Principles
- Modularity: Each detection method (custom, mesh, NN-based) stands as a separate module making it easier to swap or update techniques.
- Separation of Concerns: Clear distinction between input processing, model inference, and user interface layers.
- Extensibility: The design allows for the simple addition of new processing modules or model types due to the clearly structured directories.
- Pipeline Pattern: The README’s “Training/Inference Pipeline” image should be reflected by having sequential processing steps from data capture to keyboard output.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Input Layer
    A["Camera Input"]:::data
    B["Preprocessing Module"]:::data

    %% Main Orchestration
    C["Main Controller (main.py)"]:::control

    %% Detection Modules Subgraph
    subgraph "Detection Modules"
        D1["Custom Landmark Detection"]:::detection
        D2["Face Mesh Detection"]:::detection
        D3["Neural Network Method"]:::detection
    end

    %% Inference & Model Processing
    E["Neural Network Inference"]:::inference
    F["Neural Network Models (eyenet, layers, losses)"]:::inference
    G["Model Conversion & Deployment"]:::inference

    %% User Interface & Output
    H["User Interface & Keyboard (SelectionWindow)"]:::ui
    I["Visual Feedback (public assets)"]:::ui

    %% Utility and Infrastructure
    J["Utility Functions (gaze, eye_prediction, softargmax)"]:::util
    K["Training/Inference Pipeline (README)"]:::doc
    L["Environment Setup (environment.yml)"]:::env

    %% Connections: Data Flow and Dependencies
    A -->|"video_feed"| B
    B -->|"processed_data"| C
    C -->|"initiate"| D1
    C -->|"initiate"| D2
    C -->|"initiate"| D3

    %% Detection methods send landmarks to inference
    D1 -->|"landmarks"| E
    D2 -->|"landmarks"| E
    D3 -->|"landmarks"| E

    %% Inference uses models
    E -->|"model_calls"| F
    F -->|"deployment_ready"| G

    %% Inference results drive UI actions
    F -->|"command_output"| H
    G -->|"deployment_artifacts"| H

    %% UI provides feedback
    H -->|"display"| I

    %% Utility support for detection/inference
    J ---|"support"| D1
    J ---|"support"| D2
    J ---|"support"| D3
    J ---|"support"| E

    %% Infrastructure & Documentation
    K ---|"pipeline_doc"| C
    L ---|"env_dependencies"| C

    %% Click Events
    click C "https://github.com/abekek/cse398_project/blob/main/src/main.py"
    click D1 "https://github.com/abekek/cse398_project/blob/main/src/CustomLandmarkDetection.py"
    click D2 "https://github.com/abekek/cse398_project/blob/main/src/FaceMeshMethod.py"
    click D3 "https://github.com/abekek/cse398_project/blob/main/src/NNMethod.py"
    click F "https://github.com/abekek/cse398_project/tree/main/src/models"
    click G "https://github.com/abekek/cse398_project/blob/main/src/onnx_convert.py"
    click H "https://github.com/abekek/cse398_project/blob/main/src/SelectionWindow.py"
    click I "https://github.com/abekek/cse398_project/tree/main/public/img"
    click J "https://github.com/abekek/cse398_project/tree/main/src/util"
    click K "https://github.com/abekek/cse398_project/blob/main/README.md"
    click L "https://github.com/abekek/cse398_project/blob/main/environment.yml"

    %% Styles
    classDef data fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef control fill:#F5CBA7,stroke:#9C640C,stroke-width:2px;
    classDef detection fill:#D5F5E3,stroke:#1D8348,stroke-width:2px;
    classDef inference fill:#FADBD8,stroke:#922B21,stroke-width:2px;
    classDef ui fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef util fill:#F0B27A,stroke:#7E5109,stroke-width:2px;
    classDef doc fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef env fill:#C39BD3,stroke:#512E5F,stroke-width:2px;
```
