Views
No views yet
| Model | JA-VG-VQA-500 (ROUGE-L) | JA-VLM-Bench-In-the-Wild (ROUGE-L) | Heron-Bench(Detail) | Heron-Bench(Conv) | Heron-Bench(Complex) | Heron-Bench(Average) |
|---|---|---|---|---|---|---|
| Japanese Stable VLM | - | 40.50 | 25.15 | 51.23 | 37.84 | 38.07 |
| EvoVLM-JP-v1-7B | 19.70 | 51.25 | 50.31 | 44.42 | 40.47 | 45.07 |
| Heron BLIP Japanese StableLM Base 7B llava-620k | 14.51 | 33.26 | 49.09 | 41.51 | 45.72 | 45.44 |
| Heron GIT Japanese StableLM Base 7B | 15.18 | 37.82 | 42.77 | 54.20 | 43.53 | 46.83 |
| llava-jp-1.3b-v1.1 | 13.33 | 44.40 | 50.00 | 51.83 | 48.98 | 50.39 |
| llava-jp-1.3b-v1.1-llava-jp-instruct-108k | - | 17.07 | 50.60 | 45.31 | 33.24 | 41.52 |

git clone https://github.com/tosiyuki/LLaVA-JP.git1import torch
2import transformers
3from PIL import Image
4
5from transformers.generation.streamers import TextStreamer
6from llava.constants import DEFAULT_IMAGE_TOKEN, IMAGE_TOKEN_INDEX
7from llava.conversation import conv_templates, SeparatorStyle
8from llava.model.llava_gpt2 import LlavaGpt2ForCausalLM
9from llava.train.dataset import tokenizer_image_token
10
11
12if __name__ == "__main__":
13 model_path = 'toshi456/llava-jp-1.3b-v1.1-llava-jp-instruct-108k'
14 device = "cuda" if torch.cuda.is_available() else "cpu"
15 torch_dtype = torch.bfloat16 if device=="cuda" else torch.float32
16
17 model = LlavaGpt2ForCausalLM.from_pretrained(
18 model_path,
19 low_cpu_mem_usage=True,
20 use_safetensors=True,
21 torch_dtype=torch_dtype,
22 device_map=device,
23 )
24 tokenizer = transformers.AutoTokenizer.from_pretrained(
25 model_path,
26 model_max_length=1532,
27 padding_side="right",
28 use_fast=False,
29 )
30 model.eval()
31
32 conv_mode = "v1"
33 conv = conv_templates[conv_mode].copy()
34
35 # image pre-process
36 image_url = "https://huggingface.co/rinna/bilingual-gpt-neox-4b-minigpt4/resolve/main/sample.jpg"
37 image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
38
39 image_size = model.get_model().vision_tower.image_processor.size["height"]
40 if model.get_model().vision_tower.scales is not None:
41 image_size = model.get_model().vision_tower.image_processor.size["height"] * len(model.get_model().vision_tower.scales)
42
43 if device == "cuda":
44 image_tensor = model.get_model().vision_tower.image_processor(
45 image,
46 return_tensors='pt',
47 size={"height": image_size, "width": image_size}
48 )['pixel_values'].half().cuda().to(torch_dtype)
49 else:
50 image_tensor = model.get_model().vision_tower.image_processor(
51 image,
52 return_tensors='pt',
53 size={"height": image_size, "width": image_size}
54 )['pixel_values'].to(torch_dtype)
55
56 # create prompt
57 # ユーザー: <image>\n{prompt}
58 prompt = "画像について説明してください。"
59 inp = DEFAULT_IMAGE_TOKEN + '\n' + prompt
60 conv.append_message(conv.roles[0], inp)
61 conv.append_message(conv.roles[1], None)
62 prompt = conv.get_prompt()
63
64 input_ids = tokenizer_image_token(
65 prompt,
66 tokenizer,
67 IMAGE_TOKEN_INDEX,
68 return_tensors='pt'
69 ).unsqueeze(0)
70 if device == "cuda":
71 input_ids = input_ids.to(device)
72
73 input_ids = input_ids[:, :-1] # </sep>がinputの最後に入るので削除する
74 stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
75 keywords = [stop_str]
76 streamer = TextStreamer(tokenizer, skip_prompt=True, timeout=20.0)
77
78 # predict
79 with torch.inference_mode():
80 output_id = model.generate(
81 inputs=input_ids,
82 images=image_tensor,
83 do_sample=False,
84 temperature=1.0,
85 top_p=1.0,
86 no_repeat_ngram_size=2,
87 max_new_tokens=256,
88 streamer=streamer,
89 use_cache=True,
90 )
91
92 """グレーの壁に置かれた木製のテーブルの上に、茶色のタビーの猫が横たわっている。猫は右を向いており、頭は左を向き、尻尾は体の前に突き出ているように見える。テーブルは木製で、猫の後ろには黒い金属製の脚があり、テーブルの下には小さな緑の植物が置かれる。<EOD|LLM-jp>"""