# fritingo/yolo_on_browser architecture

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

## Overview

##### Main Components

a. Web Frontend:
- A set of HTML pages (e.g., index.html in root, pokedex/index.html, voc/index.html) that serve as the user interface.
- Styling provided by directories such as css and pokedex/src/styles.
- Dynamic behaviors and interactions via JavaScript files found in js, iottalk, pokedex/src/scripts, and voc/js.
- Integration of additional libraries (e.g., within the “iottalk” directory which contains csmapi.js, dai.js, dan.js, ida.js, and jquery.js) that may be used for real-time data handling or device communication.

b. YOLO Model Processing & Inference Backend:
- Python-based modules for YOLOv4 (found under the “yolov4” folder) and YOLOv4_tiny (under the “yolov4_tiny” folder) that handle tasks such as model conversion (to ONNX format) and web inference.
- Model files such as yolov4_tiny.onnx and animal.pth that indicate pre-trained model artifacts are part of the workflow.
- Scripts like to_onnx.py, inf_web.py, and web_yolo.py that orchestrate the conversion and inference pipelines.

c. Demo and Example Applications:
- The “pokedex” demonstration provides a themed example (likely showcasing object detection integrated with a familiar interface such as for Pokémon).
- The “voc” example appears to serve as another demo instance—perhaps tailored to a dataset or a specific object detection use-case.

##### Relationships and Interactions

- The Web Frontend interacts with the underlying YOLO inference logic either by integrating ONNX runtime/wrappers directly in the browser (if using JavaScript-based inference libraries) or by making asynchronous API calls to server-side Python endpoints (e.g., provided by scripts in yolov4 or yolov4_tiny).
- The JavaScript libraries (including those in iottalk) can be used to communicate real-time data (e.g., image frames from a webcam) to the inference modules.
- Different demo apps (pokedex and voc) serve as alternate frontends that utilize the underlying detection capabilities, demonstrating the model’s performance in different contexts.

##### Architectural Patterns and Design Principles

- Separation of concerns is evident: the client-side is exclusively handled by HTML/CSS/JS assets, while model processing and conversion are dealt with in Python.
- There is a modular design that supports multiple demonstration applications (each in its own directory) while reusing common assets (such as the iottalk and shared JavaScript libraries).
- The use of ONNX models suggests a design decision aimed at portability, allowing for potential client-side inference using ONNX Runtime on WebAssembly or by interfacing with a backend service.

##### Technologies, Frameworks, and Libraries

- Frontend: Standard web technologies (HTML, CSS, JavaScript, jQuery).
- Model Inference/Conversion: Python with specialized scripts (e.g., CSPDarknet53, upsampling utilities) and ONNX models.
- Optional IoT/Realtime Communication: The “iottalk” JavaScript components imply integration with external or IoT services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Index HTML Page"]:::frontend
        CSS["CSS Assets"]:::frontend
        JS["JS Assets"]:::frontend
        PD["Pokedex Demo"]:::demo
        VD["VOC Demo"]:::demo
    end

    %% Integration Library
    subgraph "Integration"
        IOT["iottalk Library"]:::integration
    end

    %% Model Processing & Inference
    subgraph "Model Processing & Inference"
        YOLO4["YOLOv4 Engine"]:::backend
        YOLOTiny["YOLOv4 Tiny Engine"]:::backend
        ONNXRoot["YOLOv4_tiny.onnx (Root)"]:::backend
        VOC_ONNX["VOC yolov4_tiny.onnx"]:::backend
        VOC_PTH["VOC voc.pth"]:::backend
    end

    %% Connections within Presentation Layer
    UI -->|"LoadAssets"| JS
    UI -->|"Navigate"| PD
    UI -->|"Navigate"| VD

    %% Integration with Frontend
    IOT -->|"RealtimeData"| JS

    %% Frontend to Inference Backend
    JS -->|"InferenceReq"| YOLO4
    JS -->|"InferenceReq"| YOLOTiny
    YOLO4 -->|"DetectionResult"| JS
    YOLOTiny -->|"DetectionResult"| JS

    %% Inference Modules to Model Artifacts
    YOLOTiny -->|"Uses"| ONNXRoot

    %% VOC Demo loads its dedicated model artifacts
    VD -->|"LoadModel"| VOC_ONNX
    VD -->|"LoadModel"| VOC_PTH

    %% Style Definitions
    classDef frontend fill:#CCF,stroke:#333,stroke-width:2px;
    classDef backend fill:#CFC,stroke:#333,stroke-width:2px;
    classDef integration fill:#FCF,stroke:#333,stroke-width:2px;
    classDef demo fill:#FF9,stroke:#333,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/fritingo/yolo_on_browser/blob/main/index.html"
    click CSS "https://github.com/fritingo/yolo_on_browser/tree/main/css/"
    click JS "https://github.com/fritingo/yolo_on_browser/tree/main/js/"
    click PD "https://github.com/fritingo/yolo_on_browser/tree/main/pokedex/"
    click VD "https://github.com/fritingo/yolo_on_browser/tree/main/voc/"
    click IOT "https://github.com/fritingo/yolo_on_browser/tree/main/iottalk/"
    click YOLO4 "https://github.com/fritingo/yolo_on_browser/tree/main/yolov4/"
    click YOLOTiny "https://github.com/fritingo/yolo_on_browser/tree/main/yolov4_tiny/"
    click ONNXRoot "https://github.com/fritingo/yolo_on_browser/blob/main/yolov4_tiny.onnx"
    click VOC_ONNX "https://github.com/fritingo/yolo_on_browser/blob/main/voc/yolov4_tiny.onnx"
    click VOC_PTH "https://github.com/fritingo/yolo_on_browser/blob/main/voc/voc.pth"
```
