Views
No views yet
| Model Name | Base MLLM | Language Part | HF Link |
|---|---|---|---|
| Sa2VA-1B | InternVL2.5-1B | Qwen2.5-0.5B-Instruct | 🤗 link |
| Sa2VA-4B | InternVL2.5-4B | Qwen2.5-3B-Instruct | 🤗 link |
| Sa2VA-8B | InternVL2.5-8B | internlm2_5-7b-chat | 🤗 link |
| Sa2VA-26B | InternVL2.5-26B | internlm2_5-20b-chat | 🤗 link |
| Model Name | MME | MMBench | RefCOCO | RefCOCO+ | RefCOCOg | MeVIS (val_u) | DAVIS |
|---|---|---|---|---|---|---|---|
| Sa2VA-1B | 1504/434 | 71.9 | 79.6 | 73.6 | 77.7 | 53.4 | 69.5 |
| Sa2VA-4B | 1691/610 | 81.8 | 82.4 | 77.6 | 79.7 | 55.9 | 73.7 |
| Sa2VA-8B | 1690/610 | 84.4 | 82.6 | 78.0 | 80.3 | 58.9 | 75.9 |
| Sa2VA-26B | 1698/653 | 85.8 | 82.9 | 79.3 | 81.2 | 61.8 | 78.6 |
Sa2VA using transformers.1import torch
2from transformers import AutoTokenizer, AutoModel
3from PIL import Image
4import numpy as np
5import os
6
7# load the model and tokenizer
8path = "ByteDance/Sa2VA-1B"
9model = AutoModel.from_pretrained(
10 path,
11 torch_dtype=torch.bfloat16,
12 low_cpu_mem_usage=True,
13 use_flash_attn=True,
14 trust_remote_code=True).eval().cuda()
15tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
16
17# for image chat
18image_path = "/PATH/TO/IMAGE"
19text_prompts = "<image>Please describe the image."
20image = Image.open(image_path).convert('RGB')
21input_dict = {
22 'image': image,
23 'text': text_prompts,
24 'past_text': '',
25 'mask_prompts': None,
26 'tokenizer': tokenizer,
27 }
28return_dict = model.predict_forward(**input_dict)
29answer = return_dict["prediction"] # the text format answer
30
31# for image chat with segmentation output
32image_path = "/PATH/TO/IMAGE"
33text_prompts = "<image>Could you please give me a brief description of the image? Please respond with interleaved segmentation masks for the corresponding parts of the answer."
34image = Image.open(image_path).convert('RGB')
35input_dict = {
36 'image': image,
37 'text': text_prompts,
38 'past_text': '',
39 'mask_prompts': None,
40 'tokenizer': tokenizer,
41 }
42return_dict = model.predict_forward(**input_dict)
43answer = return_dict["prediction"] # the text format answer
44masks = return_dict['prediction_masks'] # segmentation masks, list(np.array(1, h, w), ...)
45
46# for chat with visual prompt (mask format) input
47mask_prompts = np.load('/PATH/TO/pred_masks.npy') # np.array(n_prompts, h, w)
48image_path = "/PATH/TO/IMAGE"
49text_prompts = "<image>Can you provide me with a detailed description of the region in the picture marked by region1."
50image = Image.open(image_path).convert('RGB')
51input_dict = {
52 'image': image,
53 'text': text_prompts,
54 'past_text': '',
55 'mask_prompts': mask_prompts,
56 'tokenizer': tokenizer,
57 }
58return_dict = model.predict_forward(**input_dict)
59answer = return_dict["prediction"] # the text format answer
60
61# for video chat
62video_folder = "/PATH/TO/VIDEO_FOLDER"
63images_paths = os.listdir(video_folder)
64images_paths = [os.path.join(video_folder, image_path) for image_name in images_paths]
65if len(images_paths) > 5: # uniformly sample 5 frames
66 step = (len(images_paths) - 1) // (5 - 1)
67 images_paths = [images_paths[0]] + images_paths[1:-1][::step][1:] + [images_paths[-1]]
68text_prompts = "<image>Please describe the video."
69input_dict = {
70 'video': images_paths,
71 'text': text_prompts,
72 'past_text': '',
73 'mask_prompts': None,
74 'tokenizer': tokenizer,
75}
76return_dict = model.predict_forward(**input_dict)
77answer = return_dict["prediction"] # the text format answer
78
79
80# for video chat with segmentation mask output
81video_folder = "/PATH/TO/VIDEO_FOLDER"
82images_paths = os.listdir(video_folder)
83images_paths = [os.path.join(video_folder, image_path) for image_name in images_paths]
84text_prompts = "<image>Please segment the person."
85input_dict = {
86 'video': images_paths,
87 'text': text_prompts,
88 'past_text': '',
89 'mask_prompts': None,
90 'tokenizer': tokenizer,
91}
92return_dict = model.predict_forward(**input_dict)
93answer = return_dict["prediction"] # the text format answer
94masks = return_dict['prediction_masks'] # segmentation masks, list(np.array(n_frames, h, w), ...)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 Huang, Zilong Huang and Xu, Shilin and Ji, Shunping and Tong, Yunhai and Qi, Lu and Feng, Jiashi and Yang, Ming-Hsuan},
4 journal={arXiv preprint},
5 year={2025}
6}