Googleが公開しているVision&Languageモデル(VLM)の「PaliGemma」を使ってみる

はじめに

Vision&Languageモデル(VLM)を使って写真の説明をしてもらいます。

今回はGoogleが最近オープンソースとして公開してくれた「PaliGemma」を使ってみました。

その他のVision&Languageモデル(VLM)

touch-sp.hatenablog.com

touch-sp.hatenablog.com
touch-sp.hatenablog.com
touch-sp.hatenablog.com

画像と結果

写真


結果

Two children sit on a ledge, looking up at a shooting star. The sky is dark, with a few stars visible. The boy is pointing to the sky, his arm outstretched. The girl is wearing overalls and has her hair in a braid. The boy is wearing a striped shirt and has a small smile on his face. The girl is wearing a pink shirt and has a small smile on her face. The shooting star is flying through the sky, and the children are looking at it with wonder.

DeepLで翻訳した結果

二人の子供が縁台に座って流れ星を見上げている。空は暗く、星がいくつか見える。男の子は腕を伸ばして空を指さしている。女の子はオーバーオールを着て、髪を三つ編みにしている。男の子はストライプのシャツを着て、顔に小さな笑みを浮かべている。女の子はピンクのシャツを着て、顔に小さな笑みを浮かべている。流れ星は空を飛んでいて、子供たちは不思議そうにそれを見ている。

Pythonスクリプト

from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
from diffusers.utils import load_image
import torch

# downloaded from https://huggingface.co/google/paligemma-3b-mix-448
model_id = "paligemma-3b-mix-448"

url = "sample.jpg"
image = load_image(url)

model = PaliGemmaForConditionalGeneration.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16
).to("cuda")

processor = AutoProcessor.from_pretrained(model_id)

prompt = "caption en"
input = processor(
    text=prompt,
    images=image,
    return_tensors="pt"
).to("cuda")

output = model.generate(**input, max_new_tokens=200)

print(processor.decode(output[0], skip_special_tokens=True)[len(prompt):])




このエントリーをはてなブックマークに追加