How cuhk-aim-group/endogaussian works
1. What this repo is
This is a PyTorch-based 4D Gaussian splatting system for dynamic endoscopic scene reconstruction. The core idea is: ingest a time-ordered endoscopic dataset, optimize a deformable Gaussian scene representation, then render novel views/frames and evaluate image quality.
2. Main execution entry points
The root-level workflow is centered on train.py, render.py, metrics.py, and full_eval.py. These are the primary orchestration scripts for training, rendering checkpoints, computing metrics, and running larger evaluation sweeps. The journal/ tree mirrors the same structure for the later TMI version.
3. Configuration is dataset-scene driven
The arguments/ package contains scene-specific config modules for EndoNeRF and SCARED, and journal/arguments/ adds Hamlyn. These files encode per-sequence hyperparameters and dataset paths, so the architecture is not “one model fits all”; it is configured per clip/sequence from Python config modules.
4. Data ingestion boundary
Raw datasets are expected under data/... in a preprocessed layout. The scene/ package is the dataset layer: dataset.py, dataset_readers.py, endo_loader.py, and colmap_loader.py turn endoscopic or COLMAP-style assets into camera objects, image streams, and scene metadata. This is the boundary between filesystem datasets and the learning system.
5. Core scene representation
The central model lives in scene/gaussian_model.py. Supporting modules such as deformation.py, hexplane.py, and regulation.py define the temporal deformation field and regularization terms that make the scene dynamic rather than static. In architecture terms, this is the “world model” the optimizer updates.
6. Camera and geometry utilities
scene/cameras.py plus the utils/ helpers provide camera parameter handling, image/graphics math, spherical-harmonics utilities, scene normalization, and general experiment utilities. These modules are shared infrastructure used by both training and rendering.
7. Rendering pipeline
Rendering is handled through gaussian_renderer/, which wraps the differentiable splatting backend and includes network_gui.py for live/interactive visualization support. The renderer consumes the optimized Gaussian scene plus camera parameters and outputs images, depth, and other render products used by training and evaluation.
8. Optimization and loss computation
Training is not just reconstruction loss; it also uses utility losses from utils/loss_utils.py and regularization from scene/regulation.py. The workflow is typical: load a batch of cameras/frames, render through the Gaussian renderer, compare against ground truth, and backpropagate into the Gaussian/deformation parameters.
9. Evaluation and reconstruction outputs
metrics.py computes quantitative results, and in the journal version journal/metrics.py is paired with journal/lpipsPyTorch/ for perceptual LPIPS evaluation. render.py and journal/render.py support offline rendering of train/test/video splits, and the journal version also mentions optional point-cloud reconstruction via an extra flag.
10. Custom CUDA extensions are part of the architecture
Two compiled submodules are essential: submodules/depth-diff-gaussian-rasterization provides the differentiable Gaussian rasterizer with depth support, and submodules/simple-knn provides fast KNN/spatial queries. These are not optional helpers; they are the performance-critical backend that makes the model train and render in real time.
11. Repository structure has two code generations
The root-level code appears to be the EndoGaussian implementation tied to the arXiv release, while journal/ is a fuller fork for the TMI paper. The journal tree adds Hamlyn support, LPIPS, extraction utilities, and mirrored scene/renderer/training code, but the high-level architecture stays the same.
12. External datasets and preprocessing
The system depends on external medical datasets rather than a built-in synthetic generator: EndoNeRF, SCARED, and Hamlyn. The repository assumes those datasets are preprocessed into the expected directory layout before training, so data preparation is a separate upstream stage in the pipeline.
13. Outputs and experiment organization
Trained models and rendered artifacts are written under per-experiment output directories such as output/endonerf/pulling. This makes the boundary between “experiment definition” and “experiment results” very explicit, and it is what the evaluation and rendering scripts consume later.
14. Where to draw the architecture diagram
A good diagram would show: dataset inputs on the left; config modules selecting a scene; the scene/data loaders creating cameras and frames; the Gaussian/deformation model in the center; the custom CUDA rasterizer underneath; and training/rendering/evaluation scripts on the right consuming the same model. The journal/ tree can be shown as a parallel, expanded implementation of the same pipeline.
Main entry points: scene Scene layer · train.py Train · render.py Render · journal/train.py Train
Components 22
Root pipeline
Primary EndoGaussian implementation
- Configs · Scene-specific Python argument modules for EndoNeRF and SCARED
arguments - Train · Main optimization entry point
train.py - Render · Offline rendering entry point
render.py - Metrics · Quantitative evaluation entry point
metrics.py - Full eval · Batch evaluation over scenes and checkpoints
full_eval.py - Scene layer · Dataset loading, cameras, deformation, Gaussian model, and regularization
scene - Renderer · Gaussian splatting renderer and live GUI support
gaussian_renderer - Utils · Shared camera, geometry, loss, SH, scene, and system helpers
utils
Journal pipeline
Expanded TMI fork with mirrored architecture
- Configs · Journal scene configs including EndoNeRF, SCARED, and Hamlyn
journal/arguments - Train · Journal training entry point
journal/train.py - Render · Journal offline rendering entry point
journal/render.py - Metrics · Journal quantitative evaluation with LPIPS support
journal/metrics.py - Full eval · Journal batch evaluation entry point
journal/full_eval.py - Scene layer · Journal copy of dataset, camera, deformation, and Gaussian model stack
journal/scene - Renderer · Journal renderer and live GUI support
journal/gaussian_renderer - Utils · Journal helpers for cameras, graphics, losses, SH, params, and timing
journal/utils - LPIPS · LPIPS evaluation module used in journal metrics
journal/lpipsPyTorch - Extract · Journal extraction/export helper
journal/extract.py
Native backend
Performance-critical CUDA extensions
- Rasterizer · Differentiable depth-aware Gaussian rasterization backend
submodules/depth-diff-gaussian-rasterization - KNN · Fast spatial nearest-neighbor queries
submodules/simple-knn
External data
Preprocessed medical datasets and experiment outputs
- Datasets · Preprocessed EndoNeRF, SCARED, and related experiment data
- Outputs · Checkpoints, renders, and evaluation outputs
Connections 24
- Configs → Train: selects · Scene configs parameterize training runs
- Configs → Render: selects · Configs define render-time scene settings
- Datasets → Scene layer: loads · Preprocessed datasets are ingested by the scene layer
- Scene layer → Train: feeds · Scenes provide cameras, frames, and metadata to training
- Scene layer → Render: feeds · Scene objects drive offline rendering
- Scene layer → Renderer: models · Gaussian model and deformation fields are consumed by the renderer
- Renderer → Rasterizer: uses · Renderer delegates splatting to the CUDA rasterizer
- Scene layer → KNN: uses · Spatial queries support scene and model operations
- Utils → Train: supports · Losses, geometry, and system helpers support optimization
- Utils → Render: supports · Shared utilities support rendering and output handling
- Renderer → Train: renders · Training optimizes through rendered outputs
- Train → Outputs: writes · Checkpoints and experiment artifacts are saved per run
- Render → Outputs: writes · Rendered frames and videos are exported
- Metrics → Outputs: reads · Metrics consume rendered outputs and checkpoints
- Full eval → Metrics: drives · Full evaluation orchestrates metric computation
- Configs → Train: selects · Journal configs parameterize training
- Scene layer → Train: feeds · Journal scene layer supplies data and models
- Scene layer → Renderer: models · Journal renderer consumes the same deformable Gaussian world model
- Renderer → Rasterizer: uses · Journal renderer uses the shared CUDA backend
- Utils → Train: supports · Journal training uses shared helper utilities
- Renderer → Train: renders · Journal optimization is driven by rendered outputs
- LPIPS → Metrics: extends · LPIPS is part of journal metric computation
- Render → Outputs: writes · Journal render outputs are saved alongside experiments
- Extract → Outputs: exports · Extraction utility produces additional artifacts