|
![image/png](https://cdn-uploads.huggingface.co/production/uploads/646e4203407c402498b7aa7a/jY4uywIiL4uQamsmMQnQR.png) |
|
|
|
![image/png](https://cdn-uploads.huggingface.co/production/uploads/646e4203407c402498b7aa7a/_Fxhss6aO5jiaMAVVH3jm.png) |
|
|
|
![image/png](https://cdn-uploads.huggingface.co/production/uploads/646e4203407c402498b7aa7a/PdlKUUv7C9IgFBqcbjOaf.png) |
|
|
|
## How to Get Started with the Model |
|
|
|
Use the code below to get started with the model. |
|
|
|
```python |
|
import requests |
|
|
|
from PIL import Image |
|
from transformers import AutoProcessor, AutoModelForCausalLM |
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained("F16/florence2-large-ft-gufeng_v3", trust_remote_code=True) |
|
processor = AutoProcessor.from_pretrained("F16/florence2-large-ft-gufeng_v3", trust_remote_code=True) |
|
|
|
prompt = "<MORE_DETAILED_CAPTION>" |
|
|
|
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true" |
|
image = Image.open(requests.get(url, stream=True).raw) |
|
|
|
inputs = processor(text=prompt, images=image, return_tensors="pt") |
|
|
|
generated_ids = model.generate( |
|
input_ids=inputs["input_ids"], |
|
pixel_values=inputs["pixel_values"], |
|
max_new_tokens=1024, |
|
do_sample=False, |
|
num_beams=3 |
|
) |
|
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0] |
|
|
|
parsed_answer = processor.post_process_generation(generated_text, task=prompt, image_size=(image.width, image.height)) |
|
|
|
print(parsed_answer) |
|
|
|
``` |
|
--- |
|
license: mit |
|
--- |
|
|