Upload folder using huggingface_hub
Browse files- README.md +39 -3
- weights.pt +3 -0
README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
| 1 |
-
--
|
| 2 |
-
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HiSpatial-3B-RGB
|
| 2 |
+
|
| 3 |
+
RGB-only variant of [HiSpatial](https://github.com/microsoft/HiSpatial), built on PaliGemma2-3B-mix-448.
|
| 4 |
+
|
| 5 |
+
## Usage
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
import torch
|
| 9 |
+
from huggingface_hub import hf_hub_download
|
| 10 |
+
from transformers import PaliGemmaForConditionalGeneration, PaliGemmaProcessor
|
| 11 |
+
|
| 12 |
+
BASE = "google/paligemma2-3b-mix-448"
|
| 13 |
+
REPO = "lhzzzzzy/HiSpatial-3B-RGB"
|
| 14 |
+
|
| 15 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained(BASE, torch_dtype=torch.bfloat16)
|
| 16 |
+
state_dict = torch.load(
|
| 17 |
+
hf_hub_download(REPO, "weights.pt"), map_location="cpu", weights_only=True
|
| 18 |
+
)
|
| 19 |
+
model.load_state_dict(state_dict)
|
| 20 |
+
model = model.eval().cuda()
|
| 21 |
+
|
| 22 |
+
processor = PaliGemmaProcessor.from_pretrained(BASE)
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
Inference:
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
import cv2
|
| 29 |
+
|
| 30 |
+
image = cv2.cvtColor(cv2.imread("example.jpg"), cv2.COLOR_BGR2RGB)
|
| 31 |
+
image = cv2.resize(image, (448, 448))
|
| 32 |
+
prompt = "<image>Which object is closer to the camera, the chair or the table?"
|
| 33 |
+
|
| 34 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
|
| 35 |
+
with torch.inference_mode():
|
| 36 |
+
output = model.generate(**inputs, max_new_tokens=100, do_sample=False)
|
| 37 |
+
|
| 38 |
+
print(processor.decode(output[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 39 |
+
```
|
weights.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f3d0c7e6768c26de6a4d90bf722cf25e57be24edda20f39c6fc68d5898853d16
|
| 3 |
+
size 14503383771
|