# poeticoding/yolo_elixir architecture

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

- Interactive diagram: https://gitdiagram.com/poeticoding/yolo_elixir
- Repository: https://github.com/poeticoding/yolo_elixir

## Overview

##### Core Processing Pipeline
a. Preprocessing Stage
b. Model Inference Stage
c. Postprocessing Stage

##### Frame Scaling System
- EvisionScaler (OpenCV)
- ImageScaler
- NxIdentityScaler
- To the Preprocessing Stage

##### Model Implementation Layer
- Ultralytics Implementation
- YOLOv8 Specific Logic
- Connection to the core pipeline

##### External Dependencies & Integration
- ONNX Runtime (Ortex)
- Hardware Acceleration Options:
- CoreML (Mac)
- DirectML (Windows)
- CUDA/TensorRT (Linux)

##### Optional Components
- FastNMS Integration
- Standard NMS Implementation

**┌─────────────────────────────────────── YOLO System ───────────────────────────────────────┐**

- ┌─── Input Sources ───┐    ┌────── Core Pipeline ───────┐    ┌──── Output Format ────┐  │
- Image Files      │    │   1. Preprocessing         │    │  Detected Objects     │  │
- Webcam Stream    │───▶│   2. Model Inference       │───▶│  [{class, prob,      │  │
- Video Feed       │    │   3. Postprocessing        │    │    bbox, class_idx}] │  │
- ┘     └────────────────────────────┘    └────────────────────┘  │
- ▲                                              │

- ┌─── Frame Scalers ────┐    ┌─── Model Layer ────┐    ┌──── NMS Options ─────────┐  │
- EvisionScaler     │    │  - Ultralytics     │    │  - Standard NMS          │  │
- ImageScaler       │────│  - YOLOv8          │    │  - FastNMS (Rust NIF)    │  │
- NxIdentityScaler  │    └──────────────────┘    └────────────────────────┘  │
- ┘                                                              │

- ┌─── Hardware Acceleration ──┐    ┌─── External Dependencies ─┐                    │
- CoreML (Mac)           │    │  - ONNX Runtime           │                    │
- DirectML (Windows)     │    │  - Evision/OpenCV         │                    │
- CUDA/TensorRT (Linux)  │    │  - Nx                     │                    │
- ┘    └────────────────────────┘                    │

- ┘

- Use blue for core pipeline components
- Use green for input/output components
- Use orange for hardware acceleration
- Use purple for external dependencies
- Use yellow for optional components

Important Implementation Details to Note:

##### Performance optimization options

This design captures both the high-level architecture and the important implementation details while maintaining clarity about the system's primary purpose of real-time object detection.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        IF[Image Files]
        WS[Webcam Stream]
        VF[Video Feed]
    end

    subgraph CorePipeline
        direction TB
        PP[Preprocessing]:::core
        MI[Model Inference]:::core
        POP[Postprocessing]:::core
        PP --> MI --> POP
    end

    subgraph FrameScalers
        direction TB
        FS[Frame Scalers]:::scaler
        ES[EvisionScaler]:::scaler
        IS[ImageScaler]:::scaler
        NIS[NxIdentityScaler]:::scaler
        FS --> ES
        FS --> IS
        FS --> NIS
    end

    subgraph ModelLayer
        direction TB
        UL[Ultralytics]:::model
        Y8[YOLOv8]:::model
    end

    subgraph NMSOptions
        direction TB
        SNMS[Standard NMS]:::nms
        FNMS[FastNMS]:::nms
    end

    subgraph HardwareAccel
        direction TB
        CM[CoreML]:::hw
        DML[DirectML]:::hw
        CUDA[CUDA/TensorRT]:::hw
    end

    subgraph ExternalDeps
        direction TB
        ONNX[ONNX Runtime]:::ext
        EV[Evision/OpenCV]:::ext
        NX[Nx]:::ext
    end

    subgraph Output
        DO[Detected Objects]
    end

    IF --> PP
    WS --> PP
    VF --> PP

    FrameScalers --> PP
    ModelLayer --> MI
    NMSOptions --> POP
    HardwareAccel --> MI
    ExternalDeps --> CorePipeline
    POP --> DO

    %% Click Events
    click PP "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo.ex"
    click MI "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/model.ex"
    click FS "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/frame_scaler.ex"
    click ES "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/frame_scalers/evision_scaler.ex"
    click IS "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/frame_scalers/image_scaler.ex"
    click NIS "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/frame_scalers/nx_identity_scaler.ex"
    click UL "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/models/ultralytics.ex"
    click Y8 "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/models/yolo_v8.ex"
    click SNMS "https://github.com/poeticoding/yolo_elixir/blob/main/lib/yolo/nms.ex"
    click FNMS "https://github.com/poeticoding/yolo_elixir/blob/main/examples/yolo_fast_nms.livemd"

    %% Styling
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef scaler fill:#2ecc71,stroke:#27ae60,color:white
    classDef model fill:#9b59b6,stroke:#8e44ad,color:white
    classDef nms fill:#f1c40f,stroke:#f39c12,color:black
    classDef hw fill:#e67e22,stroke:#d35400,color:white
    classDef ext fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        C[Core Components]:::core
        S[Scalers]:::scaler
        M[Models]:::model
        N[NMS]:::nms
        H[Hardware]:::hw
        E[External]:::ext
    end
```
