-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
# pip install accelerate
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("/data3/VLM/blip2-opt-2.7b")
model = Blip2ForConditionalGeneration.from_pretrained("/data3/VLM/blip2-opt-2.7b", device_map="auto")
img_url = './img/cat.jpg'
raw_image = Image.open(img_url).convert('RGB')
question = "how many cats are in the picture?"
inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True).strip())
Output:
how many cats are in the picture?
Metadata
Metadata
Assignees
Labels
No labels