1import torch
2from transformers import AutoModel, AutoTokenizer
3from PIL import Image
4
5path = "HarborYuan/Sa2VA-LLaVA-1.5-7B"
6model = AutoModel.from_pretrained(
7 path, torch_dtype=torch.bfloat16, trust_remote_code=True, low_cpu_mem_usage=True,
8).eval().cuda()
9tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
10
11image = Image.open("your_image.jpg").convert("RGB")
12out = model.predict_forward(
13 image=image,
14 text="<image>Please segment the dog in the image.",
15 tokenizer=tokenizer,
16)
17print(out["prediction"]) # text response containing [SEG]
18masks = out["prediction_masks"] # list of boolean masks at the original image size
1@article{sa2va,
2 title={Sa2VA: Marrying SAM2 with LLaVA for Dense Grounded Understanding of Images and Videos},
3 author={Yuan, Haobo and Li, Xiangtai and Zhang, Tao and Sun, Yueyi and Huang, Zilong and Xu, Shilin and Ji, Shunping and Tong, Yunhai and Qi, Lu and Feng, Jiashi and Yang, Ming-Hsuan},
4 journal={IEEE TPAMI},
5 year={2026}
6}