How sanoscience/pr-endo works
Purpose and Entry Points
PR-ENDO is a GPU-based research pipeline for reconstructing endoscopic scenes as physically based, relightable 3D Gaussian splats. Training is orchestrated by run_all.sh and implemented in train_viewdir.py; rendering and evaluation are exposed through render.py, render_light_rotations.py, render_body_movement.py, and metrics.py.
Dataset and Scene Ingestion
Scene loading supports COLMAP-derived and EndoGSLAM-optimized inputs, converting camera calibration, poses, images, and point-cloud data into the internal scene representation. The data boundary is concentrated in:
• scene/dataset_readers.py
• scene/colmap_loader.py
• scene/rnnslam_loader.py
• scene/cameras.py
Gaussian Scene Representation
The trainable scene is a collection of 3D Gaussians with geometry, appearance, and relighting-related parameters. scene/gaussian_model.py owns this representation and its optimization-facing state. It is paired with neural components in scene/mlp.py, including the diffuse/view-light modeling needed to separate tissue properties from illumination.
Differentiable Rendering and Relighting
gaussian_renderer/__init__.py is the rendering integration boundary: it projects and shades the Gaussian model from a camera viewpoint and produces training/render outputs. Its CUDA-backed rasterization and spatial-neighbor operations come from installed submodules:
• submodules/depth-diff-gaussian-rasterization
• submodules/simple-knn
• submodules/gaussian-norms
The renderer consumes camera state, Gaussian attributes, lighting/view directions, and MLP outputs; gradients flow back to Gaussian and neural parameters during training.
Training Control Flow
train_viewdir.py drives iterative optimization: load a scene, select training cameras, render predicted frames, calculate image/reconstruction losses, and update Gaussian/MLP parameters. Training-specific operations such as scheduling, densification/pruning support, and loss-related utilities are organized under:
• utils/train_utils.py
• utils/loss_utils.py
• utils/general_utils.py
arguments/__init__.py centralizes command-line parameter grouping for the executable scripts.
Output Modes
Standard novel-view output is produced by render.py. Two specialized rendering paths expose the paper’s controllable effects:
• render_light_rotations.py changes light direction/spotlight settings while preserving scene properties.
• render_body_movement.py applies Gaussian reparameterization-based body-motion simulation.
Camera trajectories and viewpoint construction are supported by utils/camera_utils.py and utils/spiral_utils.py; illumination/view calculations are supported by utils/gaussian_viewing_utils.py.
Runtime and External Dependencies
The system targets Python 3.10, PyTorch 2.1, CUDA 12.1, and an NVIDIA GPU. It depends on custom CUDA extensions for differentiable Gaussian rasterization, KNN, and normal estimation; FAISS GPU for accelerated similarity/search operations; and Tiny-CUDA-NN for optional HashGrid support. Source datasets are externally preprocessed C3VD/EndoGSLAM and RotateColon scene directories, configured through run_all.sh.
Main entry points: __init__.py Gaussian renderer · train_viewdir.py Training loop · gaussian_model.py Gaussian scene model · dataset_readers.py Dataset readers
Components 19
Entrypoints
- Pipeline launcher · Configures datasets and runs reconstruction stages.
run_all.sh - CLI parameters
arguments/__init__.py - Training loop · Iteratively renders, computes losses, and updates scene parameters.
train_viewdir.py
Scene and learning
- Dataset readers · Converts supported source formats into the internal scene.
scene/dataset_readers.py - COLMAP loader
scene/colmap_loader.py - EndoGSLAM loader
scene/rnnslam_loader.py - Camera state
scene/cameras.py - Gaussian scene model · Owns geometry, appearance, relighting, and optimization state.
scene/gaussian_model.py - Appearance MLPs · Models diffuse and view/light-dependent appearance.
scene/mlp.py - Optimization utilities · Scheduling, densification, pruning, losses, and general utilities.
utils/train_utils.py
Differentiable rendering
- Gaussian renderer · Projects and shades splats, producing differentiable frame outputs.
gaussian_renderer/__init__.py - CUDA extensions · Rasterization, spatial KNN, and normal estimation.
submodules/depth-diff-gaussian-rasterization - View and lighting utilities
utils/gaussian_viewing_utils.py
Rendering modes
- Camera trajectory utilities
utils/camera_utils.py - Novel-view renderer
render.py - Light rotation renderer · Changes illumination while preserving scene properties.
render_light_rotations.py - Body movement renderer · Applies Gaussian reparameterization-based body-motion simulation.
render_body_movement.py - Evaluation
metrics.py
Other components
- External scene datasets · C3VD, EndoGSLAM, and RotateColon scene directories.
Connections 26
- Pipeline launcher → Training loop: launches
- Pipeline launcher → External scene datasets: configures
- CLI parameters → Training loop: configures
- External scene datasets → Dataset readers: source scenes
- COLMAP loader → Dataset readers: COLMAP input
- EndoGSLAM loader → Dataset readers: EndoGSLAM input
- Dataset readers → Camera state: builds
- Dataset readers → Gaussian scene model: initializes
- Training loop → Gaussian renderer: renders iterations
- Camera state → Gaussian renderer: viewpoint
- Gaussian scene model → Gaussian renderer: splat attributes
- Appearance MLPs → Gaussian renderer: shading outputs
- View and lighting utilities → Gaussian renderer: view/light directions
- CUDA extensions → Gaussian renderer: GPU kernels
- Gaussian renderer → Training loop: frames and gradients
- Optimization utilities → Training loop: optimization support
- Training loop → Gaussian scene model: updates
- Training loop → Appearance MLPs: updates
- Gaussian scene model → Novel-view renderer: trained scene
- Gaussian scene model → Light rotation renderer: trained scene
- Gaussian scene model → Body movement renderer: trained scene
- Camera trajectory utilities → Novel-view renderer: camera paths
- Gaussian renderer → Novel-view renderer: render backend
- Gaussian renderer → Light rotation renderer: render backend
- Gaussian renderer → Body movement renderer: render backend
- Novel-view renderer → Evaluation: rendered outputs