How robbyant/lingbot-map works
1. What this repo is
LingBot-Map is a PyTorch-based package for streaming 3D reconstruction from image sequences or video. The architecture is centered around a feed-forward geometric context transformer that predicts camera/scene structure incrementally, rather than doing iterative optimization.
2. Primary entry point and orchestration
demo.py is the main end-to-end runner. It loads a checkpoint, reads frames from --image_folder or --video_path, runs streaming inference, and sends reconstructed outputs to a browser-based viser viewer. The demo also controls runtime modes such as keyframe caching, windowed inference, offloading to CPU, and optional sky masking.
3. Model subsystem
The lingbot_map/models package contains three major model variants:
- gct_base.py: base geometric context transformer model
- gct_stream.py: streaming inference model
- gct_stream_window.py: long-sequence/windowed variant for very long videos
These are the architectural core of the repo and likely define the forward pass, state handling, and how predictions are produced frame-by-frame.
4. Transformer and sequence modeling internals
lingbot_map/layers holds the low-level building blocks that implement the transformer stack:
- attention, RoPE, flashinfer cache, and drop-path utilities
- patch embedding and vision transformer backbone pieces
- MLP/SwiGLU feed-forward blocks, layer scale, and residual blocks
This is the main compute path for feature extraction and long-range temporal memory. The presence of flashinfer_cache.py indicates support for paged KV-cache attention for efficient streaming.
5. Geometric prediction heads
lingbot_map/heads contains task-specific output heads:
- camera_head.py for camera/pose estimation or pose refinement
- dpt_head.py for dense depth prediction
- head_act.py and utilities for activation/output shaping
These heads convert transformer features into the 3D reconstruction outputs consumed by downstream visualization or export.
6. Streaming memory and aggregation
lingbot_map/aggregator appears to manage how per-frame features and state are accumulated across time:
- base.py likely defines a common aggregation interface
- stream.py likely implements the streaming memory / cache policy
This is an important boundary: the model does not just process independent frames; it maintains temporal context, keyframes, and/or windowed state across long sequences.
7. Geometry and pose utilities
lingbot_map/utils contains mathematical helpers that support the reconstruction pipeline:
- geometry.py for projection/backprojection and coordinate transforms
- rotation.py for pose/rotation conversions
- pose_enc.py for pose encoding / pose-reference features
- load_fn.py for checkpoint or asset loading
These utilities form the bridge between neural predictions and explicit 3D geometry.
8. Inference modes and sequence scaling
The README describes three operational regimes that map to the model structure:
- normal streaming over ordinary sequences
- keyframe interval mode to reduce KV-cache growth
- windowed inference for very long sequences
This suggests the repo is designed around maintaining bounded memory while still supporting long-horizon reconstruction.
9. Visualization and export boundary
lingbot_map/vis is a separate output/inspection layer, not part of the model:
- viser_wrapper.py connects to the browser viewer
- point_cloud_viewer.py handles point-cloud rendering
- glb_export.py exports reconstructed scenes to GLB
- sky_segmentation.py and utils.py support visualization cleanup and tooling
This keeps the reconstruction core separate from UI and export concerns.
10. Optional sky masking pipeline
For outdoor scenes, the repo can run ONNX-based sky segmentation before visualization. That path depends on onnxruntime and a downloaded skyseg.onnx model. It is a preprocessing/postprocessing concern, not part of the main transformer.
11. Runtime and acceleration dependencies
The repo is built on PyTorch and optionally FlashInfer. FlashInfer is used for efficient streaming attention; if it is unavailable, the code can fall back to PyTorch SDPA. This is a meaningful architectural choice because it directly affects streaming throughput and sequence length scalability.
12. Examples and packaged assets
example/ contains ready-to-run scene folders used by the demo, and assets/ holds README imagery. The repository is packaged via pyproject.toml, making the codebase both a library (lingbot_map) and a runnable demo application.
13. High-level data flow
The practical pipeline is:
input frames/video -> optional sky mask generation -> streaming model inference with temporal cache -> camera/depth/3D reconstruction outputs -> point cloud / GLB / browser visualization.
The main architectural boundaries are therefore between input preprocessing, the transformer-based reconstruction core, temporal aggregation/state, and visualization/export.
Main entry points: gct_stream.py Streaming GCT · demo.py Demo · vision_transformer.py Transformer · camera_head.py Camera Head
Components 20
Runtime
End-to-end demo and inference orchestration
- Demo · Main end-to-end entry point for streaming reconstruction
demo.py - Load Helpers · Checkpoint and asset loading helpers
lingbot_map/utils/load_fn.py
Model Core
Streaming reconstruction model and temporal state
- Streaming GCT · Primary streaming reconstruction model
lingbot_map/models/gct_stream.py - Base GCT · Shared geometric context transformer core
lingbot_map/models/gct_base.py - Window GCT · Long-sequence windowed streaming variant
lingbot_map/models/gct_stream_window.py - Aggregator API · Common interface for temporal aggregation
lingbot_map/aggregator/base.py - Stream Cache · Streaming memory and keyframe accumulation policy
lingbot_map/aggregator/stream.py - Transformer · Vision transformer backbone and block stack
lingbot_map/layers/vision_transformer.py - Patch Embed · Image tokenization and feature projection
lingbot_map/layers/patch_embed.py - Attention · Attention and rotary-positioned sequence mixing
lingbot_map/layers/attention.py - KV Cache · Paged cache support for efficient streaming attention
lingbot_map/layers/flashinfer_cache.py - Camera Head · Camera and pose output head
lingbot_map/heads/camera_head.py - Depth Head · Dense depth prediction head
lingbot_map/heads/dpt_head.py
Geometry
Geometric helpers and pose representations
- Geometry Utils · Projection, backprojection, and coordinate transforms
lingbot_map/utils/geometry.py - Rotation Utils · Pose and rotation conversions
lingbot_map/utils/rotation.py - Pose Encoding · Pose feature encoding for model inputs
lingbot_map/utils/pose_enc.py
Output
Visualization, export, and optional masking
- Viser Viewer · Browser-based live visualization bridge
lingbot_map/vis/viser_wrapper.py - Point Cloud · Point-cloud rendering and inspection
lingbot_map/vis/point_cloud_viewer.py - GLB Export · Scene export to GLB
lingbot_map/vis/glb_export.py - Sky Mask · Optional sky segmentation for outdoor scenes
lingbot_map/vis/sky_segmentation.py
Connections 19
- Demo → Load Helpers: loads · Loads checkpoints and runtime assets
- Demo → Sky Mask: optional · Applies sky masking when enabled
- Demo → Streaming GCT: runs · Executes streaming reconstruction inference
- Demo → Viser Viewer: visualizes · Streams reconstructed outputs to the browser viewer
- Streaming GCT → Base GCT: extends · Builds on the shared geometric transformer core
- Window GCT → Streaming GCT: variant · Adds long-sequence windowed streaming behavior
- Streaming GCT → Stream Cache: uses · Maintains temporal memory and keyframe state
- Stream Cache → Aggregator API: implements · Concrete streaming policy behind the aggregator API
- Base GCT → Transformer: contains · Main transformer backbone path
- Transformer → Patch Embed: starts with · Converts frames into patch tokens
- Transformer → Attention: mixes · Performs token and temporal attention
- Attention → KV Cache: accelerates · Supports streaming KV-cache attention
- Streaming GCT → Camera Head: predicts · Produces camera and pose estimates
- Streaming GCT → Depth Head: predicts · Produces dense depth outputs
- Streaming GCT → Pose Encoding: conditions on · Uses pose encoding as geometric context
- Camera Head → Geometry Utils: uses · Converts model outputs into 3D geometry
- Camera Head → Rotation Utils: uses · Handles pose and rotation parameterization
- Demo → Point Cloud: renders · Displays reconstructed point clouds
- Demo → GLB Export: exports · Writes scene exports for downstream use