# khiemnl00/scaledyolov4 architecture

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

## Overview

##### Project type and purpose
- This is a deep-learning object-detection codebase (Scaled-YOLOv4 large) implemented in PyTorch.
- Its purpose is to train, validate, test, and run inference on YOLOv4-P5/P6/P7 models using COCO-style datasets.

##### File structure
- Root scripts:
- train.py – orchestrates multi-GPU or single-GPU training
- test.py  – runs evaluation on validation/test datasets
- detect.py – runs inference on images or video
- data/ folder: dataset configuration files (coco.yaml, coco128.yaml) and hyperparameter YAMLs (hyp.finetune.yaml, hyp.scratch.yaml).
- models/ folder: model definitions and export utilities:
- yolo.py       – core model graph (backbone+head)
- common.py     – CSP and other building blocks
- experimental.py – experimental layers (attention, BoF)
- export.py     – model‐to‐ONNX/other
- *.yaml        – architecture spec files (yolov4-p5.yaml, p6, p7, etc.)
- utils/ folder: reusable helper modules: activations, datasets (DataLoader wrappers), general utilities (logging, IO), google_utils (download utilities), torch_utils (distributed training helpers).
- requirement.txt: Python library dependencies (PyTorch, CUDA toolkits, etc.).

##### README for additional insights
- Confirms three model scales (P5/P6/P7) and performance metrics.
- Instructions call out: Docker container setup, Mish-CUDA dummy installation, data mounting, GPU usage, and torchrun for distributed training.

##### Detail without over-splitting
- Don’t break down every single helper function; instead show “utils/activations”, “utils/datasets” grouped.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data & Config"
        DL["COCO Dataset (images+annotations)"]:::data
        DC["Dataset Configs\n(data/*.yaml)"]:::data
        HC["Hyperparameters\n(data/hyp.*.yaml)"]:::data
        MC["Model Specs\n(models/*.yaml)"]:::data
        CP["Model Weights\n(Checkpoint)"]:::data
    end

    subgraph "Data Loading & Augmentation"
        DLA["utils/datasets.py\n+ DataLoader"]:::util
    end

    subgraph "Model Definition"
        MD["models/yolo.py\n+ common.py\n+ experimental.py"]:::model
    end

    subgraph "Scripts"
        TR["train.py"]:::script
        TE["test.py"]:::script
        IN["detect.py"]:::script
    end

    EX["export.py\n(ONNX/TorchScript)"]:::model

    subgraph "Infrastructure"
        INF["Docker (nvidia-docker)\nGPU (CUDA/cuDNN)"]:::infra
        REQ["requirement.txt"]:::infra
    end

    %% Data and Config flows
    DL --> DLA
    DC --> DLA
    DC -.-> TR
    HC -.-> TR
    MC -.-> MD

    %% Training flows
    DLA --> TR
    MD --> TR
    TR -->|"forward/backward"| MD
    TR -->|"saves weights"| CP

    %% Inference & Evaluation flows
    CP --> TE
    CP --> IN
    MD --> TE
    MD --> IN

    %% Export flow
    MD --> EX

    %% Infrastructure dependencies
    INF -.-> TR
    INF -.-> TE
    INF -.-> IN
    REQ -.-> TR

    %% Click events
    click DL "https://github.com/khiemnl00/scaledyolov4/tree/yolov4-large/data/"
    click DC "https://github.com/khiemnl00/scaledyolov4/tree/yolov4-large/data/"
    click HC "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/data/hyp.finetune.yaml"
    click HC "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/data/hyp.scratch.yaml"
    click MC "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/yolov4-p5.yaml"
    click MC "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/yolov4-p6.yaml"
    click MC "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/yolov4-p7.yaml"
    click MC "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/yolov4-csp.yaml"
    click DLA "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/utils/datasets.py"
    click MD "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/yolo.py"
    click MD "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/common.py"
    click MD "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/experimental.py"
    click TR "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/train.py"
    click TE "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/test.py"
    click IN "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/detect.py"
    click EX "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/models/export.py"
    click REQ "https://github.com/khiemnl00/scaledyolov4/blob/yolov4-large/requirement.txt"

    %% Styles
    classDef data fill:#AEDFF7,stroke:#6FB4D8
    classDef util fill:#D5F5E3,stroke:#82C485
    classDef model fill:#D4EFDF,stroke:#73B16E
    classDef script fill:#FDE9D9,stroke:#F5B7B1
    classDef infra fill:#F2F3F4,stroke:#CACFD2
```
