# thu-mig/yolo-uniow architecture

> Architecture diagram of the GitHub repository thu-mig/yolo-uniow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thu-mig/yolo-uniow
- Repository: https://github.com/thu-mig/yolo-uniow

## Overview

##### Project type and purpose
- This is an open-source research and training framework for open-world object detection (OWOD) built in Python.
- It builds on a third-party MMYOLO library (under `third_party/mmyolo`) and provides:
- Config-driven training for OWOD and standard object detection tasks
- Data loaders and transforms for OWOD datasets
- Custom model definitions (backbones, necks, heads) under `yolo_world/models`
- A training engine with hooks and optimizers under `yolo_world/engine`
- Evaluation metrics, demo scripts, and export tools

##### High-level architectural components
A. Data Layer
- Raw OWOD data (`data/OWOD/...`) and JSON metadata (`data/texts/…`)
- Dataset definitions and transforms in `yolo_world/datasets`
B. Configuration Layer
- Training/evaluation configs under `configs/` (pretrain, OWOD fine-tune)
- A registry/factory that instantiates datasets, models, engines based on config
C. Core Framework
1. Model Modules (`yolo_world/models`)
– Backbones, Necks (PAFPN), Dense Heads
– Detectors that glue backbone–neck–heads
2. Engine (`yolo_world/engine`)
– Training loop, hooks (e.g., learning-rate scheduling), optimizer constructors
3. Metrics (`yolo_world/metrics`)
– OWOD-specific evaluation
4. Registry (`yolo_world/…/registry.py`)
– Central plugin registry for datasets, models, hooks, etc.
D. Third-Party Library
- MMYOLO under `third_party/mmyolo/` provides low-level model definitions, deployment code, tools, demos, docs, and tests
E. Orchestration & Scripts
- Entry-point shell scripts (`run_owod.sh`, `run_ovod.sh`)
- Python CLI/train scripts under `tools/` and `demo/` (e.g., `tools/train_owod.py`, `demo/image_demo.py`)
F. Deployment & Demo
- ONNX export, DeepStream integration under `third_party/mmyolo/projects/easydeploy/`
- Interactive demos (Gradio, video/image demos)

##### Relationships and data flow
- Data flows from raw files → `yolo_world/datasets` → DataLoader →
Configures model via registry →
Engine consumes model + data →
Checkpoints + metrics →
Export (ONNX) →
Deployment/Demo
- Scripts orchestrate end-to-end: parse config → build components → train/evaluate → export/demo

##### Architectural patterns & design principles
- Config-driven, plugin-based instantiation (registry/factory pattern)
- Hook-based training engine (observer pattern)
- Separation of concerns:
- Data processing vs. model definition vs. training logic vs. deployment
- Third-party integration via submodule (`third_party/mmyolo`)

##### Detailed capture
- Sub-components: e.g., inside “Model Architecture” show Backbone → Neck → Head
- Inside “Engine” show hooks (LR scheduler, deploy hook) and optimizer constructors
- In “Deployment” highlight ONNX export and DeepStream integration

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RawData["Raw OWOD Data"]:::data
        MetaData["JSON Metadata"]:::data
        Datasets["Dataset Definitions & Transforms"]:::data
    end

    %% Configuration Layer
    subgraph "Configuration Layer"
        direction TB
        Configs["Configs"]:::core
        DatasetFactory["Dataset Factory & Registry"]:::core
    end

    %% Core Framework
    subgraph "Core Framework"
        direction TB

        subgraph "Model Modules"
            direction TB
            Backbones["Backbones"]:::core
            Necks["Necks (PAFPN)"]:::core
            Heads["Dense Heads"]:::core
            Detectors["Detectors"]:::core
        end

        subgraph "Engine & Training"
            direction TB
            Engine["Training Engine & Hooks"]:::core
            Optimizer["Optimizer Constructors"]:::core
        end

        Metrics["Evaluation Metrics"]:::core
        Registry["Central Registry"]:::core
    end

    %% Third-Party Library
    subgraph "Third-Party (MMYOLO)"
        direction TB
        MMYOLO["MMYOLO Library"]:::third
    end

    %% Orchestration & Scripts
    subgraph "Orchestration & Scripts"
        direction TB
        ShellScripts["run_owod.sh / run_ovod.sh"]:::script
        TrainTools["Training Scripts (tools/)"]:::script
        DemoTools["Demo Scripts (demo/)"]:::script
    end

    %% Deployment & Demo
    subgraph "Deployment & Demo"
        direction TB
        ExportONNX["ONNX Export"]:::core
        DeepStream["DeepStream Integration"]:::third
        GradioDemo["Gradio Interactive Demo"]:::script
    end

    %% Data flow
    RawData --> Datasets
    MetaData --> Datasets
    Datasets --> Engine
    Configs --> DatasetFactory
    DatasetFactory --> Registry
    Registry --> Backbones
    Registry --> Necks
    Registry --> Heads
    Registry --> Detectors
    MMYOLO --> Backbones
    MMYOLO --> Necks
    MMYOLO --> Heads
    MMYOLO --> Detectors
    Backbones --> Detectors
    Necks --> Detectors
    Heads --> Detectors
    Detectors --> Engine
    Engine --> Optimizer
    Engine --> Metrics
    Metrics --> ExportONNX
    ExportONNX --> DeepStream
    ExportONNX --> GradioDemo

    ShellScripts -->|invoke| DatasetFactory
    TrainTools -->|invoke| Engine
    DemoTools -->|invoke| GradioDemo

    %% Click Events
    click RawData "https://github.com/thu-mig/yolo-uniow/tree/main/data/OWOD/"
    click MetaData "https://github.com/thu-mig/yolo-uniow/tree/main/data/texts/"
    click Datasets "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/datasets/mm_dataset.py"
    click Datasets "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/datasets/owodb.py"
    click Datasets "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/datasets/owodb_const.py"
    click Datasets "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/datasets/transformers/mm_transforms.py"
    click Datasets "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/datasets/transformers/mm_mix_img_transforms.py"
    click Datasets "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/datasets/utils.py"
    click Configs "https://github.com/thu-mig/yolo-uniow/tree/main/configs/"
    click DatasetFactory "https://github.com/thu-mig/yolo-uniow/blob/main/configs/datasets/owod_dataset.py"
    click Backbones "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/backbones/mm_backbone.py"
    click Necks "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/necks/yolo_world_pafpn.py"
    click Heads "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/dense_heads/yolo_world_head.py"
    click Heads "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/dense_heads/yolo_world_seg_head.py"
    click Heads "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/dense_heads/yolov10_world_head.py"
    click Detectors "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/detectors/yolo_world.py"
    click Detectors "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/detectors/yolo_world_image.py"
    click Detectors "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/models/detectors/yolo_world_owod.py"
    click Engine "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/engine/__init__.py"
    click Optimizer "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/engine/optimizers/yolow_v5_optim_constructor.py"
    click Metrics "https://github.com/thu-mig/yolo-uniow/blob/main/yolo_world/metrics/ow_metric.py"
    click MMYOLO "https://github.com/thu-mig/yolo-uniow/tree/main/third_party/mmyolo/"
    click ShellScripts "https://github.com/thu-mig/yolo-uniow/blob/main/run_owod.sh"
    click ShellScripts "https://github.com/thu-mig/yolo-uniow/blob/main/run_ovod.sh"
    click TrainTools "https://github.com/thu-mig/yolo-uniow/blob/main/tools/train_owod.py"
    click TrainTools "https://github.com/thu-mig/yolo-uniow/blob/main/tools/train.py"
    click TrainTools "https://github.com/thu-mig/yolo-uniow/blob/main/tools/dist_train_owod.sh"
    click DemoTools "https://github.com/thu-mig/yolo-uniow/blob/main/demo/image_demo.py"
    click DemoTools "https://github.com/thu-mig/yolo-uniow/blob/main/demo/video_demo.py"
    click DemoTools "https://github.com/thu-mig/yolo-uniow/blob/main/demo/gradio_demo.py"
    click DemoTools "https://github.com/thu-mig/yolo-uniow/blob/main/demo/simple_demo.py"
    click ExportONNX "https://github.com/thu-mig/yolo-uniow/blob/main/third_party/mmyolo/projects/easydeploy/tools/export_onnx.py"
    click DeepStream "https://github.com/thu-mig/yolo-uniow/tree/main/third_party/mmyolo/projects/easydeploy/deepstream/"
    click GradioDemo "https://github.com/thu-mig/yolo-uniow/blob/main/demo/gradio_demo.py"

    %% Styles
    classDef data fill:#e0f7fa,stroke:#006064,color:#006064
    classDef core fill:#e3f2fd,stroke:#0d47a1,color:#0d47a1
    classDef third fill:#f5f5f5,stroke:#757575,color:#424242
    classDef script fill:#fff3e0,stroke:#e65100,color:#e65100
```
