# mit-han-lab/bevfusion architecture

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

- Interactive diagram: https://gitdiagram.com/mit-han-lab/bevfusion
- Repository: https://github.com/mit-han-lab/bevfusion

## Overview

##### Main Components
- Data Sources & Inputs: Represent the sensors that feed the system (cameras, LiDAR, radar). Note that the README emphasizes multi-sensor fusion.
- Data Preparation & Configuration: Show the dataset and configuration management. This includes the YAML configuration files found under the “configs” directory for different tasks (detection, segmentation) and modalities (camera, LiDAR, fusion).
- Preprocessing & Dataset Pipelines: Indicate the data conversion and loading pipelines defined in the “mmdet3d/datasets” and “tools/data_converter” directories. Include the data preparation module (as outlined in the README regarding nuScenes data preparation).
- Feature Extraction Backbones: Illustrate sensor-specific encoders (Camera backbone in “mmdet3d/models/backbones/resnet.py”, “swint”, etc., LiDAR encoder modules, and even radar encoder if applicable). Emphasize that BEVFusion leverages these backbones to extract high-dimensional features.
- BEV Transformation & Fusion Module: This is the heart of the framework. Highlight:
– The “view transformation” component that converts sensor-specific features into a unified BEV space.
– The “efficient BEV pooling” operator implemented under “mmdet3d/ops/bev_pool”.
– The Fusion modules (see “mmdet3d/models/necks/lss.py”, “generalized_lss.py” and in fusion models “bevfusion.py”) that merge features from multiple sensors.
- Task-specific Heads:
– Segmentation Heads: Found in “mmdet3d/models/heads/segm” (e.g., “vanilla.py”) for BEV map segmentation.
- Post-Processing & Evaluation: Represent the components where non-maximum suppression (NMS) and other post-processing tasks are performed. The “mmdet3d/core/post_processing” directory provides related utilities.
- Training and Inference Controllers: Include the orchestration components such as the APIs for training and testing (see “mmdet3d/apis/train.py” and “mmdet3d/apis/test.py”), as well as the distributed runner “torchpack” used for multi-GPU execution.
- Custom CUDA Operations: Detail the custom CUDA extensions and ops (found in “mmdet3d/ops/*”) which are critical for efficiency. Group these as “Custom Ops” that accelerate key computations including voxelization, ball query, gather points, and others.

##### Relationships and Interactions
– From sensor inputs → Data loader & Preprocessing → Sensor-specific Feature Extraction.
– Feature Extraction outputs are fed into the BEV Transformation module.
– The BEV Fusion module aggregates multi-modal data and sends the unified BEV features to the Task-specific Heads.
– Outputs from these heads are passed to Post-Processing components and eventually to the evaluation and inference modules.
– Additionally, show that training pipelines interact with distributed runners and incorporate feedback loops.
- Connections between configuration management (via YAML files) and nearly every major module since these files dictate the runtime behavior.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize that the project follows a modular structure by partitioning sensors, backbones, fusion strategies, and task heads.
- Extensibility: Note the design’s goal to be task-agnostic—one module (the BEV representation) supports both detection and segmentation with minimal changes.
- Efficiency Optimizations: Mark the custom CUDA ops and optimized BEV pooling as key performance aspects.
- Use of Standard Frameworks: For instance, integration with MMDetection3D and distributed training via Torchpack.

##### Technologies, Frameworks, and Libraries
- Built on PyTorch (with specific version constraints as mentioned in the README).
- Integration with libraries such as MMCV and MMDectection3D.
- Utilization of custom modules for CUDA-based operations (CUDA C++/cu files in ops folders).
- Deployment considerations (e.g., Docker, TensorRT integration for deployment on NVIDIA platforms).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources
    subgraph "Data Sources"
        S1["Camera"]:::sensor
        S2["LiDAR"]:::sensor
        S3["Radar"]:::sensor
    end

    %% Data Preparation & Configuration
    subgraph "Data Preparation & Configuration"
        Cfg["Data Config & YAML Files"]:::config
    end

    %% Preprocessing & Dataset Pipelines
    subgraph "Preprocessing & Dataset Pipelines"
        DS["Dataset Pipeline"]:::preproc
        Conv["nuScenes Converter"]:::preproc
    end

    %% Feature Extraction Backbones
    subgraph "Feature Extraction"
        CamEnc["Camera Encoder (ResNet)"]:::feature
        RadEnc["Radar Encoder"]:::feature
        LidarEnc["LiDAR Encoder"]:::feature
    end

    %% BEV Transformation & Fusion Module
    subgraph "BEV Transformation & Fusion"
        BEVPool["BEV Pooling"]:::fusion
        FusionLSS["Fusion Module (LSS)"]:::fusion
        FusionGen["Fusion Module (Generalized LSS)"]:::fusion
        BEVFusion["BEVFusion Fusion Model"]:::fusion
    end

    %% Task-specific Heads
    subgraph "Task-specific Heads"
        DetCP["Detection Head (CenterPoint)"]:::head
        DetTrans["Detection Head (Transfusion)"]:::head
        SegVanilla["Segmentation Head (Vanilla)"]:::head
    end

    %% Post-Processing & Evaluation
    subgraph "Post-Processing & Evaluation"
        PostProc["Post-Processing & NMS"]:::postproc
    end

    %% Training and Inference Controllers
    subgraph "Training & Inference Controllers"
        TrainCtl["Training Controller"]:::control
        TestCtl["Inference Controller"]:::control
        OrchTrain["Orchestration: Train Script"]:::control
        OrchTest["Orchestration: Test Script"]:::control
    end

    %% Custom CUDA Operations
    subgraph "Custom CUDA Operations"
        CUDAOps["Custom CUDA Ops"]:::cuda
    end

    %% Connections between components
    S1 -->|"sends_data"| Cfg
    S2 -->|"sends_data"| Cfg
    S3 -->|"sends_data"| Cfg

    Cfg -->|"configures"| DS
    Cfg -->|"configures"| Conv

    DS -->|"feeds_data"| Conv
    Conv -->|"preprocesses"| CamEnc
    Conv -->|"preprocesses"| RadEnc
    DS -->|"provides_data"| LidarEnc

    CamEnc -->|"extracts_features"| BEVPool
    RadEnc -->|"extracts_features"| BEVPool
    LidarEnc -->|"extracts_features"| BEVPool

    BEVPool -->|"transforms_to_BEV"| FusionLSS
    BEVPool -->|"transforms_to_BEV"| FusionGen
    FusionLSS -->|"fuses_features"| BEVFusion
    FusionGen -->|"fuses_features"| BEVFusion

    BEVFusion -->|"detection_features"| DetCP
    BEVFusion -->|"detection_features"| DetTrans
    BEVFusion -->|"segmentation_features"| SegVanilla

    DetCP -->|"post_process"| PostProc
    DetTrans -->|"post_process"| PostProc
    SegVanilla -->|"post_process"| PostProc

    PostProc -->|"final_output"| TrainCtl
    PostProc -->|"final_output"| TestCtl

    TrainCtl -->|"triggers"| OrchTrain
    TestCtl -->|"triggers"| OrchTest

    %% Dashed configuration influence
    Cfg --- CamEnc
    Cfg --- RadEnc
    Cfg --- LidarEnc
    Cfg --- BEVPool
    Cfg --- FusionLSS
    Cfg --- FusionGen
    Cfg --- BEVFusion
    Cfg --- DetCP
    Cfg --- DetTrans
    Cfg --- SegVanilla

    %% Custom CUDA Ops support
    CUDAOps --- BEVPool
    CUDAOps --- FusionLSS
    CUDAOps --- FusionGen
    CUDAOps --- BEVFusion

    %% Click Events
    click Cfg "https://github.com/mit-han-lab/bevfusion/tree/main/configs"
    click DS "https://github.com/mit-han-lab/bevfusion/tree/main/mmdet3d/datasets"
    click Conv "https://github.com/mit-han-lab/bevfusion/blob/main/tools/data_converter/nuscenes_converter.py"
    click CamEnc "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/backbones/resnet.py"
    click RadEnc "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/backbones/radar_encoder.py"
    click BEVPool "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/ops/bev_pool/bev_pool.py"
    click FusionLSS "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/necks/lss.py"
    click FusionGen "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/necks/generalized_lss.py"
    click BEVFusion "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/fusion_models/bevfusion.py"
    click DetCP "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/heads/bbox/centerpoint.py"
    click DetTrans "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/heads/bbox/transfusion.py"
    click SegVanilla "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/models/heads/segm/vanilla.py"
    click PostProc "https://github.com/mit-han-lab/bevfusion/tree/main/mmdet3d/core/post_processing"
    click TrainCtl "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/apis/train.py"
    click TestCtl "https://github.com/mit-han-lab/bevfusion/blob/main/mmdet3d/apis/test.py"
    click OrchTrain "https://github.com/mit-han-lab/bevfusion/blob/main/tools/train.py"
    click OrchTest "https://github.com/mit-han-lab/bevfusion/blob/main/tools/test.py"
    click CUDAOps "https://github.com/mit-han-lab/bevfusion/tree/main/mmdet3d/ops"

    %% Styles
    classDef sensor fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef config fill:#66CCFF,stroke:#333,stroke-width:2px;
    classDef preproc fill:#FF6666,stroke:#333,stroke-width:2px;
    classDef feature fill:#CCFF99,stroke:#333,stroke-width:2px;
    classDef fusion fill:#99CCFF,stroke:#333,stroke-width:2px;
    classDef head fill:#FF9999,stroke:#333,stroke-width:2px;
    classDef postproc fill:#CCCCCC,stroke:#333,stroke-width:2px;
    classDef control fill:#CC99FF,stroke:#333,stroke-width:2px;
    classDef cuda fill:#FFCCFF,stroke:#333,stroke-width:2px;
```
