🚀 SpatialBot - 具備空間理解能力的視覺語言模型
SpatialBot是一款具備空間理解和推理能力的視覺語言模型(VLM),它能夠精準理解深度圖,並利用這些信息執行高級任務。在這個Hugging Face倉庫中,我們提供了基於Phi - 2和SigLIP的SpatialBot - 3B合併模型。該模型在一般的VLM任務以及像SpatialBench這樣的空間理解基準測試中表現出色。
🚀 快速開始
⚠️ 重要提示
我們在2024年8月28日更新了倉庫和快速啟動代碼。如果您在此日期之前下載了模型和代碼,請進行更新。
📦 安裝指南
首先,安裝依賴項:
pip install torch transformers accelerate pillow numpy
💻 使用示例
基礎用法
運行模型的代碼如下:
import torch
import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
from PIL import Image
import warnings
import numpy as np
transformers.logging.set_verbosity_error()
transformers.logging.disable_progress_bar()
warnings.filterwarnings('ignore')
device = 'cuda'
model_name = 'RussRobin/SpatialBot-3B'
offset_bos = 0
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map='auto',
trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(
model_name,
trust_remote_code=True)
prompt = 'What is the depth value of point <0.5,0.2>? Answer directly from depth map.'
text = f"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image 1>\n<image 2>\n{prompt} ASSISTANT:"
text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image 1>\n<image 2>\n')]
input_ids = torch.tensor(text_chunks[0] + [-201] + [-202] + text_chunks[1][offset_bos:], dtype=torch.long).unsqueeze(0).to(device)
image1 = Image.open('rgb.jpg')
image2 = Image.open('depth.png')
channels = len(image2.getbands())
if channels == 1:
img = np.array(image2)
height, width = img.shape
three_channel_array = np.zeros((height, width, 3), dtype=np.uint8)
three_channel_array[:, :, 0] = (img // 1024) * 4
three_channel_array[:, :, 1] = (img // 32) * 8
three_channel_array[:, :, 2] = (img % 32) * 8
image2 = Image.fromarray(three_channel_array, 'RGB')
image_tensor = model.process_images([image1,image2], model.config).to(dtype=model.dtype, device=device)
output_ids = model.generate(
input_ids,
images=image_tensor,
max_new_tokens=100,
use_cache=True,
repetition_penalty=1.0
)[0]
print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
📚 詳細文檔
相關論文
點擊查看
GitHub倉庫
點擊查看
基準測試SpatialBench
點擊查看
帶有LoRA的SpatialBot - 3B檢查點
點擊查看
📄 許可證
本項目採用CC - BY - 4.0許可證。