# graphdeco-inria/on-the-fly-nvs architecture

> Architecture diagram of the GitHub repository graphdeco-inria/on-the-fly-nvs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/graphdeco-inria/on-the-fly-nvs
- Repository: https://github.com/graphdeco-inria/on-the-fly-nvs

## Overview

1. This repository is a single Python/CUDA reconstruction pipeline for sequential, unposed image capture. The main entry point is `train.py`, which orchestrates the whole system: dataset loading, pose bootstrapping/tracking, scene growth, differentiable rendering, optimization, evaluation, and optional live viewing.

2. The architecture is built around a strict input boundary: it expects an ordered image sequence, usually from `${SOURCE_PATH}/images`, and does not reorder frames like COLMAP. Optional COLMAP files in `sparse/0` are used for initialization, pose comparison, or visualization, but they are not required for the main reconstruction loop.

3. Data ingestion is split between still-image and live-stream paths. `dataloaders/image_dataset.py` handles folder-based images and masks, while `dataloaders/stream_dataset.py` supports a video-stream URL for the mobile/web prototype. `dataloaders/read_write_model.py` reads and writes COLMAP-style camera and trajectory files, which are also used later for rendering camera paths.

4. Pose estimation is a dedicated subsystem under `poses/`. It includes feature detection and matching, pose initialization, guided multi-view stereo, RANSAC-based geometric verification, mini bundle adjustment, and triangulation. These modules bootstrap the first camera poses and then incrementally extend the trajectory as new keyframes arrive.

5. The scene-reconstruction layer lives under `scene/`. It manages keyframes, anchors, scene state, and optimization of the 3D representation. `scene/mono_depth.py` and `scene/dense_extractor.py` introduce depth-aware dense sampling, with `submodules/Depth-Anything-V2` acting as an external monocular-depth prior. This layer is what turns sparse pose estimates and image observations into a growing Gaussian scene.

6. The actual renderable representation is 3D Gaussian Splatting. The differentiable rasterizer comes from `submodules/diff-gaussian-rasterization`, and point-neighbor acceleration comes from `submodules/simple-knn`. Loss computation also uses `submodules/fused-ssim`. In other words, Python controls the optimization loop, while the heavy lifting for rendering and geometry is done by custom CUDA extensions.

7. Scene optimization is iterative and joint: the system refines camera poses and Gaussian parameters together while processing the sequence. `scene/optimizers.py` and `scene/scene_model.py` coordinate parameter updates, scene growth, clustering/merging, and export of checkpoints and test renders. The repository is designed for on-the-fly updates rather than a one-shot offline reconstruction.

8. Output artifacts are written under `model_path` or `results/…`. Typical outputs include optimized checkpoints, saved test renders, a COLMAP-style pose export, and video renders along user-specified camera paths. `scripts/render_path.py` renders a trained scene along a trajectory, and can align that trajectory to the reconstructed scene if the camera coordinate systems differ.

9. Viewer support is a first-class subsystem rather than an afterthought. `gaussianviewer.py` provides local, server, and client modes for inspecting a reconstruction or monitoring live optimization. `webviewer/` adds a browser-based viewer for the streaming/mobile workflow. The viewer stack is based on the separate `graphdecoviewer` submodule and can run either on the same machine as training or on a remote client.

10. The `scripts/` directory contains the repo’s operational tooling: dataset download, image rectification/resizing, path rendering, and batch evaluation across scenes. `scripts/train_eval_all.py` automates the benchmark loop used in the paper, while `scripts/download_datasets.py` prepares the dataset layout expected by the dataloaders.

11. The main system boundary is therefore: ordered images or stream in, pose bootstrap and incremental tracking in the middle, Gaussian scene optimization and differentiable rendering at the core, and multiple output/inspection channels at the edge (saved model, rendered evaluations, local/remote/web viewers).

12. Technically, the project is a Python application with GPU-accelerated native extensions. CUDA, PyTorch, and CuPy matter because the reconstruction loop depends on custom GPU kernels for matching, RANSAC/MVS-related steps, and rasterized rendering. This means the architecture is compute-centric and centered on a single reconstruction host, with optional lightweight clients for viewing.

Main entry points: [`train.py`](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/train.py) (train.py), [`poses/guided_mvs.py`](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/guided_mvs.py) (guided MVS), [`scene/scene_model.py`](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/scene_model.py) (scene model), [`scene/optimizers.py`](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/optimizers.py) (optimizers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Training pipeline"]
  node_n1["train.py<br/>orchestrator<br/>[train.py]"]
end

subgraph group_g2["Data layer"]
  node_n2["image dataset<br/>folder loader<br/>[image_dataset.py]"]
  node_n3["stream dataset<br/>live input<br/>[stream_dataset.py]"]
  node_n4["model IO<br/>COLMAP IO"]
end

subgraph group_g3["Pose bootstrap"]
  node_n5["feature detect<br/>matching front-end"]
  node_n6["matcher<br/>correspondence<br/>[matcher.py]"]
  node_n7["pose init<br/>bootstrap"]
  node_n8["guided MVS<br/>geometric verify<br/>[guided_mvs.py]"]
  node_n9["RANSAC<br/>robust fit<br/>[ransac.py]"]
  node_n10["mini BA<br/>refinement<br/>[mini_ba.py]"]
  node_n11["triangulator<br/>3D init<br/>[triangulator.py]"]
end

subgraph group_g4["Scene growth"]
  node_n12["keyframes<br/>scene state<br/>[keyframe.py]"]
  node_n13["anchors<br/>scene state<br/>[anchor.py]"]
  node_n14["dense sampling<br/>depth prior<br/>[dense_extractor.py]"]
  node_n15["mono depth<br/>depth prior<br/>[mono_depth.py]"]
  node_n16[("scene model<br/>gaussian scene<br/>[scene_model.py]")]
  node_n17["optimizers<br/>joint optimize<br/>[optimizers.py]"]
  node_n18["extractor model<br/>scene init<br/>[extractor_model.py]"]
end

subgraph group_g5["GPU extensions"]
  node_n19["rasterizer<br/>CUDA render"]
  node_n20["simple knn<br/>CUDA geometry"]
  node_n21["fused ssim<br/>loss kernel"]
end

subgraph group_g6["Inspection & tools"]
  node_n22["viewer<br/>inspection<br/>[gaussianviewer.py]"]
  node_n23["web viewer<br/>browser client<br/>[webviewer.py]"]
  node_n24["scripts<br/>ops tools"]
  node_n25["render path<br/>trajectory render<br/>[render_path.py]"]
end

node_n1 -->|"loads"| node_n2
node_n1 -->|"optionally streams"| node_n3
node_n1 -->|"reads init"| node_n4
node_n1 -->|"starts tracking"| node_n5
node_n5 -->|"feeds matches"| node_n6
node_n6 -->|"bootstraps"| node_n7
node_n7 -->|"extends poses"| node_n8
node_n8 -->|"verifies"| node_n9
node_n8 -->|"refines"| node_n10
node_n8 -->|"triangulates"| node_n11
node_n1 -->|"manages"| node_n12
node_n1 -->|"optimizes"| node_n17
node_n12 -->|"anchors"| node_n13
node_n13 -->|"guides sampling"| node_n14
node_n14 -->|"uses prior"| node_n15
node_n17 -->|"updates"| node_n16
node_n16 -->|"renders with"| node_n19
node_n16 -->|"accelerates"| node_n20
node_n17 -->|"computes loss"| node_n21
node_n1 -->|"opens viewer"| node_n22
node_n22 -->|"shares stream"| node_n23
node_n1 -->|"uses tooling"| node_n24
node_n24 -->|"renders trajectories"| node_n25
node_n25 -->|"aligns/export"| node_n4
node_n18 -.->|"initializes"| node_n16

click node_n1 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/train.py"
click node_n2 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/dataloaders/image_dataset.py"
click node_n3 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/dataloaders/stream_dataset.py"
click node_n4 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/dataloaders/read_write_model.py"
click node_n5 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/feature_detector.py"
click node_n6 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/matcher.py"
click node_n7 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/pose_initializer.py"
click node_n8 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/guided_mvs.py"
click node_n9 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/ransac.py"
click node_n10 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/mini_ba.py"
click node_n11 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/triangulator.py"
click node_n12 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/keyframe.py"
click node_n13 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/anchor.py"
click node_n14 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/dense_extractor.py"
click node_n15 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/mono_depth.py"
click node_n16 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/scene_model.py"
click node_n17 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/optimizers.py"
click node_n18 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/extractor_model.py"
click node_n19 "https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/submodules/diff-gaussian-rasterization"
click node_n20 "https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/submodules/simple-knn"
click node_n21 "https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/submodules/fused-ssim"
click node_n22 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/gaussianviewer.py"
click node_n23 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/webviewer/webviewer.py"
click node_n24 "https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/scripts"
click node_n25 "https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scripts/render_path.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n1 toneBlue
class node_n2,node_n3,node_n4 toneAmber
class node_n5,node_n6,node_n7,node_n8,node_n9,node_n10,node_n11 toneMint
class node_n12,node_n13,node_n14,node_n15,node_n16,node_n17,node_n18 toneRose
class node_n19,node_n20,node_n21 toneIndigo
class node_n22,node_n23,node_n24,node_n25 toneTeal
```

## Components

### Training pipeline

Main entrypoint and orchestration of reconstruction.

- [train.py](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/train.py): orchestrator · Main reconstruction loop that coordinates loading, tracking, optimization, evaluation, and viewing. · `train.py`

### Data layer

Ordered image and stream ingestion plus COLMAP-style IO.

- [image dataset](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/dataloaders/image_dataset.py): folder loader · Loads ordered image sequences and optional masks from disk. · `dataloaders/image_dataset.py`
- [stream dataset](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/dataloaders/stream_dataset.py): live input · Ingests a video-stream source for the mobile/web prototype. · `dataloaders/stream_dataset.py`
- [model IO](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/dataloaders/read_write_model.py): COLMAP IO · Reads and writes COLMAP-style camera and trajectory files. · `dataloaders/read_write_model.py`

### Pose bootstrap

Feature, matching, initialization, verification, and triangulation.

- [feature detect](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/feature_detector.py): matching front-end · Detects features for pose bootstrapping and tracking. · `poses/feature_detector.py`
- [matcher](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/matcher.py): correspondence · Matches features across frames for initialization and extension. · `poses/matcher.py`
- [pose init](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/pose_initializer.py): bootstrap · Initializes the first camera poses from sequential observations. · `poses/pose_initializer.py`
- [guided MVS](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/guided_mvs.py): geometric verify · Guided multi-view stereo and geometric verification for pose extension. · `poses/guided_mvs.py`
- [RANSAC](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/ransac.py): robust fit · CUDA-accelerated robust estimation used during pose verification. · `poses/ransac.py`
- [mini BA](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/mini_ba.py): refinement · Small bundle adjustment step for local pose refinement. · `poses/mini_ba.py`
- [triangulator](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/poses/triangulator.py): 3D init · Triangulates track observations into initial 3D structure. · `poses/triangulator.py`

### Scene growth

Keyframes, anchors, depth priors, and Gaussian scene optimization.

- [keyframes](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/keyframe.py): scene state · Maintains selected frames and temporal anchors for growth. · `scene/keyframe.py`
- [anchors](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/anchor.py): scene state · Represents persistent anchor structures used during reconstruction. · `scene/anchor.py`
- [dense sampling](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/dense_extractor.py): depth prior · Produces depth-aware dense samples for scene expansion. · `scene/dense_extractor.py`
- [mono depth](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/mono_depth.py): depth prior · Wraps monocular depth guidance used by dense extraction. · `scene/mono_depth.py`
- [scene model](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/scene_model.py): gaussian scene · Stores and updates the growing Gaussian scene representation. · `scene/scene_model.py`
- [optimizers](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/optimizers.py): joint optimize · Coordinates pose and Gaussian parameter updates, growth, and checkpoint/export flow. · `scene/optimizers.py`
- [extractor model](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scene/extractor_model.py): scene init · Auxiliary model for scene feature extraction and initialization. · `scene/extractor_model.py`

### GPU extensions

Native CUDA/PyTorch acceleration used by pose and rendering code.

- [rasterizer](https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/submodules/diff-gaussian-rasterization): CUDA render · Differentiable Gaussian rasterization backend. · `submodules/diff-gaussian-rasterization`
- [simple knn](https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/submodules/simple-knn): CUDA geometry · Neighbor search and point acceleration for scene geometry. · `submodules/simple-knn`
- [fused ssim](https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/submodules/fused-ssim): loss kernel · SSIM kernel used in reconstruction loss computation. · `submodules/fused-ssim`

### Inspection & tools

Local and web viewers plus operational scripts.

- [viewer](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/gaussianviewer.py): inspection · Local/server/client viewer for monitoring reconstruction and live optimization. · `gaussianviewer.py`
- [web viewer](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/webviewer/webviewer.py): browser client · Web-based viewer for the streaming workflow. · `webviewer/webviewer.py`
- [scripts](https://github.com/graphdeco-inria/on-the-fly-nvs/tree/main/scripts): ops tools · Dataset prep, rectification, resizing, rendering, and benchmark automation. · `scripts`
- [render path](https://github.com/graphdeco-inria/on-the-fly-nvs/blob/main/scripts/render_path.py): trajectory render · Renders a trained scene along a camera trajectory and can align paths. · `scripts/render_path.py`

## Connections

- train.py → image dataset: loads · Uses folder-based image sequences as the primary input.
- train.py → stream dataset: optionally streams · Can switch to the live-stream path for prototype workflows.
- train.py → model IO: reads init · Consumes optional COLMAP-style poses and exports trajectory files.
- train.py → feature detect: starts tracking · Begins pose bootstrapping from detected features.
- feature detect → matcher: feeds matches · Feature detection supplies correspondences to the matcher.
- matcher → pose init: bootstraps · Matches are used to initialize the first camera poses.
- pose init → guided MVS: extends poses · Initialization hands off to guided multi-view pose extension.
- guided MVS → RANSAC: verifies · Guided MVS relies on robust geometric verification.
- guided MVS → mini BA: refines · Incremental pose estimates are tightened locally.
- guided MVS → triangulator: triangulates · Verified correspondences are turned into 3D points.
- train.py → keyframes: manages · The main loop maintains keyframe selection and sequencing.
- train.py → optimizers: optimizes · Orchestrates joint updates of poses and scene parameters.
- keyframes → anchors: anchors · Keyframes are tied to persistent anchors.
- anchors → dense sampling: guides sampling · Anchors inform dense extraction and growth.
- dense sampling → mono depth: uses prior · Dense extraction is driven by monocular depth guidance.
- optimizers → scene model: updates · Optimization mutates the Gaussian scene state.
- scene model → rasterizer: renders with · Scene model is rasterized through the CUDA renderer.
- scene model → simple knn: accelerates · Neighbor search supports scene geometry operations.
- optimizers → fused ssim: computes loss · Training losses include fused SSIM.
- train.py → viewer: opens viewer · Training can publish state to the local viewer.
- viewer → web viewer: shares stream · Viewer stack supports a browser-based client path.
- train.py → scripts: uses tooling · Operational scripts support dataset prep and evaluation.
- scripts → render path: renders trajectories · Path rendering is one of the main utility flows.
- render path → model IO: aligns/export · Trajectory rendering can consume and compare COLMAP-style paths.
- extractor model → scene model: initializes · Extractor model contributes to scene initialization.
