Skip to content

Why my BLIP2 output just repeat the question? #806

@Anson-He

Description

@Anson-He
# 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions