# zhanggang001/hednet architecture

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

- Interactive diagram: https://gitdiagram.com/zhanggang001/hednet
- Repository: https://github.com/zhanggang001/hednet

## Overview

##### Project Type & Purpose
- This is an open-source, research-grade 3D object-detection codebase (HEDNet & SAFDNet) built atop OpenPCDet.
- It provides end-to-end pipelines for loading point-cloud datasets (Waymo, KITTI, Lyft, etc.), preprocessing (voxelization, augmentation), sparse-convolutional model training (hierarchical encoder-decoder, fully sparse), evaluation, and submission.

##### High-Level Components
a. Data Layer
- “data/…” directories for raw dataset splits and ImageSets
- pcdet/datasets package: dataset interfaces, augmentors, samplers, custom dataset support
b. Preprocessing & Feature Engineering
- Voxelization, point-feature encoders (VFE) in pcdet/models/backbones_3d/vfe and pcdet/datasets/processor
- 2D BEV mapping modules in pcdet/models/backbones_2d
c. Model Core
- Backbones (2D & 3D), attention modules, sparse conv in pcdet/models/backbones_*
- Dense heads (anchor, center, transfusion) in pcdet/models/dense_heads
- ROI heads (PartA2, PointRCNN, PV-RCNN) in pcdet/models/roi_heads
- Detector wrappers (HEDNet, SAFDNet, CenterPoint, etc.) in pcdet/models/detectors
d. Low-Level Ops
- Custom C++/CUDA operators under pcdet/ops (bev_pool, iou3d_nms, pointnet2, roipoint_pool3d, etc.)
e. Training & Evaluation Engine
- tools/train.py, tools/test.py orchestrate distributed training/testing
- tools/scripts for Slurm, torch.distributed launch
- tools/eval_utils for metric computation and submission creation
f. Configuration & Orchestration
- YAML configs in tools/cfgs drive dataset, model, optimizer, scheduler settings
- pcdet/config.py reads and merges configs at runtime
g. Deployment & Reproducibility
- Dockerfile in docker/ for uniform environment (PyTorch, CUDA, spconv)
- requirements.txt, setup.py for pip installable package
- docs/ for install, dataset tutorial, getting started

##### Component Relationships & Data-Flow
- Data (raw point clouds) → Dataset loader (pcdet/datasets) → Augmentor & Sampler → DataProcessor (voxelization, VFE)
→ Model Backbone → Detection Heads → Loss & Post-processing → Checkpoint & Metrics
- Config files feed into both Data loader and Model builder
- Training scripts (tools/train.py) dispatch jobs to GPUs, link with custom ops and return checkpoints
- Evaluation scripts load checkpoints, run inference on test splits, compute metrics via eval_utils

##### Architectural Patterns & Principles
- Modular plugin design: adding new dataset or detector only requires implementing a subclass in the appropriate package
- Config-driven: decouples code from hyperparameters, fosters reproducibility
- Separation of concerns: data ingestion, preprocessing, model definition, and training loops are cleanly separated
- High-performance: custom CUDA kernels for bottleneck ops, distributed data parallel training

b. Next, Preprocessing block (pcdet/datasets/processor, VFE modules).
c. Center: Model Core subdivided into Backbone, Heads, Detectors.
d. Underneath Model Core: Custom ops layer (pcdet/ops) feeding into Backbone/Heads.
f. At the top or bottom: Config manager (tools/cfgs + pcdet/config.py) feeding into Data Layer and Model Core.
g. External services off to one side: Docker, Slurm, Output storage (checkpoints, submission files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        DataRaw["Raw Point Clouds\ndata/kitti, lyft, once"]:::dataSink
        DatasetPkg["pcdet/datasets/"]:::pythonModule
    end

    %% Preprocessing & Feature Engineering
    subgraph "Preprocessing & Feature Engineering"
        DataProcessor["data_processor.py"]:::pythonModule
        PFE["point_feature_encoder.py"]:::pythonModule
        VFEpkg["pcdet/models/backbones_3d/vfe/"]:::pythonModule
        BEV2D["pcdet/models/backbones_2d/"]:::pythonModule
    end

    %% Model Core
    subgraph "Model Core"
        subgraph "3D Backbones"
            Back3D["pcdet/models/backbones_3d/"]:::pythonModule
        end
        subgraph "2D Backbones & Fusion"
            Back2D["pcdet/models/backbones_2d/"]:::pythonModule
        end
        DenseHeads["pcdet/models/dense_heads/"]:::pythonModule
        ROIHeads["pcdet/models/roi_heads/"]:::pythonModule
        Detectors["pcdet/models/detectors/"]:::pythonModule
    end

    %% Low-Level Ops
    subgraph "Low-Level Ops"
        Ops["pcdet/ops/"]:::pythonModule
    end

    %% Training & Evaluation Engine
    subgraph "Training & Evaluation Engine"
        Train["tools/train.py"]:::pythonModule
        Test["tools/test.py"]:::pythonModule
        ScriptsTrain["tools/scripts/"]:::pythonModule
        ScriptsTest["tools/scripts/"]:::pythonModule
        EvalUtils["tools/eval_utils/"]:::pythonModule
    end

    %% Configuration & Orchestration
    subgraph "Configuration & Orchestration"
        CFGs["tools/cfgs/"]:::pythonModule
        ConfigPy["pcdet/config.py"]:::pythonModule
    end

    %% Deployment & Reproducibility
    subgraph "Deployment & Reproducibility"
        Docker["Docker"]:::external
        Packaging["requirements.txt\nsetup.py"]:::pythonModule
        Docs["docs/"]:::pythonModule
    end

    %% Persistent Storage
    Checkpoints["Checkpoints"]:::storage
    Submission["Submission Files"]:::dataSink

    %% Data & Control Flows
    DataRaw -->|"load"| DatasetPkg
    CFGs -.->|"config"| DatasetPkg
    DatasetPkg -->|"augment & sample"| DataProcessor
    DataProcessor -->|"voxelize"| VFEpkg
    VFEpkg -->|"features"| Back3D
    DatasetPkg -->|"2D BEV data"| BEV2D
    BEV2D -->|"features"| Back2D

    %% Model assembly
    Back3D -->|"sparse conv"| DenseHeads
    Back3D -->|"sparse conv"| ROIHeads
    Back2D -->|"fusion"| DenseHeads
    DenseHeads --> Detectors
    ROIHeads --> Detectors

    %% Custom ops integration
    Ops --> Back3D
    Ops --> DenseHeads
    Ops --> ROIHeads

    %% Training & Evaluation
    ConfigPy -.->|"config"| Detectors
    Train -->|"train model"| Detectors
    Train --> Checkpoints
    Test --> Detectors
    Test --> Submission
    Test --> EvalUtils

    ScriptsTrain --> Train
    ScriptsTest --> Test
    Slurm["Slurm"]:::external
    Docker -->|"env"| Train

    %% Click Events
    click DataRaw "https://github.com/zhanggang001/hednet/tree/main/data/kitti"
    click DatasetPkg "https://github.com/zhanggang001/hednet/tree/main/pcdet/datasets/"
    click DataProcessor "https://github.com/zhanggang001/hednet/blob/main/pcdet/datasets/processor/data_processor.py"
    click PFE "https://github.com/zhanggang001/hednet/blob/main/pcdet/datasets/processor/point_feature_encoder.py"
    click VFEpkg "https://github.com/zhanggang001/hednet/tree/main/pcdet/models/backbones_3d/vfe/"
    click BEV2D "https://github.com/zhanggang001/hednet/tree/main/pcdet/models/backbones_2d/"
    click Back3D "https://github.com/zhanggang001/hednet/tree/main/pcdet/models/backbones_3d/"
    click Back2D "https://github.com/zhanggang001/hednet/tree/main/pcdet/models/backbones_2d/"
    click DenseHeads "https://github.com/zhanggang001/hednet/tree/main/pcdet/models/dense_heads/"
    click ROIHeads "https://github.com/zhanggang001/hednet/tree/main/pcdet/models/roi_heads/"
    click Detectors "https://github.com/zhanggang001/hednet/tree/main/pcdet/models/detectors/"
    click Ops "https://github.com/zhanggang001/hednet/tree/main/pcdet/ops/"
    click Train "https://github.com/zhanggang001/hednet/blob/main/tools/train.py"
    click ScriptsTrain "https://github.com/zhanggang001/hednet/blob/main/tools/scripts/dist_train.sh"
    click Test "https://github.com/zhanggang001/hednet/blob/main/tools/test.py"
    click ScriptsTest "https://github.com/zhanggang001/hednet/blob/main/tools/scripts/dist_test.sh"
    click EvalUtils "https://github.com/zhanggang001/hednet/blob/main/tools/eval_utils/eval_utils.py"
    click CFGs "https://github.com/zhanggang001/hednet/tree/main/tools/cfgs/"
    click ConfigPy "https://github.com/zhanggang001/hednet/blob/main/pcdet/config.py"
    click Docker "https://github.com/zhanggang001/hednet/tree/main/docker/Dockerfile"
    click Packaging "https://github.com/zhanggang001/hednet/blob/main/setup.py"
    click Docs "https://github.com/zhanggang001/hednet/tree/main/docs/"

    %% Styles
    classDef pythonModule fill:#B3D7FF,stroke:#333,stroke-width:1px
    classDef dataSink fill:#FFA500,stroke:#333,stroke-width:1px,shape:parallelogram
    classDef storage fill:#A3BE8C,stroke:#333,stroke-width:1px,shape:cylinder
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px,shape:hexagon
```
