Views
No views yet
1import torch
2from huggingface_hub import hf_hub_download
3from transformers import PaliGemmaForConditionalGeneration, PaliGemmaProcessor
4
5BASE = "google/paligemma2-3b-mix-448"
6REPO = "lhzzzzzy/HiSpatial-3B-RGB"
7
8model = PaliGemmaForConditionalGeneration.from_pretrained(BASE, torch_dtype=torch.bfloat16)
9state_dict = torch.load(
10 hf_hub_download(REPO, "weights.pt"), map_location="cpu", weights_only=True
11)
12model.load_state_dict(state_dict)
13model = model.eval().cuda()
14
15processor = PaliGemmaProcessor.from_pretrained(BASE)1import cv2
2
3image = cv2.cvtColor(cv2.imread("example.jpg"), cv2.COLOR_BGR2RGB)
4image = cv2.resize(image, (448, 448))
5prompt = "<image>Which object is closer to the camera, the chair or the table?"
6
7inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
8with torch.inference_mode():
9 output = model.generate(**inputs, max_new_tokens=100, do_sample=False)
10
11print(processor.decode(output[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))