# ahmednull/l2cs-net architecture

> Architecture diagram of the GitHub repository ahmednull/l2cs-net, 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/ahmednull/l2cs-net
- Repository: https://github.com/ahmednull/l2cs-net

## Overview

##### Main Components
- Data Sources and Storage:
- Datasets: The “datasets” directory holds different datasets (e.g., MPIIFaceGaze and Gaze360) along with instructions for their preparation.
- Pre-trained Models: The “models” directory serves as the storage for the pre-trained model files (e.g., L2CSNet_gaze360.pkl).
- Core Library – l2cs Package:
- Core Modules: The “l2cs” directory contains modules that define various aspects of the system:
▪ datasets.py: Handles data loading and preprocessing tailored for gaze estimation.
▪ model.py: Defines the neural network architecture (using PyTorch), responsible for gaze prediction.
▪ pipeline.py: Orchestrates the inference pipeline by coordinating face detection, model prediction, and further processing.
▪ results.py: Manages the output from predictions, likely compiling results from model inferences.
▪ utils.py: Contains miscellaneous helper functions which might assist in data handling, metric computation, etc.
▪ vis.py: Provides functionality for visualizing the gaze tracking results, such as overlaying predictions on video frames.
- Execution and Evaluation Scripts:
- train.py: Script to initiate model training on supplied datasets with configurable hyperparameters.
- test.py: Script to run evaluations on pretrained snapshots.
- leave_one_out_eval.py: Implements leave-one-person-out evaluation, specifically for the MPIIGaze dataset.
- demo.py: A standalone demo to capture webcam input, process the frame through the Pipeline (from l2cs), and showcase gaze estimation in real time.
- External Dependencies:
- PyTorch: The backbone framework for model implementation and training.
- OpenCV (cv2): Used for video capture and image processing (notably in the demo).

##### Depicting Relationships and Interactions
- Data Flow:
- Data from “datasets” is fed into the modules in the l2cs package, particularly via datasets.py.
- The pipeline (in pipeline.py) takes processed input data to run it through the model (model.py) and then passes results to the visualization module (vis.py) if necessary.
- Training, testing, and evaluation scripts orchestrate these interactions, using the core modules to perform specific tasks. For example, train.py and test.py use model.py for forward passes and datasets.py for batch fetching.
- Control Flow:
- Inference Flow: demo.py and Pipeline illustrate real-time processing from webcam capture → preprocessing → model inference → rendering results.
- Evaluation Flow: Scripts such as leave_one_out_eval.py demonstrate how evaluation metrics are computed from model outputs, which are stored within designated directories (output, evaluation).
- External Interactions:
- The project integrates with external libraries (PyTorch for deep learning, OpenCV for computer vision) and encourages community contributions as seen in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources & Storage
    subgraph "Data Sources & Storage"
        DS1["Datasets"] 
        DS2["Datasets README"]
        DS3["Pre-trained Models"]
        DS4["Models README"]
    end

    %% l2cs Library Components
    subgraph "l2cs Library"
        DLD["Data Loading & Preprocessing (datasets.py)"]
        NM["Neural Network Model (model.py)"]
        IP["Inference Pipeline (pipeline.py)"]
        RC["Results Compilation (results.py)"]
        UF["Utility Functions (utils.py)"]
        VIS["Visualization Module (vis.py)"]
    end

    %% Execution Scripts
    subgraph "Execution Scripts"
        TS["Training Script (train.py)"]
        TES["Testing Script (test.py)"]
        LOO["Leave-One-Out Eval Script (leave_one_out_eval.py)"]
        DEMO["Demo Script (demo.py)"]
    end

    %% External Libraries
    subgraph "External Libraries"
        PT["PyTorch"]
        OC["OpenCV"]
    end

    %% Connections - Data Flow
    DS1 -->|"load&preprocess"| DLD
    DS3 -->|"loadmodel"| NM
    DLD -->|"feeddata"| IP
    IP -->|"inference"| NM
    IP -->|"collectresults"| RC
    IP -->|"visualizeresults"| VIS

    %% Connections - Scripts and their operations
    TS -->|"fetchbatches"| DLD
    TS -->|"training"| NM
    TES -->|"fetchbatches"| DLD
    TES -->|"evaluate"| NM
    LOO -->|"computemetrics"| RC
    DEMO -->|"realtimeinput"| IP
    DEMO -->|"displayresults"| VIS

    %% Connections - External Libraries
    PT -->|"deeplearning"| NM
    PT -->|"compute"| IP
    OC -->|"capturevideo"| DEMO
    OC -->|"imageprocessing"| VIS

    %% Click Events for Data Sources & Storage
    click DS1 "https://github.com/ahmednull/l2cs-net/tree/main/datasets/"
    click DS2 "https://github.com/ahmednull/l2cs-net/blob/main/datasets/README.md"
    click DS3 "https://github.com/ahmednull/l2cs-net/tree/main/models/"
    click DS4 "https://github.com/ahmednull/l2cs-net/blob/main/models/README.md"

    %% Click Events for l2cs Library
    click DLD "https://github.com/ahmednull/l2cs-net/blob/main/l2cs/datasets.py"
    click NM "https://github.com/ahmednull/l2cs-net/blob/main/l2cs/model.py"
    click IP "https://github.com/ahmednull/l2cs-net/blob/main/l2cs/pipeline.py"
    click RC "https://github.com/ahmednull/l2cs-net/blob/main/l2cs/results.py"
    click UF "https://github.com/ahmednull/l2cs-net/blob/main/l2cs/utils.py"
    click VIS "https://github.com/ahmednull/l2cs-net/blob/main/l2cs/vis.py"

    %% Click Events for Execution Scripts
    click TS "https://github.com/ahmednull/l2cs-net/blob/main/train.py"
    click TES "https://github.com/ahmednull/l2cs-net/blob/main/test.py"
    click LOO "https://github.com/ahmednull/l2cs-net/blob/main/leave_one_out_eval.py"
    click DEMO "https://github.com/ahmednull/l2cs-net/blob/main/demo.py"

    %% Styling: Classes for color coding
    classDef datasource fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef core fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef script fill:#ffa500,stroke:#333,stroke-width:2px;
    classDef external fill:#dda0dd,stroke:#333,stroke-width:2px;

    class DS1,DS2,DS3,DS4 datasource;
    class DLD,NM,IP,RC,UF,VIS core;
    class TS,TES,LOO,DEMO script;
    class PT,OC external;
```
