Model Description

The Florence-2_FT_VQA model is a fine-tuned version of the microsoft/Florence-2-base-ft model, tailored specifically for the task of visual question answering.

  • Finetuned from model: microsoft/Florence-2-base-ft

How to use

! pip install -q "flash_attn==2.7.4.post1" "timm==1.0.15" "einops==0.8.1" "transformers==4.51.3"
from transformers import AutoModelForCausalLM, AutoProcessor
import requests
import torch
from PIL import Image
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("nirusanan/Florence-2_FT_VQA", torch_dtype=torch_dtype, trust_remote_code=True).to(device)
processor = AutoProcessor.from_pretrained("nirusanan/Florence-2_FT_VQA", trust_remote_code=True)
prompt = "DocVQA" + "What is the diseases of this leaf?"


url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYoDmTW0JLiW2VNGbT0OozJqi3biTszTOQKCnuuvdPuFUzHS6gQwFdCLQi7mmY7hGD150&usqp=CAU"
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")

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,
    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="DocVQA", image_size=(image.width, image.height))

print(parsed_answer)
Downloads last month
33
Safetensors
Model size
271M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for nirusanan/Florence-2_FT_VQA

Finetuned
(16)
this model

Dataset used to train nirusanan/Florence-2_FT_VQA