# graphdeco-inria/reduced-3dgs architecture

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

- Interactive diagram: https://gitdiagram.com/graphdeco-inria/reduced-3dgs
- Repository: https://github.com/graphdeco-inria/reduced-3dgs

## Overview

##### Project type and purpose
- This is a research-oriented, full-stack 3D graphics and machine-learning codebase for “Reducing the Memory Footprint of 3D Gaussian Splatting.”
- It combines a Python/CUDA training pipeline (PyTorch + custom C++ extensions), data-conversion utilities, evaluation scripts, and two interactive viewer applications (built with SIBR in C++/OpenGL).

##### File structure
- Top-level scripts:
- train.py, full_eval.py, render.py, metrics.py — orchestrate training, evaluation, rendering, metrics.
- convert.py, update_old_ply_format.py — data conversion (COLMAP→undistorted images, legacy PLY→new quantized PLY).
- Core modules:
- scene/ — dataset loaders (COLMAP, NeRF), camera models, Gaussian model.
- gaussian_renderer/ — Python interface + network GUI to the differentiable rasterizer.
- lpipsPyTorch/ — LPIPS perceptual-loss module.
- utils/ — camera, image, graphics, loss, profiling, system, visualization helpers.
- submodules/diff-gaussian-rasterization — C++/CUDA PyTorch extension for rasterizing Gaussians.
- submodules/simple-knn — CUDA extension for nearest-neighbor search.
- Viewer code: SIBR_viewers/ contains two C++ applications built with CMake; one for remote network viewing, one for local real-time viewing.
- Configuration: environment.yml, CMakeLists.txt under submodules, .gitmodules, scripts for building submodules.

##### Extract architectural insights from the README
- Data flow: raw images + COLMAP data → convert.py → structured dataset → train.py →
- uses scene loaders + differentiable rasterizer extension + PyTorch optimizer →
- outputs trained model (directory with .ply files + checkpoints + codebooks) →
- evaluation (render.py + metrics.py + full_eval.py)
- interactive monitoring via gaussian_renderer/network_gui.py ← train.py (opens TCP server on port 6009).
- Quantization pipeline: PLY format manipulation, codebook entries appended to files, half-float storage.
- Viewer apps connect to the training pipeline or read final models for visualization.

##### Main components and their interactions
a. Data Ingestion & Conversion
- convert.py reads raw images & COLMAP outputs → produces undistorted/resized images + camera metadata.
- update_old_ply_format.py transforms legacy PLY to new quantized format.
b. Training Pipeline
- train.py (Python)
- Imports scene/, gaussian_renderer/, lpipsPyTorch/, utils/
- Builds and calls C++ CUDA extensions (diff-gaussian-rasterization, simple-knn) via PyTorch’s extension mechanism
- Launches network GUI server (gaussian_renderer/network_gui.py) for real-time training visualization.
- Saves model state (.ply + codebooks + checkpoints) and logs.
c. Evaluation & Results
- render.py: loads trained model → uses same CUDA rasterizer → renders novel views → saves images.
- metrics.py: loads rendered images → computes L1, PSNR, LPIPS.
- full_eval.py: orchestrates train/render/metrics over multiple datasets and experiments.
- generate_results.py: collates final numbers and plots.
d. Interactive Viewers (Presentation Layer)
- SIBR_remoteGaussian_app: connects to the network GUI server on training machine → displays splats.
- SIBR_gaussianViewer_app: standalone real-time viewer reading a saved model → OpenGL + CUDA interop.
e. Third-party services & dependencies
- PyTorch (with CUDA), COLMAP, ImageMagick, OpenGL 4.5, CMake, Visual Studio/g++, Conda.

##### Architectural patterns & design principles
- Layered separation:
- Data layer (datasets, conversions)
- Compute layer (Python orchestration + C++/CUDA extensions)
- Presentation layer (network GUI, C++ viewers)
- Extension modules: clean separation of CUDA-accelerated rasterizer and K-NN as PyTorch extensions.
- Modular CLI: each Python script focuses on a single concern (train, render, metrics, convert).
- Clear data formats: PLY files with appended codebooks, half-float quantization.

##### Detailed elements to capture
- Python scripts: train.py, render.py, metrics.py, full_eval.py, convert.py, update_old_ply_format.py
- Modules: scene/, gaussian_renderer/, utils/, lpipsPyTorch/
- Submodules: diff-gaussian-rasterization, simple-knn
- Data: raw images + COLMAP sparse, converted dataset, trained model directory (.ply + codebooks), rendered images, metric logs
- Viewers: network GUI server (Python), SIBR_remoteGaussian_app, SIBR_gaussianViewer_app
- External: PyTorch/CUDA, COLMAP, ImageMagick, OpenGL, CMake/compilers, Conda environment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Conversion Layer
    subgraph "Data & Conversion"
        direction TB
        RawData["Raw Images + COLMAP Sparse"]:::datastore
        Convert[convert.py]:::python
        UpdatePLY[update_old_ply_format.py]:::python
        SceneCL[scene/colmap_loader.py]:::python
        SceneDR[scene/dataset_readers.py]:::python
        SceneCam[scene/cameras.py]:::python
        Converted["Converted Dataset"]:::datastore
    end

    %% Training & Evaluation Layer
    subgraph "Training & Evaluation"
        direction TB
        Train[train.py]:::python
        GUI[network_gui.py]:::python
        LPIPS1[lpips.py]:::python
        LPIPS2[networks.py]:::python
        UtilImg[image_utils.py]:::python
        UtilGfx[graphics_utils.py]:::python
        UtilLoss[loss_utils.py]:::python
        UtilProf[profiling_utils.py]:::python
        UtilSys[system_utils.py]:::python
        UtilViz[visualisation_utils.py]:::python
        subgraph "CUDA Extensions"
            direction TB
            DGSetup[diff-gaussian-rasterization/setup.py]:::cppcuda
            DGExt[diff-gaussian-rasterization/ext.cpp]:::cppcuda
            SKSetup[simple-knn/setup.py]:::cppcuda
            SKFExt[simple-knn/ext.cpp]:::cppcuda
        end
        ModelStore["Trained Model Store\n(.ply + codebooks + checkpoints)"]:::datastore
        Render[render.py]:::python
        Metrics[metrics.py]:::python
        FullEval[full_eval.py]:::python
        GenResults[generate_results.py]:::python
        Rendered["Rendered Images"]:::datastore
        MetricLogs["Metric Logs"]:::datastore
    end

    %% Viewer Layer
    subgraph "Presentation Layer"
        direction TB
        SIBRRemote[SIBR_remoteGaussian_app]:::viewer
        SIBRLocal[SIBR_gaussianViewer_app]:::viewer
    end

    %% External Dependencies
    PyTorch((PyTorch/CUDA)):::external
    COLMAP((COLMAP)):::external
    IM((ImageMagick)):::external
    OpenGL((OpenGL 4.5)):::external
    CMake((CMake/Compilers)):::external
    Conda((Conda Env)):::external

    %% Data Flow & Connections
    RawData -->|ingest| Convert -->|outputs| Converted
    RawData -->|legacy PLY| UpdatePLY -->|updates| Converted
    Converted -->|load| Train
    Train -->|calls| SceneCL
    Train -->|calls| SceneDR
    Train -->|calls| SceneCam
    Train -->|imports| DGSetup
    Train -->|imports| DGExt
    Train -->|imports| SKSetup
    Train -->|imports| SKFExt
    Train -->|imports| UtilImg
    Train -->|imports| UtilGfx
    Train -->|imports| UtilLoss
    Train -->|imports| UtilProf
    Train -->|imports| UtilSys
    Train -->|imports| UtilViz
    Train -->|imports| LPIPS1
    Train -->|imports| LPIPS2
    Train -->|launches| GUI
    Train -->|saves| ModelStore
    ModelStore -->|load| Render
    Render -->|saves| Rendered
    Rendered -->|load| Metrics
    Metrics -->|saves| MetricLogs
    FullEval -->|orchestrates| Train
    FullEval -->|orchestrates| Render
    FullEval -->|orchestrates| Metrics
    MetricLogs -->|use| GenResults

    GUI <-->|connects to| SIBRRemote
    ModelStore -->|read| SIBRLocal

    %% External Integrations
    Train -->|runs on| PyTorch
    Convert -->|uses| COLMAP
    Convert -->|uses| IM
    SIBRLocal -->|renders via| OpenGL
    DGExt -->|built with| CMake
    SKSetup -->|builds with| CMake
    Train -->|env| Conda

    %% Click Events
    click Convert "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/convert.py"
    click UpdatePLY "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/update_old_ply_format.py"
    click SceneCL "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/scene/colmap_loader.py"
    click SceneDR "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/scene/dataset_readers.py"
    click SceneCam "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/scene/cameras.py"
    click Train "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/train.py"
    click GUI "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/gaussian_renderer/network_gui.py"
    click LPIPS1 "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/lpipsPyTorch/modules/lpips.py"
    click LPIPS2 "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/lpipsPyTorch/modules/networks.py"
    click UtilImg "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/utils/image_utils.py"
    click UtilGfx "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/utils/graphics_utils.py"
    click UtilLoss "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/utils/loss_utils.py"
    click UtilProf "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/utils/profiling_utils.py"
    click UtilSys "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/utils/system_utils.py"
    click UtilViz "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/utils/visualisation_utils.py"
    click DGSetup "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/submodules/diff-gaussian-rasterization/setup.py"
    click DGExt "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/submodules/diff-gaussian-rasterization/ext.cpp"
    click SKSetup "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/submodules/simple-knn/setup.py"
    click SKFExt "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/submodules/simple-knn/ext.cpp"
    click Render "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/render.py"
    click Metrics "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/metrics.py"
    click FullEval "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/full_eval.py"
    click GenResults "https://github.com/graphdeco-inria/reduced-3dgs/blob/main/generate_results.py"

    %% Styles
    classDef python fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef cppcuda fill:#FFA500,stroke:#333,stroke-width:1px
    classDef datastore fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef viewer fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external stroke-dasharray: 5 5,fill:none,stroke:#666,stroke-width:1px
```
