Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## How to Get Started with the Model
|
2 |
+
|
3 |
+
Use the code below to get started with the model.
|
4 |
+
|
5 |
+
```python
|
6 |
+
import requests
|
7 |
+
|
8 |
+
from PIL import Image
|
9 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
10 |
+
|
11 |
+
|
12 |
+
model = AutoModelForCausalLM.from_pretrained("F16/florence2-large-ft-gufeng_v3", trust_remote_code=True)
|
13 |
+
processor = AutoProcessor.from_pretrained("F16/florence2-large-ft-gufeng_v3", trust_remote_code=True)
|
14 |
+
|
15 |
+
prompt = "<MORE_DETAILED_CAPTION>"
|
16 |
+
|
17 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
|
18 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
19 |
+
|
20 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt")
|
21 |
+
|
22 |
+
generated_ids = model.generate(
|
23 |
+
input_ids=inputs["input_ids"],
|
24 |
+
pixel_values=inputs["pixel_values"],
|
25 |
+
max_new_tokens=1024,
|
26 |
+
do_sample=False,
|
27 |
+
num_beams=3
|
28 |
+
)
|
29 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
|
30 |
+
|
31 |
+
parsed_answer = processor.post_process_generation(generated_text, task=prompt, image_size=(image.width, image.height))
|
32 |
+
|
33 |
+
print(parsed_answer)
|
34 |
+
|
35 |
+
```
|
36 |
+
---
|
37 |
+
license: mit
|
38 |
+
---
|