# brian891203/gold-yolo architecture

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

- Interactive diagram: https://gitdiagram.com/brian891203/gold-yolo
- Repository: https://github.com/brian891203/gold-yolo

## Overview

##### Project type and purpose
- This is an open-source deep-learning framework centered on “Gold-YOLO,” an efficient object‐detector built on top of YOLOv6.
- It provides training, self-distillation, evaluation, quantization and multi-platform deployment (ONNX, OpenVINO, TensorRT) pipelines.

##### File structure
- Top-level directories:
- configs: hyperparameter and architecture configurations for each Gold-YOLO variant
- data: dataset definitions (COCO, VOC), image folders and YAML paths
- gold_yolo: custom network modules (layers, common utilities, reppan, transformer)
- yolov6: underlying YOLOv6 implementation (assigners, core engine, data loaders, model definitions, utils)
- tools: CLI scripts for training, evaluation, inference, partial quantization, QAT, PPQ
- deploy: export and inference code for ONNX, OpenVINO, TensorRT (with subfolders for C++ and Python examples)
- docs: usage tutorials, speed tests, quantization guides
- Auxiliary files: assets (benchmark images/plots), requirements.txt, LICENSE, README.md

##### Extract insights from README
- Describes training workflows: base model → self-distillation
- Specifies multi-GPU distributed training, DFL mode, syncBN, fuse_ab
- Lists evaluation and benchmarking steps on COCO
- Links to deployment notebooks and code for each target runtime

##### Main components and their relationships
a. Data Ingestion & Preparation
- Components: data/ coco.yaml, voc.yaml, data loaders in yolov6/data
- Flow: Raw images + labels → Data augmenters → Batch tensors to Training Engine
b. Model Definition
- Components: gold_yolo/* (gather-and-distribute modules), yolov6/models (efficientrep, yolo head), layers
- Flow: Config-driven model instantiation → Forward/backward passes
c. Training & Distillation Pipeline
- Components: tools/train.py, yolov6/core/engine.py, core/solver/build.py
- Flow: Distributed-launch → Engine coordinates data → Model → Loss → Optimizer → Checkpoint
- Self-distillation: teacher_model_path flag triggers dual-model flow
d. Evaluation & Inference
- Components: tools/eval.py, tools/infer.py, yolov6/core/evaler.py, core/inferer.py
- Flow: Load checkpoint → Run validation on val split → Compute mAP
e. Quantization & Compression
- Components: tools/partial_quantization, tools/qat, tools/quantization/ppq, /tensorrt
- Flow: Post-training quantization scripts → Sensitivity analysis → Calibrator → QAT-aware quantization
f. Export & Deployment
- Components: deploy/ONNX (export_onnx, eval_trt, notebooks), deploy/OpenVINO/export_openvino.py, deploy/TensorRT/onnx_to_trt.py
- Flow: Export PyTorch model → Convert to ONNX → (optional) TensorRT builder → C++/Python inference demos
g. External services and hardware
- COCO/VOC datasets, Google Drive links for pre-trained weights
- GPU runtimes (T4-TRT7, TRT8), CMake builds for C++ demos

##### Architectural patterns and design principles
- Layered architecture:
- Data layer → Model layer → Training layer → Deployment layer
- Config-driven components: all hyperparameters and paths are injected via configs/*.py
- Plugin-style deployment: export scripts target different runtimes without changing core model code
- Reusability and extensibility: partial quantization and QAT modules decoupled from training core

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        COCO((COCO Dataset)):::dataGreen
        VOC((VOC Dataset)):::dataGreen
        loader["Data Loader"]:::pythonBlue
        augment["Augmentation"]:::pythonBlue
        COCO --> loader
        VOC --> loader
        loader --> augment
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        common["common.py"]:::pythonBlue
        layers["layers.py"]:::pythonBlue
        reppan_mod["reppan.py"]:::pythonBlue
        transformer["transformer.py"]:::pythonBlue
        effirep["efficientrep.py"]:::pythonBlue
        effide["effidehead.py"]:::pythonBlue
        rep_yolo["reppan.py (yolov6)"]:::pythonBlue
        yolo_mod["yolo.py"]:::pythonBlue
        yolov6_layers["common.py (yolov6 layers)"]:::pythonBlue
    end

    %% Config Layer
    subgraph "Config Layer"
        direction TB
        cfg_s["gold_yolo-s.py"]:::pythonBlue
        cfg_m["gold_yolo-m.py"]:::pythonBlue
        cfg_l["gold_yolo-l.py"]:::pythonBlue
        cfg_n["gold_yolo-n.py"]:::pythonBlue
        cfg_exp["eval_640_repro.py"]:::pythonBlue
    end

    %% Training Layer
    subgraph "Training & Distillation"
        direction TB
        train["Train"]:::workflowOrange
        engine["engine.py"]:::pythonBlue
        solver["build.py"]:::pythonBlue
        checkpoint["Checkpoint"]:::workflowOrange
        distill["Distillation"]:::workflowOrange
    end

    %% Evaluation Layer
    subgraph "Evaluation & Inference"
        direction TB
        eval_node["Evaluation"]:::workflowOrange
        infer_node["Inference"]:::workflowOrange
        evaler["evaler.py"]:::pythonBlue
        inferer["inferer.py"]:::pythonBlue
    end

    %% Quantization Layer
    subgraph "Quantization & Compression"
        direction TB
        ptq["partial_quant.py"]:::pythonBlue
        ptq2["ptq.py"]:::pythonBlue
        sens["sensitivity_analyse.py"]:::pythonBlue
        qat_exp["qat_export.py"]:::pythonBlue
        onnx_util["onnx_utils.py"]:::pythonBlue
        ppq["ProgramEntrance.py"]:::pythonBlue
        cali["Calibrator.py"]:::pythonBlue
        trt_pt["onnx_to_tensorrt.py"]:::pythonBlue
        qat_aware["QAT_quantizer.py"]:::pythonBlue
    end

    %% Deployment Layer
    subgraph "Export & Deployment"
        direction TB
        onnx_export["export_onnx.py"]:::pythonBlue
        eval_trt["eval_trt.py"]:::pythonBlue
        openvino["export_openvino.py"]:::pythonBlue
        trt_convert["onnx_to_trt.py"]:::pythonBlue
        python_demo["Python Demo"]:::runtimePurple
        cpp_demo["C++ Demo"]:::runtimePurple
    end

    %% External
    subgraph "External Dependencies"
        direction TB
        PyReq["requirements.txt"]:::pythonBlue
        Assets["assets/"]:::pythonBlue
        README["README.md"]:::pythonBlue
        LICENSE["LICENSE"]:::pythonBlue
        GPU["GPU Hardware"]:::runtimePurple
    end

    %% Flow Connections
    augment --> common
    augment --> effirep
    common --> yolo_mod
    layers --> yolo_mod
    effirep --> yolo_mod
    effide --> yolo_mod
    rep_yolo --> yolo_mod
    yolov6_layers --> yolo_mod

    cfg_s -.-> common
    cfg_m -.-> common
    cfg_l -.-> common
    cfg_n -.-> common
    cfg_exp -.-> common

    yolo_mod --> train
    loader --> train
    train --> engine
    engine --> solver
    solver --> checkpoint
    train --> distill
    distill --> checkpoint

    checkpoint --> eval_node
    checkpoint --> infer_node
    eval_node --> evaler
    infer_node --> inferer

    yolo_mod --> ptq
    yolo_mod --> sens
    ptq --> cali
    onnx_export --> trt_pt
    onnx_export --> openvino
    ptq2 --> cali
    qat_exp --> onnx_util
    onnx_util --> ppq
    trt_pt --> ppq
    ppq --> qat_aware

    checkpoint --> onnx_export
    onnx_export --> python_demo
    onnx_export --> cpp_demo
    openvino --> python_demo
    trt_convert --> python_demo

    %% Click Events
    click loader "https://github.com/brian891203/gold-yolo/blob/master/yolov6/data/data_load.py"
    click augment "https://github.com/brian891203/gold-yolo/blob/master/yolov6/data/data_augment.py"
    click COCO "https://github.com/brian891203/gold-yolo/blob/master/data/coco.yaml"
    click VOC "https://github.com/brian891203/gold-yolo/blob/master/data/voc.yaml"
    click common "https://github.com/brian891203/gold-yolo/blob/master/gold_yolo/common.py"
    click layers "https://github.com/brian891203/gold-yolo/blob/master/gold_yolo/layers.py"
    click reppan_mod "https://github.com/brian891203/gold-yolo/blob/master/gold_yolo/reppan.py"
    click transformer "https://github.com/brian891203/gold-yolo/blob/master/gold_yolo/transformer.py"
    click effirep "https://github.com/brian891203/gold-yolo/blob/master/yolov6/models/efficientrep.py"
    click effide "https://github.com/brian891203/gold-yolo/blob/master/yolov6/models/effidehead.py"
    click rep_yolo "https://github.com/brian891203/gold-yolo/blob/master/yolov6/models/reppan.py"
    click yolo_mod "https://github.com/brian891203/gold-yolo/blob/master/yolov6/models/yolo.py"
    click yolov6_layers "https://github.com/brian891203/gold-yolo/blob/master/yolov6/layers/common.py"
    click cfg_s "https://github.com/brian891203/gold-yolo/blob/master/configs/gold_yolo-s.py"
    click cfg_m "https://github.com/brian891203/gold-yolo/blob/master/configs/gold_yolo-m.py"
    click cfg_l "https://github.com/brian891203/gold-yolo/blob/master/configs/gold_yolo-l.py"
    click cfg_n "https://github.com/brian891203/gold-yolo/blob/master/configs/gold_yolo-n.py"
    click cfg_exp "https://github.com/brian891203/gold-yolo/blob/master/configs/experiment/eval_640_repro.py"
    click train "https://github.com/brian891203/gold-yolo/blob/master/tools/train.py"
    click engine "https://github.com/brian891203/gold-yolo/blob/master/yolov6/core/engine.py"
    click solver "https://github.com/brian891203/gold-yolo/blob/master/yolov6/solver/build.py"
    click eval_node "https://github.com/brian891203/gold-yolo/blob/master/tools/eval.py"
    click infer_node "https://github.com/brian891203/gold-yolo/blob/master/tools/infer.py"
    click evaler "https://github.com/brian891203/gold-yolo/blob/master/yolov6/core/evaler.py"
    click inferer "https://github.com/brian891203/gold-yolo/blob/master/yolov6/core/inferer.py"
    click ptq "https://github.com/brian891203/gold-yolo/blob/master/tools/partial_quantization/partial_quant.py"
    click ptq2 "https://github.com/brian891203/gold-yolo/blob/master/tools/partial_quantization/ptq.py"
    click sens "https://github.com/brian891203/gold-yolo/blob/master/tools/partial_quantization/sensitivity_analyse.py"
    click qat_exp "https://github.com/brian891203/gold-yolo/blob/master/tools/qat/qat_export.py"
    click onnx_util "https://github.com/brian891203/gold-yolo/blob/master/tools/qat/onnx_utils.py"
    click ppq "https://github.com/brian891203/gold-yolo/blob/master/tools/quantization/ppq/ProgramEntrance.py"
    click cali "https://github.com/brian891203/gold-yolo/blob/master/tools/quantization/tensorrt/post_training/Calibrator.py"
    click trt_pt "https://github.com/brian891203/gold-yolo/blob/master/tools/quantization/tensorrt/post_training/onnx_to_tensorrt.py"
    click qat_aware "https://github.com/brian891203/gold-yolo/blob/master/tools/quantization/tensorrt/training_aware/QAT_quantizer.py"
    click onnx_export "https://github.com/brian891203/gold-yolo/blob/master/deploy/ONNX/export_onnx.py"
    click eval_trt "https://github.com/brian891203/gold-yolo/blob/master/deploy/ONNX/eval_trt.py"
    click openvino "https://github.com/brian891203/gold-yolo/blob/master/deploy/OpenVINO/export_openvino.py"
    click trt_convert "https://github.com/brian891203/gold-yolo/blob/master/deploy/TensorRT/onnx_to_trt.py"

    %% Styles
    classDef pythonBlue fill:#AED6F1,stroke:#21618C,color:#1B2631;
    classDef dataGreen fill:#ABEBC6,stroke:#145A32,color:#1B2631;
    classDef workflowOrange fill:#F9E79F,stroke:#B9770E,color:#1B2631;
    classDef runtimePurple fill:#D2B4DE,stroke:#6C3483,color:#1B2631;
```
