# jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui architecture

> Architecture diagram of the GitHub repository jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui
- Repository: https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui

## Overview

##### Project type and purpose
- This is a desktop GUI application (built with PyQt) for running ultralytics YOLO-based AI tasks (object detection, pose estimation, segmentation) and multi-object tracking (DeepSort, ByteTrack) on local files, camera feeds or RTSP streams.

##### File structure
- Top‐level files:
- main.py – entry point that launches the Qt application and wires up UI, video sources, AI workers
- download_weights.py – utility to fetch model weights into the weights/ folder
- environment.yml, requirements.txt – dependency definitions
- data/ – static assets (e.g. sample video, UI screenshot)
- weights/ – downloaded ONNX model files and class definitions
- src/ – core application code, subdivided into:
- data_type/ – frame buffering abstractions (VideoBuffer)
- models/ – AI inference modules, organized by functionality:
– base/yolo_base.py – common model loader and inference wrapper
– detection/… – YOLO‐ONNX detection classes
– pose/… – YOLO‐ONNX pose estimator
– segmentation/… – YOLO‐ONNX segmentation
– tracking/… – ByteTrack and DeepSort implementations with Kalman, matching, feature extractor, trackers
- qt/ – streaming and threading layers:
– stream/ai_worker.py – background worker that receives frames, runs inference, emits results
– stream/video_capture.py – captures frames from camera, file, RTSP
– video/video_worker.py – orchestrates reading video on worker thread
- tests/ – unit tests

##### README for additional insights
- Confirms supported AI tasks, model variants (YOLO11, YOLOv8 in ONNX), supported trackers and input sources
- Usage pattern: install dependencies → download weights → run main.py

##### Main components
a. User Interface (Qt GUI)
– MainWindow: menus/buttons for selecting tasks, input sources; display canvas
b. Input Source Manager
– VideoCaptureWorker: opens camera/file/RTSP, buffers frames
– VideoWorker: thread manager
c. AI Processing Layer
– AIWorker threads: receive frames → dispatch to selected pipeline
– Model Pipeline:
- Detection (YoloDetectorONNX)
- Pose (YoloPoseONNX)
- Segmentation (YoloSegONNX)
- Tracking (ByteTrack / DeepSort modules)
d. Data & Storage
– Weights directory with ONNX model files
– In‐memory VideoBuffer
e. Visualization & Output
– UI display canvas updates in real time
f. External Dependencies
– ONNX Runtime / PyTorch backend
– PyQt5
– System camera, file system, network (RTSP)

##### Relationships and interactions
- User→UI triggers “Open File/Camera/RTSP”
- UI requests VideoCaptureWorker to start
- Video frames flow → VideoWorker → VideoBuffer
- AIWorker pulls frames from VideoBuffer, runs inference via Model Pipeline
- Model Pipeline loads weights from weights/ when initialized
- Visualization module overlays results and emits Qt signals to update UI canvas

##### Architectural patterns & design principles
- MVC‐like separation:
- View: Qt UI definitions + visualization
- Controller: ai_worker, video_worker coordinating data flow
- Model: AI modules in src/models
- Producer–consumer queues for thread safety (VideoBuffer)
- Plug-in style model abstractions (base classes + ONNX implementations)
- Clear layering: UI ↔ streaming ↔ AI inference ↔ utils/visualization

##### Technologies, frameworks, libraries to annotate
- Python 3.x, PyQt5 (QtDesigner .ui files), ONNX Runtime
- ultralytics YOLO (exported to ONNX)
- ByteTrack, DeepSort algorithms in pure Python
- Conda or pip environment for dependencies

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Sources
    subgraph "External Sources"
        direction TB
        Camera[(Camera)]:::external
        FileSystem[(File System)]:::external
        Network[(RTSP Stream)]:::external
    end

    %% Entry Point
    Main["Application Entry Point\n(main.py)"]:::processing
    click Main "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/main.py"

    %% UI Layer
    subgraph "User Interface (Qt GUI)"
        direction TB
        MainWindow["MainWindow\n(src/ui/main_window.py)"]:::ui
        click MainWindow "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/ui/main_window.py"
        click MainWindow "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/ui/main_window.ui"
        Apprcc["Resource File\n(src/ui/apprcc_rc.py)"]:::ui
        click Apprcc "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/ui/apprcc_rc.py"
        Icons["Icon Resources\n(src/ui/icons/)"]:::ui
        click Icons "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/tree/main/src/ui/icons/"
    end

    %% Input Source Manager
    subgraph "Input Source Manager"
        direction TB
        VideoCapture["VideoCaptureWorker\n(src/qt/stream/video_capture.py)"]:::processing
        click VideoCapture "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/qt/stream/video_capture.py"
        VideoWorker["VideoWorker\n(src/qt/video/video_worker.py)"]:::processing
        click VideoWorker "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/qt/video/video_worker.py"
        VideoBuffer["VideoBuffer\n(src/data_type/video_buffer.py)"]:::data
        click VideoBuffer "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/data_type/video_buffer.py"
    end

    %% AI Processing Layer
    subgraph "AI Processing Layer"
        direction TB
        AIWorker["AIWorker Thread\n(src/qt/stream/ai_worker.py)"]:::processing
        click AIWorker "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/qt/stream/ai_worker.py"
        subgraph "Model Pipeline"
            direction TB
            BaseModel["YoloBase Loader\n(src/models/base/yolo_base.py)"]:::model
            click BaseModel "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/models/base/yolo_base.py"
            Detection["YoloDetectorONNX\n(src/models/detection/yolo_detector_onnx.py)"]:::model
            click Detection "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/models/detection/yolo_detector_onnx.py"
            Pose["YoloPoseONNX\n(src/models/pose/yolo_pose_onnx.py)"]:::model
            click Pose "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/models/pose/yolo_pose_onnx.py"
            Segmentation["YoloSegONNX\n(src/models/segmentation/yolo_seg_onnx.py)"]:::model
            click Segmentation "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/models/segmentation/yolo_seg_onnx.py"
            subgraph "Tracking"
                direction TB
                ByteTrack["ByteTrack\n(src/models/tracking/byte_track/byte_tracker.py)"]:::model
                click ByteTrack "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/models/tracking/byte_track/byte_tracker.py"
                DeepSort["DeepSort\n(src/models/tracking/deep_sort/deep_sort.py)"]:::model
                click DeepSort "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/models/tracking/deep_sort/deep_sort.py"
            end
        end
    end

    %% Visualization & Output
    subgraph "Visualization & Output"
        direction TB
        StreamVis["StreamVisualizer\n(src/qt/stream/visualize.py)"]:::processing
        click StreamVis "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/qt/stream/visualize.py"
        UtilsVis["Visualization Helpers\n(src/utils/visualize.py)"]:::processing
        click UtilsVis "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/utils/visualize.py"
    end

    %% Data & Storage
    subgraph "Data & Storage"
        direction TB
        Weights["Model Weights\n(weights/)"]:::data
        click Weights "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/tree/main/weights/"
        StaticData["Sample Video\n(data/dance.mp4)"]:::data
        click StaticData "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/data/dance.mp4"
    end

    %% Utilities
    subgraph "Utility Functions"
        direction TB
        Boxes["Box Math\n(src/utils/boxes.py)"]:::processing
        click Boxes "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/utils/boxes.py"
        General["General Utils\n(src/utils/general.py)"]:::processing
        click General "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/src/utils/general.py"
    end

    %% Dependencies
    Env["Dependencies\n(environment.yml\nrequirements.txt)"]:::external
    click Env "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/environment.yml"
    click Env "https://github.com/jingh-ai/ultralytics-yolo-deepsort-bytetrack-pyqt-gui/blob/main/requirements.txt"

    %% Connections
    Camera -->|provides frame| VideoCapture
    FileSystem -->|provides frame| VideoCapture
    Network -->|provides frame| VideoCapture
    Main -->|launches| MainWindow
    MainWindow -->|requests open source| VideoCapture
    VideoCapture -->|pushes frame| VideoBuffer
    VideoWorker -->|manages thread| VideoCapture
    VideoBuffer -->|pulls frame| AIWorker
    AIWorker -->|loads model| BaseModel
    BaseModel --> Detection
    BaseModel --> Pose
    BaseModel --> Segmentation
    BaseModel --> ByteTrack
    BaseModel --> DeepSort
    AIWorker -->|runs inference| Detection
    AIWorker -->|runs inference| Pose
    AIWorker -->|runs inference| Segmentation
    AIWorker -->|runs tracking| ByteTrack
    AIWorker -->|runs tracking| DeepSort
    Detection -->|outputs results| StreamVis
    Pose -->|outputs results| StreamVis
    Segmentation -->|outputs results| StreamVis
    ByteTrack -->|outputs results| StreamVis
    DeepSort -->|outputs results| StreamVis
    StreamVis -->|overlays| MainWindow
    Weights -->|loaded by| BaseModel
    Boxes -->|used by| StreamVis
    General -->|used by| StreamVis

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,color:#000;
    classDef processing fill:#90EE90,stroke:#000,color:#000;
    classDef model fill:#FFFF99,stroke:#000,color:#000;
    classDef data fill:#FFA500,stroke:#000,color:#000;
    classDef external fill:#D3D3D3,stroke:#000,color:#000;
```
