Instructions to use microsoft/Florence-2-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Florence-2-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/Florence-2-base", trust_remote_code=True)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True) model = AutoModelForImageTextToText.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use microsoft/Florence-2-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Florence-2-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Florence-2-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/Florence-2-base
- SGLang
How to use microsoft/Florence-2-base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "microsoft/Florence-2-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Florence-2-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "microsoft/Florence-2-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Florence-2-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/Florence-2-base with Docker Model Runner:
docker model run hf.co/microsoft/Florence-2-base
Update README.md
Browse files
README.md
CHANGED
|
@@ -110,20 +110,7 @@ Here are the tasks `Florence-2` could perform:
|
|
| 110 |
<details>
|
| 111 |
<summary> Click to expand </summary>
|
| 112 |
|
| 113 |
-
### OCR
|
| 114 |
-
|
| 115 |
-
```python
|
| 116 |
-
prompt = "<OCR>"
|
| 117 |
-
run_example(prompt)
|
| 118 |
-
```
|
| 119 |
|
| 120 |
-
### OCR with Region
|
| 121 |
-
OCR with region output format:
|
| 122 |
-
{'\<OCR_WITH_REGION>': {'quad_boxes': [[x1, y1, x2, y2, x3, y3, x4, y4], ...], 'labels': ['text1', ...]}}
|
| 123 |
-
```python
|
| 124 |
-
prompt = "<OCR_WITH_REGION>"
|
| 125 |
-
run_example(prompt)
|
| 126 |
-
```
|
| 127 |
|
| 128 |
### Caption
|
| 129 |
```python
|
|
@@ -143,6 +130,16 @@ prompt = "<MORE_DETAILED_CAPTION>"
|
|
| 143 |
run_example(prompt)
|
| 144 |
```
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
### Object Detection
|
| 147 |
|
| 148 |
OD results format:
|
|
@@ -172,14 +169,19 @@ prompt = "<REGION_PROPOSAL>"
|
|
| 172 |
run_example(prompt)
|
| 173 |
```
|
| 174 |
|
| 175 |
-
###
|
| 176 |
-
caption to phrase grounding task requires additional text input, i.e. caption.
|
| 177 |
|
| 178 |
-
Caption to phrase grounding results format:
|
| 179 |
-
{'\<CAPTION_TO_PHRASE_GROUNDING>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}
|
| 180 |
```python
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
```
|
| 184 |
|
| 185 |
for More detailed examples, please refer to [notebook](https://huggingface.co/microsoft/Florence-2-large/blob/main/sample_inference.ipynb)
|
|
|
|
| 110 |
<details>
|
| 111 |
<summary> Click to expand </summary>
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
### Caption
|
| 116 |
```python
|
|
|
|
| 130 |
run_example(prompt)
|
| 131 |
```
|
| 132 |
|
| 133 |
+
### Caption to Phrase Grounding
|
| 134 |
+
caption to phrase grounding task requires additional text input, i.e. caption.
|
| 135 |
+
|
| 136 |
+
Caption to phrase grounding results format:
|
| 137 |
+
{'\<CAPTION_TO_PHRASE_GROUNDING>': {'bboxes': [[x1, y1, x2, y2], ...], 'labels': ['', '', ...]}}
|
| 138 |
+
```python
|
| 139 |
+
task_prompt = "<CAPTION_TO_PHRASE_GROUNDING>"
|
| 140 |
+
results = run_example(task_prompt, text_input="A green car parked in front of a yellow building.")
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
### Object Detection
|
| 144 |
|
| 145 |
OD results format:
|
|
|
|
| 169 |
run_example(prompt)
|
| 170 |
```
|
| 171 |
|
| 172 |
+
### OCR
|
|
|
|
| 173 |
|
|
|
|
|
|
|
| 174 |
```python
|
| 175 |
+
prompt = "<OCR>"
|
| 176 |
+
run_example(prompt)
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
### OCR with Region
|
| 180 |
+
OCR with region output format:
|
| 181 |
+
{'\<OCR_WITH_REGION>': {'quad_boxes': [[x1, y1, x2, y2, x3, y3, x4, y4], ...], 'labels': ['text1', ...]}}
|
| 182 |
+
```python
|
| 183 |
+
prompt = "<OCR_WITH_REGION>"
|
| 184 |
+
run_example(prompt)
|
| 185 |
```
|
| 186 |
|
| 187 |
for More detailed examples, please refer to [notebook](https://huggingface.co/microsoft/Florence-2-large/blob/main/sample_inference.ipynb)
|