Safetensors
florence2
remyx
multitask
custom_code
salma-remyx commited on
Commit
58c61f9
·
verified ·
1 Parent(s): 92bb86c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -0
README.md CHANGED
@@ -17,7 +17,41 @@ datasets:
17
  - **Repository:** [VQASynth](https://github.com/remyxai/VQASynth/tree/main)
18
  - **Paper:** [SpatialVLM](https://arxiv.org/abs/2401.12168)
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  ## Citation
23
  ```
 
17
  - **Repository:** [VQASynth](https://github.com/remyxai/VQASynth/tree/main)
18
  - **Paper:** [SpatialVLM](https://arxiv.org/abs/2401.12168)
19
 
20
+ # Running SpaceFlorence-2
21
+ ```
22
+ import requests
23
+
24
+ import torch
25
+ from PIL import Image
26
+ from transformers import AutoProcessor, AutoModelForCausalLM
27
+
28
+
29
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
30
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
31
+
32
+ model = AutoModelForCausalLM.from_pretrained("remyxai/SpaceFlorence-2", trust_remote_code=True).to(device)
33
+ processor = AutoProcessor.from_pretrained("remyxai/SpaceFlorence-2", trust_remote_code=True)
34
+
35
+ prompt = "<SpatialVQA> How far between the person and the pallet of boxes?"
36
 
37
+ url = "https://remyx.ai/assets/spatialvlm/warehouse_rgb.jpg?download=true"
38
+ image = Image.open(requests.get(url, stream=True).raw)
39
+
40
+ inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)
41
+
42
+ generated_ids = model.generate(
43
+ input_ids=inputs["input_ids"],
44
+ pixel_values=inputs["pixel_values"],
45
+ max_new_tokens=1024,
46
+ num_beams=3,
47
+ do_sample=False
48
+ )
49
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
50
+
51
+ parsed_answer = processor.post_process_generation(generated_text, task="<SpatialVQA>", image_size=(image.width, image.height))
52
+
53
+ print(parsed_answer)
54
+ ```
55
 
56
  ## Citation
57
  ```