Safetensors
florence2
remyx
multitask
custom_code
File size: 3,147 Bytes
8057a08
 
8a5f18e
 
2365804
 
26b089f
 
 
8057a08
 
86d42c4
8057a08
 
dd80f5b
a2ad63d
 
 
 
 
 
dd80f5b
 
86d42c4
 
dd80f5b
 
 
870a1f9
 
58c61f9
c67bd29
58c61f9
 
 
 
 
 
 
 
 
 
 
 
 
 
870a1f9
58c61f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870a1f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
license: mit
datasets:
- remyxai/vqasynth_spacellava
tags:
- remyx
- multitask
base_model:
- microsoft/Florence-2-base-ft
---

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1or4muggFnUnZJ50tkCYCla7b9no9HogN?usp=sharing)

![image/png](https://cdn-uploads.huggingface.co/production/uploads/647777304ae93470ffc28913/eGBP2Selg2xAruycvTVI1.png)

# Model Card for SpaceFlorence-2

**SpaceFlorence-2** does a full finetune of the BERT component of [Florence-2](https://github.com/haotian-liu/LLaVA/tree/main) with a [dataset](https://huggingface.co./datasets/remyxai/vqasynth_spacellava) designed with [VQASynth](https://github.com/remyxai/VQASynth/tree/main) to enhance spatial reasoning as in [SpatialVLM](https://spatial-vlm.github.io/)

## Model Details

- **Developed by:** remyx.ai
- **Model type:** MultiModal Model, Vision Language Model, Florence-2
- **Finetuned from model:** Florence-2
  
### Model Sources
- **Dataset:** [SpaceLLaVA](https://huggingface.co./datasets/remyxai/vqasynth_spacellava)
- **Repository:** [VQASynth](https://github.com/remyxai/VQASynth/tree/main)
- **Paper:** [SpatialVLM](https://arxiv.org/abs/2401.12168)

# Running SpaceFlorence-2
```python
import requests

import torch
from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM 


device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32

model = AutoModelForCausalLM.from_pretrained("remyxai/SpaceFlorence-2", trust_remote_code=True).to(device)
processor = AutoProcessor.from_pretrained("remyxai/SpaceFlorence-2", trust_remote_code=True)

prompt = "<SpatialVQA> How far between the person and the pallet of boxes?"

url = "https://remyx.ai/assets/spatialvlm/warehouse_rgb.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)

inputs = processor(text=prompt, images=image, return_tensors="pt").to(device, torch_dtype)

generated_ids = model.generate(
    input_ids=inputs["input_ids"],
    pixel_values=inputs["pixel_values"],
    max_new_tokens=1024,
    num_beams=3,
    do_sample=False
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]

parsed_answer = processor.post_process_generation(generated_text, task="<SpatialVQA>", image_size=(image.width, image.height))

print(parsed_answer)
```

## Citation
```
@article{chen2024spatialvlm,
  title = {SpatialVLM: Endowing Vision-Language Models with Spatial Reasoning Capabilities},
  author = {Chen, Boyuan and Xu, Zhuo and Kirmani, Sean and Ichter, Brian and Driess, Danny and Florence, Pete and Sadigh, Dorsa and Guibas, Leonidas and Xia, Fei},
  journal = {arXiv preprint arXiv:2401.12168},
  year = {2024},
  url = {https://arxiv.org/abs/2401.12168},
}

@article{xiao2023florence,
  title={Florence-2: Advancing a unified representation for a variety of vision tasks},
  author={Xiao, Bin and Wu, Haiping and Xu, Weijian and Dai, Xiyang and Hu, Houdong and Lu, Yumao and Zeng, Michael and Liu, Ce and Yuan, Lu},
  journal={arXiv preprint arXiv:2311.06242},
  year={2023}
}
```