How graphdeco-inria/on-the-fly-nvs works
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 train.py · guided_mvs.py guided MVS · scene_model.py scene model · optimizers.py optimizers
Components 25
Training pipeline
Main entrypoint and orchestration of reconstruction.
- train.py · 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 · Loads ordered image sequences and optional masks from disk.
dataloaders/image_dataset.py - stream dataset · Ingests a video-stream source for the mobile/web prototype.
dataloaders/stream_dataset.py - model 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 · Detects features for pose bootstrapping and tracking.
poses/feature_detector.py - matcher · Matches features across frames for initialization and extension.
poses/matcher.py - pose init · Initializes the first camera poses from sequential observations.
poses/pose_initializer.py - guided MVS · Guided multi-view stereo and geometric verification for pose extension.
poses/guided_mvs.py - RANSAC · CUDA-accelerated robust estimation used during pose verification.
poses/ransac.py - mini BA · Small bundle adjustment step for local pose refinement.
poses/mini_ba.py - triangulator · Triangulates track observations into initial 3D structure.
poses/triangulator.py
Scene growth
Keyframes, anchors, depth priors, and Gaussian scene optimization.
- keyframes · Maintains selected frames and temporal anchors for growth.
scene/keyframe.py - anchors · Represents persistent anchor structures used during reconstruction.
scene/anchor.py - dense sampling · Produces depth-aware dense samples for scene expansion.
scene/dense_extractor.py - mono depth · Wraps monocular depth guidance used by dense extraction.
scene/mono_depth.py - scene model · Stores and updates the growing Gaussian scene representation.
scene/scene_model.py - optimizers · Coordinates pose and Gaussian parameter updates, growth, and checkpoint/export flow.
scene/optimizers.py - extractor model · 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 · Differentiable Gaussian rasterization backend.
submodules/diff-gaussian-rasterization - simple knn · Neighbor search and point acceleration for scene geometry.
submodules/simple-knn - fused ssim · SSIM kernel used in reconstruction loss computation.
submodules/fused-ssim
Inspection & tools
Local and web viewers plus operational scripts.
- viewer · Local/server/client viewer for monitoring reconstruction and live optimization.
gaussianviewer.py - web viewer · Web-based viewer for the streaming workflow.
webviewer/webviewer.py - scripts · Dataset prep, rectification, resizing, rendering, and benchmark automation.
scripts - render path · Renders a trained scene along a camera trajectory and can align paths.
scripts/render_path.py
Connections 25
- 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.