🚀 ConvLLaVA-JP模型卡片
ConvLLaVA-JP是一款視覺語言模型,能夠針對輸入的圖像進行對話交流。該模型使用特定的圖像編碼器和文本解碼器進行訓練,支持高分辨率圖像輸入。以下是關於該模型的詳細介紹。
🚀 快速開始
下載依賴
git clone https://github.com/tosiyuki/LLaVA-JP.git
推理示例
import requests
import torch
import transformers
from PIL import Image
from transformers.generation.streamers import TextStreamer
from llava.constants import DEFAULT_IMAGE_TOKEN, IMAGE_TOKEN_INDEX
from llava.conversation import conv_templates, SeparatorStyle
from llava.model.llava_gpt2 import LlavaGpt2ForCausalLM
from llava.train.dataset import tokenizer_image_token
if __name__ == "__main__":
model_path = 'toshi456/ConvLLaVA-JP-1.3b-1280'
device = "cuda" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.bfloat16 if device=="cuda" else torch.float32
model = LlavaGpt2ForCausalLM.from_pretrained(
model_path,
low_cpu_mem_usage=True,
use_safetensors=True,
torch_dtype=torch_dtype,
device_map=device,
)
tokenizer = transformers.AutoTokenizer.from_pretrained(
model_path,
model_max_length=1532,
padding_side="right",
use_fast=False,
)
model.eval()
conv_mode = "v1"
conv = conv_templates[conv_mode].copy()
image_url = "https://huggingface.co/rinna/bilingual-gpt-neox-4b-minigpt4/resolve/main/sample.jpg"
image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
if device == "cuda":
image_tensor = model.get_model().vision_tower.image_processor(image).unsqueeze(0).half().cuda().to(torch_dtype)
else:
image_tensor = model.get_model().vision_tower.image_processor(image).unsqueeze(0).to(torch_dtype)
prompt = "貓の隣には何がありますか?"
inp = DEFAULT_IMAGE_TOKEN + '\n' + prompt
conv.append_message(conv.roles[0], inp)
conv.append_message(conv.roles[1], None)
prompt = conv.get_prompt()
input_ids = tokenizer_image_token(
prompt,
tokenizer,
IMAGE_TOKEN_INDEX,
return_tensors='pt'
).unsqueeze(0)
if device == "cuda":
input_ids = input_ids.to(device)
input_ids = input_ids[:, :-1]
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
keywords = [stop_str]
streamer = TextStreamer(tokenizer, skip_prompt=True, timeout=20.0)
with torch.inference_mode():
output_id = model.generate(
inputs=input_ids,
images=image_tensor,
do_sample=False,
temperature=1.0,
top_p=1.0,
max_new_tokens=256,
streamer=streamer,
use_cache=True,
)
"""貓の隣にはノートパソコンがあります。"""
✨ 主要特性
📦 安裝指南
下載項目依賴:
git clone https://github.com/tosiyuki/LLaVA-JP.git
📚 詳細文檔
更多信息請參考:https://github.com/tosiyuki/LLaVA-JP/tree/main
📄 許可證
本模型使用的許可證為cc-by-nc-4.0。