MMInstruction/M3IT
Updated • 2.78k • 136
How to use nnpy/blip-image-captioning with Transformers:
# Use a pipeline as a high-level helper
# Warning: Pipeline type "image-to-text" is no longer supported in transformers v5.
# You must load the model directly (see below) or downgrade to v4.x with:
# 'pip install "transformers<5.0.0'
from transformers import pipeline
pipe = pipeline("image-to-text", model="nnpy/blip-image-captioning") # Load model directly
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("nnpy/blip-image-captioning")
model = AutoModelForImageTextToText.from_pretrained("nnpy/blip-image-captioning")# Load model directly
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("nnpy/blip-image-captioning")
model = AutoModelForImageTextToText.from_pretrained("nnpy/blip-image-captioning")from transformers import BlipProcessor, BlipForConditionalGeneration
import torch
from PIL import Image
processor = BlipProcessor.from_pretrained("prasanna2003/blip-image-captioning")
if processor.tokenizer.eos_token is None:
processor.tokenizer.eos_token = '<|eos|>'
model = BlipForConditionalGeneration.from_pretrained("prasanna2003/blip-image-captioning")
image = Image.open('file_name.jpg').convert('RGB')
prompt = """Instruction: Generate a single line caption of the Image.
output: """
inputs = processor(image, prompt, return_tensors="pt")
output = model.generate(**inputs, max_length=100)
print(processor.tokenizer.decode(output[0]))
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="nnpy/blip-image-captioning")