Downloads · 30 days
5
17% of all-time downloads
curlyfu/blip2-QA-generation
blip2-QA-generation is a image-to-text model from curlyfu. Use it when you need a caption or text from an image. It is set up for peft. The card lists the license as apache-2.0.
Lora for Blip2 to generate QAs from a picture.
Downloads · 30 days
5
17% of all-time downloads
All-time downloads
29
Public
Repo size
168 MB
Likes
2
Public
Click a slice to open those files.
.safetensors168 MB · 100%
From the Hugging Face model README
Lora for Blip2 to generate QAs from a picture.
from datasets import load_dataset
from peft import PeftModel
import torch
from transformers import AutoProcessor, Blip2ForConditionalGeneration
# prepare the model
processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
model = Blip2ForConditionalGeneration.from_pretrained("ybelkada/blip2-opt-2.7b-fp16-sharded", device_map="auto", load_in_8bit=True)
model = PeftModel.from_pretrained(model, "curlyfu/blip2-OCR-QA-generation")
# prepare inputs
dataset = load_dataset("howard-hou/OCR-VQA", split="test")
example = dataset[10]
image = example["image"]
inputs = processor(images=image, return_tensors="pt").to("cuda", torch.float16)
pixel_values = inputs.pixel_values
generated_ids = model.generate(pixel_values=pixel_values, max_length=100)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_caption)
huggingface/notebooks