Instructions to use bf0820/VQ-SAM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use bf0820/VQ-SAM with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("bf0820/VQ-SAM") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained("bf0820/VQ-SAM") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>) # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: mask-generation
|
| 4 |
+
library_name: sam2
|
| 5 |
+
tags:
|
| 6 |
+
- visual-query-segmentation
|
| 7 |
+
- video-object-segmentation
|
| 8 |
+
- sam2
|
| 9 |
+
- vqs
|
| 10 |
+
datasets:
|
| 11 |
+
- bf0820/VQS-4K
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# VQ-SAM
|
| 15 |
+
|
| 16 |
+
Baseline checkpoint for **visual query segmentation (VQS)** from the NeurIPS 2026
|
| 17 |
+
Datasets & Benchmarks paper [*Towards Visual Query Segmentation in the
|
| 18 |
+
Wild*](https://arxiv.org/pdf/2603.08898).
|
| 19 |
+
|
| 20 |
+
Given an untrimmed video and a **visual query** — one image plus a mask of the target, taken
|
| 21 |
+
from **outside** that video — VQ-SAM segments the object in every frame where it appears.
|
| 22 |
+
It extends SAM 2 with a spatio-temporal transformer block and target / distractor memory
|
| 23 |
+
evolved through a multi-stage framework with an adaptive memory generation (AMG) module.
|
| 24 |
+
|
| 25 |
+
- 📄 Paper: [arXiv:2603.08898](https://arxiv.org/pdf/2603.08898)
|
| 26 |
+
- 💻 Code: [github.com/VAIL-Fan/VQS](https://github.com/VAIL-Fan/VQS)
|
| 27 |
+
- 📦 Dataset: [bf0820/VQS-4K](https://huggingface.co/datasets/bf0820/VQS-4K)
|
| 28 |
+
|
| 29 |
+
## Results on VQS-4K test (822 videos)
|
| 30 |
+
|
| 31 |
+
| mSTIoU | mSTIoU₅₀ | mSTIoU₇₅ | mTIoU | mTIoU₅₀ | mTIoU₇₅ | Rec | Succ | FPS |
|
| 32 |
+
|---|---|---|---|---|---|---|---|---|
|
| 33 |
+
| 26.0 | 23.8 | 12.7 | 29.6 | 26.8 | 14.4 | 43.6 | 42.1 | 29 |
|
| 34 |
+
|
| 35 |
+
Best published result on this benchmark; the strongest prior method (SAM2Long) reaches
|
| 36 |
+
18.6 mSTIoU. These numbers are reproducible from this checkpoint with the evaluation code in
|
| 37 |
+
the repository.
|
| 38 |
+
|
| 39 |
+
## Files
|
| 40 |
+
|
| 41 |
+
| File | Description |
|
| 42 |
+
|---|---|
|
| 43 |
+
| `vqsam_hiera_bplus.pt` | VQ-SAM, SAM 2.1 Hiera-B+ backbone, trained on the VQS-4K train split (1.0 GB) |
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
git clone https://github.com/VAIL-Fan/VQS && cd VQS
|
| 49 |
+
pip install -r requirements.txt && pip install -e .
|
| 50 |
+
|
| 51 |
+
python - <<'PY'
|
| 52 |
+
from huggingface_hub import hf_hub_download
|
| 53 |
+
hf_hub_download("bf0820/VQ-SAM", "vqsam_hiera_bplus.pt", local_dir="checkpoints")
|
| 54 |
+
PY
|
| 55 |
+
|
| 56 |
+
python tools/test_video_segmentation.py \
|
| 57 |
+
--sam2_cfg sam2/configs/sam2.1_training/sam2.1_hiera_b+_DAM_AdaptiveGate_Jan28.yaml \
|
| 58 |
+
--sam2_checkpoint checkpoints/vqsam_hiera_bplus.pt \
|
| 59 |
+
--base_video_dir ./data/VQS-4K/images \
|
| 60 |
+
--input_mask_dir ./data/VQS-4K/masks \
|
| 61 |
+
--video_list_file ./splits/test_t-IoU.txt \
|
| 62 |
+
--output_mask_dir ./outputs/predictions \
|
| 63 |
+
--num_frames_per_segment 8
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
The inference segment length must match the training clip length (8 for this checkpoint).
|
| 67 |
+
|
| 68 |
+
## Training
|
| 69 |
+
|
| 70 |
+
SAM 2.1 Hiera-B+ initialisation, 768x768, 8 frames per clip (1 query + 7 video), batch size 1
|
| 71 |
+
per GPU, on 4x RTX A6000. Config
|
| 72 |
+
`sam2.1_hiera_b+_DAM_AdaptiveGate_Jan28.yaml` in the repository, with two-stage memory,
|
| 73 |
+
distractor memory, quality-weighted RAM and adaptive gating enabled.
|
| 74 |
+
|
| 75 |
+
## License
|
| 76 |
+
|
| 77 |
+
Code and weights: Apache 2.0, inherited from [SAM 2](https://github.com/facebookresearch/sam2).
|
| 78 |
+
The VQS-4K dataset is separately licensed CC BY-NC 4.0, research use only.
|
| 79 |
+
|
| 80 |
+
## Citation
|
| 81 |
+
|
| 82 |
+
```bibtex
|
| 83 |
+
@inproceedings{fan2026vqs,
|
| 84 |
+
title = {Towards Visual Query Segmentation in the Wild},
|
| 85 |
+
author = {Fan, Bing and Li, Minghao and Zhang, Hanzhi and Dong, Shaohua and
|
| 86 |
+
Mareedu, Naga Prudhvi and Liu, Xiaoqiong and Shi, Weishi and
|
| 87 |
+
Feng, Yunhe and Huang, Yan and Fan, Heng},
|
| 88 |
+
booktitle = {Advances in Neural Information Processing Systems (NeurIPS)
|
| 89 |
+
Datasets and Benchmarks Track},
|
| 90 |
+
year = {2026},
|
| 91 |
+
eprint = {2603.08898},
|
| 92 |
+
archivePrefix = {arXiv}
|
| 93 |
+
}
|
| 94 |
+
```
|