# swc-17/sparsedrive architecture

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

- Interactive diagram: https://gitdiagram.com/swc-17/sparsedrive
- Repository: https://github.com/swc-17/sparsedrive

## Overview

##### Main Components
- • Input & Data Preprocessing: The system ingests multi-view images and possibly additional sensor data. This stage is represented in the configuration files (found under projects/configs) and the dataset pipelines (in projects/mmdet3d_plugin/datasets and its subdirectories).
- • Sparse Perception Module: Based on README images and file structure, the core “sparse-centric” perception is implemented in models (projects/mmdet3d_plugin/models) and includes submodules dedicated to detection3d, mapping, and motion. The “symmetric” design is visible in the separation between modules (e.g., models/detection3d, models/map, models/motion).
- • Instance Memory & Temporal Modeling: There is an instance bank (see projects/mmdet3d_plugin/models/instance_bank.py) and memory queue for temporal modeling, vital for tracking.
- • Core Operations and Utility Functions: Low-level operators (in projects/mmdet3d_plugin/ops) provide optimized functionalities (with C++/CUDA implementations) used across perception and planning.
- • Configuration & APIs: There is a dedicated APIs folder to start training, testing, and evaluation (projects/mmdet3d_plugin/apis) along with configuration scripts and external tools (e.g., scripts, tools directory) that handle tasks such as data conversion, benchmark testing, and visualizations.

##### Determining Relationships and Interactions
- Data flows from multi-view image inputs into feature extraction modules.
- Processed features are then passed into a sparse perception network that outputs a unified sparse scene representation.
- This representation serves as the input for both detection/tracking/mapping modules and concurrently for motion prediction and planning.
- An internal memory queue (instance bank) provides temporal continuity across frames.
- The training, testing, and evaluation pipelines (APIs, scripts, and tools) wrap around these main modules, coordinating module interactions using the configurations provided.

##### Architectural Patterns and Design Principles
- • Modular Organization: The clear separation among “apis”, “datasets”, “models”, “core”, and “ops” hints at a layered architecture. Each module has a specific responsibility.
- • Parallel Processing: The design explicitly supports parallel computation between motion prediction and planning.
- • Extensibility: With configuration files, plugin-like modules (mmdet3d_plugin), and separate scripts for different tasks, the design supports future modifications and extensions.
- • Use of heterogeneous technology: Components written in Python, high-performance C++/CUDA (in "ops"), and external scripts (shell scripts in scripts/ and tools/) show the system uses different languages and platforms for performance and flexibility.

##### Including Relevant Technologies and Libraries
- The project integrates with popular frameworks such as MMDetection3D (as hinted by the projects/mmdet3d_plugin and references to mmdet3d in the README).
- There are external links and acknowledgements to related projects (Sparse4D, UniAD, VAD, StreamPETR, etc.).
- The use of Python for high-level API and configuration management, along with C++/CUDA for performance-critical operations in the “ops” folder.

- From this block, branch out to a “Feature Extraction” module which then feeds into a central block labeled “Sparse Scene Representation.”
- From the central block, create two branches:
◦ One that goes to “Perception & Tracking (Detection, Mapping, Tracking)”
◦ Another that goes to “Parallel Motion Prediction & Planning.”
- Additional blocks can illustrate auxiliary components like “Configuration Management” (projects/configs) and “API & Tools” (apis, scripts, tools).
- Lastly, include annotations that mention the performance-optimized modules (ops) and mention integration with external systems such as the nuScenes benchmark.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Input & Preprocessing"
        A["Multi-View Image Inputs"]:::data
        B["Config Stage1"]:::config
        C["Config Stage2"]:::config
        D["Dataset Pipelines"]:::data
        E["Core Operations"]:::coreOps
        F["Feature Extraction"]:::processing
    end

    subgraph "Central Processing"
        G["Sparse Scene Representation"]:::processing
    end

    subgraph "Perception & Tracking"
        H["Detection3D Module"]:::perception
        I["Mapping Module"]:::perception
        J["Instance Bank"]:::temporal
    end

    subgraph "Parallel Motion Planning & Prediction"
        K["Motion Module"]:::motion
        L["Memory Queue"]:::temporal
    end

    subgraph "APIs & External Tools"
        N["APIs"]:::api
        O["Scripts"]:::api
        P["Tools"]:::api
    end

    M["Core Utilities"]:::core

    %% Data Preprocessing to Feature Extraction
    A --> F
    B --> F
    C --> F
    D --> F
    E --> F

    %% Feature Extraction to Central Processing
    F --> G
    M --> G

    %% Central Processing to Perception & Tracking
    G --> H
    G --> I
    H --> J

    %% Central Processing to Parallel Motion Planning & Prediction
    G --> K
    K --> L

    %% External APIs & Tools integration
    N --> G
    O --> G
    P --> G

    %% Click Events
    click B "https://github.com/swc-17/sparsedrive/blob/main/projects/configs/sparsedrive_small_stage1.py"
    click C "https://github.com/swc-17/sparsedrive/blob/main/projects/configs/sparsedrive_small_stage2.py"
    click D "https://github.com/swc-17/sparsedrive/tree/main/projects/mmdet3d_plugin/datasets/pipelines"
    click E "https://github.com/swc-17/sparsedrive/tree/main/projects/mmdet3d_plugin/ops"
    click H "https://github.com/swc-17/sparsedrive/tree/main/projects/mmdet3d_plugin/models/detection3d"
    click I "https://github.com/swc-17/sparsedrive/tree/main/projects/mmdet3d_plugin/models/map"
    click K "https://github.com/swc-17/sparsedrive/tree/main/projects/mmdet3d_plugin/models/motion"
    click J "https://github.com/swc-17/sparsedrive/blob/main/projects/mmdet3d_plugin/models/instance_bank.py"
    click L "https://github.com/swc-17/sparsedrive/blob/main/projects/mmdet3d_plugin/models/motion/instance_queue.py"
    click M "https://github.com/swc-17/sparsedrive/tree/main/projects/mmdet3d_plugin/core"
    click N "https://github.com/swc-17/sparsedrive/tree/main/projects/mmdet3d_plugin/apis"
    click O "https://github.com/swc-17/sparsedrive/tree/main/scripts"
    click P "https://github.com/swc-17/sparsedrive/tree/main/tools"

    %% Styles
    classDef data fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef config fill:#FFC300,stroke:#333,stroke-width:2px;
    classDef processing fill:#C0F9B4,stroke:#333,stroke-width:2px;
    classDef coreOps fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef perception fill:#B4AEE8,stroke:#333,stroke-width:2px;
    classDef motion fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef temporal fill:#D3FFCE,stroke:#333,stroke-width:2px;
    classDef api fill:#FDE1A9,stroke:#333,stroke-width:2px;
    classDef core fill:#98FB98,stroke:#333,stroke-width:2px;
```
