Instructions to use yujunwei04/UnSAMv2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use yujunwei04/UnSAMv2 with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained(yujunwei04/UnSAMv2) 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(yujunwei04/UnSAMv2) 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
UnSAMv2: Self-Supervised Learning Enables Segment Anything at Any Granularity
Project Page | arXiv | Code | Demo
UnSAMv2 adds granularity control to promptable segmentation. Alongside the usual point or box prompt, you pass a continuous granularity scalar that selects how fine or coarse the returned mask should be, letting a single model move smoothly from whole objects down to their parts without retraining or prompt engineering.
The model is trained without any human labels. A granularity-aware divide-and-conquer pipeline mines mask–granularity pairs from unlabeled images, and those pseudo-labels supervise a lightweight granularity embedding added to SAM 2.
Checkpoints
| File | Description | NoC80 ↓ | NoC90 ↓ | 1-IoU ↑ | AR1000 ↑ |
|---|---|---|---|---|---|
unsamv2.pt |
UnSAMv2 | 2.28 | 3.40 | 79.3 | 68.3 |
unsamv2_plus.pt |
UnSAMv2+, trained on more unlabeled data | 2.07 | 3.10 | 81.7 | 74.1 |
For reference, SAM 2 scores 2.44 / 3.63 / 69.0 / 49.6 on the same metrics.
Both checkpoints are fine-tuned from SAM 2.1 Hiera-Small (46.4M parameters) and are
saved in the SAM 2 training format, with the weights under the model key.
Usage
Install the code from the UnSAMv2 repository, then download a checkpoint:
from huggingface_hub import hf_hub_download
ckpt = hf_hub_download("yujunwei04/UnSAMv2", "unsamv2_plus.pt")
Load it the way the repository's notebooks do, passing a granularity scalar alongside your point or box prompt. The repository covers interactive segmentation, whole-image segmentation, and video segmentation.
Training data
Self-supervised pseudo-labels mined from unlabeled images. No human segmentation annotations were used to train these checkpoints.
License
Released under the Apache License 2.0.
Citation
@article{yu2025unsamv2,
title={UnSAMv2: Self-Supervised Learning Enables Segment Anything at Any Granularity},
author={Yu, Junwei and Darrell, Trevor and Wang, XuDong},
journal={arXiv preprint arXiv:2511.13714},
year={2025}
}
- Downloads last month
- 80
Model tree for yujunwei04/UnSAMv2
Base model
facebook/sam2.1-hiera-small