# detective319/pytorch-yolov4 architecture

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

- Interactive diagram: https://gitdiagram.com/detective319/pytorch-yolov4
- Repository: https://github.com/detective319/pytorch-yolov4

## Overview

##### Project type and purpose
- This is an open-source tool/library for object detection: “A minimal PyTorch implementation of YOLOv4” with end-to-end support for training, inference, format conversion (PyTorch→ONNX→TensorRT→TensorFlow), and DeepStream integration.
- Core use cases:
- Train custom YOLOv4 models on datasets (COCO, VOC, user data)
- Run inference with Darknet, PyTorch, ONNX, TensorRT, or DeepStream pipelines
- Convert between model formats via supplied scripts/tools

##### File structure
- Top-level directories and entry points:
- cfg/      – Darknet-style .cfg files for model architectures
- data/     – Class name lists (coco.names, voc.names)
- tool/     – Conversion and utility modules (darknet2pytorch.py, onnx2tensorflow.py, utils, yolo_layer, iou tests)
- DeepStream/ – NVIDIA DeepStream plugin source & configs
- Key scripts:
- train.py, dataset.py, models.py – training pipeline
- demo*.py – inference and conversion demos
- evaluate_on_coco.py – evaluation
- Third-party/build artifacts:
- DeepStream Makefile and plugin C++/CUDA code
- trtexec calls in README for TensorRT engine builds

##### README for additional insights
- Describes supported workflows:
- Training (with Mosaic augmentation)
- Inference modes (Darknet, PyTorch, ONNX, TensorRT, DeepStream)
- Conversion scripts and their recommended PyTorch/ONNX/TensorRT versions
- Highlights external dependencies: Darknet weights, PyTorch, ONNX Runtime, TensorRT, DeepStream SDK

##### Elements
- Labels:
- Data Preparation
- PyTorch Training
- Inference Engines (Darknet, PyTorch, ONNX, TensorRT, DeepStream)
- Conversion Pipelines
- DeepStream Plugin
- Evaluation
- Annotations:
- Version or dependency notes (PyTorch 1.4+, TensorRT 7.x, DeepStream SDK)

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Data Source
    Raw["Raw Images & Annotations"]:::external

    %% Data Preparation
    subgraph "Data Preparation"
        DP1["dataset.py"]:::python
        DP2["tool/coco_annotation.py"]:::python
    end

    %% Outputs
    DPOut["Train/Val Lists"]:::artifact

    %% Training
    subgraph "Model Definition & Training"
        M1["models.py"]:::python
        T1["train.py"]:::python
        C1["cfg.py"]:::python
        C2["cfg/*.cfg"]:::external
    end

    ModelChk["yolov4.pth"]:::artifact

    %% Conversion Pipelines
    subgraph "Conversion Pipelines"
        D2P["tool/darknet2pytorch.py"]:::python
        P2O["demo_pytorch2onnx.py"]:::python
        D2O["demo_darknet2onnx.py"]:::python
        O2T["tool/onnx2tensorflow.py"]:::python
        TRTE["README.md"]:::external
    end

    ONNX["model.onnx"]:::artifact
    TRT["model.engine"]:::artifact
    TF["model.pb"]:::artifact

    %% Inference Engines
    subgraph "Inference Engines"
        DI["demo.py\n(Darknet)"]:::python
        PI["models.py\n(PyTorch)"]:::python
        OI["ONNX Runtime"]:::external
        TI["demo_trt.py\n(TensorRT)"]:::python
        DSApp["DeepStream App"]:::external
    end

    %% DeepStream Plugin
    subgraph "DeepStream Plugin"
        DSP["nvdsinfer_custom_impl_Yolo"]:::cpp
    end

    %% Evaluation
    subgraph "Evaluation"
        EV["evaluate_on_coco.py"]:::python
        TV["tool/tv_reference/"]:::python
    end

    %% Flows Data Preparation -> Training
    Raw --> DP1
    DP1 --> DP2
    DP2 --> DPOut

    %% Flows Training
    DPOut --> T1
    C1 --> T1
    C2 -.-> T1
    M1 --> T1
    T1 --> ModelChk

    %% Conversion Flows
    ModelChk --> P2O --> ONNX
    ModelChk --> D2O --> ONNX
    ONNX --> TRTE --> TRT
    ONNX --> O2T --> TF

    %% Inference Flows
    ModelChk --> DI
    ModelChk --> PI
    ONNX --> OI
    TRT --> TI
    TRT --> DSApp
    DSP --> DSApp

    %% Evaluation Flows
    DI --> EV
    PI --> EV
    OI --> EV
    TI --> EV
    DSApp --> EV
    TV --> EV

    %% Click Events
    click DP1 "https://github.com/detective319/pytorch-yolov4/blob/master/dataset.py"
    click DP2 "https://github.com/detective319/pytorch-yolov4/blob/master/tool/coco_annotation.py"
    click M1 "https://github.com/detective319/pytorch-yolov4/blob/master/models.py"
    click T1 "https://github.com/detective319/pytorch-yolov4/blob/master/train.py"
    click C1 "https://github.com/detective319/pytorch-yolov4/blob/master/cfg.py"
    click C2 "https://github.com/detective319/pytorch-yolov4/tree/master/cfg/"
    click D2P "https://github.com/detective319/pytorch-yolov4/blob/master/tool/darknet2pytorch.py"
    click P2O "https://github.com/detective319/pytorch-yolov4/blob/master/demo_pytorch2onnx.py"
    click D2O "https://github.com/detective319/pytorch-yolov4/blob/master/demo_darknet2onnx.py"
    click O2T "https://github.com/detective319/pytorch-yolov4/blob/master/tool/onnx2tensorflow.py"
    click TRTE "https://github.com/detective319/pytorch-yolov4/blob/master/README.md"
    click DI "https://github.com/detective319/pytorch-yolov4/blob/master/demo.py"
    click PI "https://github.com/detective319/pytorch-yolov4/blob/master/models.py"
    click TI "https://github.com/detective319/pytorch-yolov4/blob/master/demo_trt.py"
    click DSApp "https://github.com/detective319/pytorch-yolov4/blob/master/DeepStream/deepstream_app_config_yoloV4.txt"
    click DSP "https://github.com/detective319/pytorch-yolov4/tree/master/DeepStream/nvdsinfer_custom_impl_Yolo"
    click EV "https://github.com/detective319/pytorch-yolov4/blob/master/evaluate_on_coco.py"
    click TV "https://github.com/detective319/pytorch-yolov4/tree/master/tool/tv_reference/"

    %% Styles
    classDef python fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef cpp fill:#ffe0b2,stroke:#fb8c00,color:#e65100
    classDef external fill:#eeeeee,stroke:#9e9e9e,color:#424242
    classDef artifact fill:#c8e6c9,stroke:#43a047,color:#1b5e20
```
