Skip to content

LangSplatv2: Implement mask + CLIP feature transforms#42

Merged
swahtz merged 7 commits intoopenvdb:mainfrom
swahtz:langsplatv2_feature_transforms
Feb 9, 2026
Merged

LangSplatv2: Implement mask + CLIP feature transforms#42
swahtz merged 7 commits intoopenvdb:mainfrom
swahtz:langsplatv2_feature_transforms

Conversation

@swahtz
Copy link
Contributor

@swahtz swahtz commented Jan 28, 2026

Implements the preprocessing pipeline to generate the SAM2 masks and CLIP feature generation as transforms in the same style as garfvdb's implementation.
closes #31

Implement sam2 and clip data transforms that work in a pipeline together to produce the features we need for langsplatv2
closes openvdb#31

Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a LangSplatV2-style preprocessing pipeline by introducing scene transforms to generate multi-scale SAM2 masks and compute CLIP features for masked regions, plus configuration and packaging scaffolding.

Changes:

  • Introduces ComputeMultiScaleSAM2Masks to generate and cache multi-scale SAM2 masks with NMS post-processing.
  • Introduces ComputeCLIPFeatures to encode masked regions with OpenCLIP and cache features + per-scale segmentation maps.
  • Adds LangSplatV2 preprocessing config dataclasses and a new Python package definition.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
open_vocabulary_segmentation/langsplatv2/pyproject.toml Adds packaging metadata and dependencies for the new langsplatv2 module.
open_vocabulary_segmentation/langsplatv2/langsplatv2/scene_transforms/multi_scale_sam_masks.py New transform to compute + cache multi-scale SAM2 masks and apply mask NMS.
open_vocabulary_segmentation/langsplatv2/langsplatv2/scene_transforms/clip_feature_encoding.py New transform to compute + cache CLIP features for masked regions and build segmentation index maps.
open_vocabulary_segmentation/langsplatv2/langsplatv2/scene_transforms/init.py Exposes the new transforms at the package level.
open_vocabulary_segmentation/langsplatv2/langsplatv2/config.py Adds pipeline configuration and a helper to assemble the transform sequence.
instance_segmentation/garfvdb/garfvdb/util.py Refactors RGB→SH conversion to use module-level constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

swahtz and others added 4 commits January 29, 2026 09:21
…nsforms/clip_feature_encoding.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
…nsforms/clip_feature_encoding.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
@swahtz swahtz merged commit bdd5df0 into openvdb:main Feb 9, 2026
8 checks passed
@swahtz swahtz deleted the langsplatv2_feature_transforms branch February 9, 2026 04:11
swahtz added a commit that referenced this pull request Feb 12, 2026
## Summary

Implements the LangSplatV2 training pipeline for learning per-Gaussian
sparse language feature fields using fVDB and fvdb-reality-capture. This
builds on the preprocessing transforms already merged in #42, adding the
model, loss, training loop, and supporting utilities needed to train
language-aware Gaussian splats. closes #32

Key components:

- **Model** (`model.py`): `LangSplatV2Model` wraps a frozen
`GaussianSplat3d` with learnable per-Gaussian logits and codebooks.
Renders sparse coefficient weight maps via splatting and decodes them
into dense CLIP feature maps through codebook lookup.
- **Vector quantization** (`vq_utils.py`): Implements
`softmax_to_topk_soft_code` for efficient sparse coefficient generation
and `ResidualVectorQuantization` for K-means codebook initialization
from ground-truth CLIP features.
- **Loss** (`loss.py`): Cosine similarity and L1 losses with per-pixel
masking for regions without valid language features.
- **Dataset** (`training/dataset.py`): `LangSplatV2Dataset` loads
pre-computed CLIP features and segmentation maps in compact form. Dense
ground-truth feature maps are materialized on-device after transfer
using `build_feature_map`, avoiding large CPU-to-GPU transfers.
- **Training runner** (`training/trainer.py`): `LangSplatV2Training`
handles the full workflow — dataset construction, K-means codebook
initialization, optimizer setup, training/eval loops with gradient
accumulation, and checkpointing.
- **Config** (`config.py`): Extended with `LangSplatV2ModelConfig` and
`LangSplatV2TrainingConfig` dataclasses.
- **Entry point** (`train_langsplatv2.py`): CLI script using `tyro` for
launching training.

### Performance optimizations

- Compact feature storage with `JaggedTensor` for variable-length
per-image features, avoiding padding overhead
- GPU-side dense feature map construction (`build_feature_map`) using
`torch.empty` to eliminate costly zero-fill of ~4 GB tensors

## Test plan

- [x] Run training on a preprocessed scene: `python train_langsplatv2.py
--scene-dir <path> --checkpoint-dir <path>`
- [x] Verify K-means codebook initialization completes and logs cluster
info
- [x] Confirm training loop progresses without OOM on a single GPU
(tested with 1080p images)
- [x] Check that checkpoints are saved and can be resumed
- [x] Profile with Nsight Systems to verify no unexpected data transfer
bottlenecks

---------

Signed-off-by: Jonathan Swartz <jonathan@jswartz.info>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement CLIP feature transform

1 participant