🚀 BLIP: 統一されたビジョン・言語理解と生成のための言語・画像事前学習のブートストラッピング
このモデルは、画像からテキストへの変換(image-to-text)を行うBLIP(Salesforceの大規模画像キャプショニングモデル)です。バックエンドのパラメータをテスト目的で若干調整しており、特に返答の長さを増やしています。COCOデータセットで事前学習された画像キャプショニング用のモデルで、ベースアーキテクチャ(ViT largeバックボーンを使用)です。
 |
画像はBLIPの公式リポジトリから引用。画像ソース: https://github.com/salesforce/BLIP |
🚀 クイックスタート
このモデルは、条件付きおよび非条件付きの画像キャプショニングに使用できます。
✨ 主な機能
論文BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generationの著者は、以下のように述べています。
ビジョン・言語事前学習(VLP)は、多くのビジョン・言語タスクの性能を向上させています。しかし、既存のほとんどの事前学習モデルは、理解ベースのタスクまたは生成ベースのタスクのいずれかにのみ優れています。さらに、性能の向上は主に、ウェブから収集されたノイズの多い画像・テキストペアでデータセットを拡大することで達成されていますが、これは最適な監督情報源ではありません。本論文では、ビジョン・言語理解と生成タスクの両方に柔軟に適用できる新しいVLPフレームワークであるBLIPを提案します。BLIPは、キャプションをブートストラッピングすることでノイズの多いウェブデータを効果的に利用します。ここでは、キャプショナーが合成キャプションを生成し、フィルターがノイズの多いキャプションを除去します。画像・テキスト検索(平均recall@1で+2.7%)、画像キャプショニング(CIDErで+2.8%)、VQA(VQAスコアで+1.6%)など、幅広いビジョン・言語タスクで最先端の結果を達成しています。また、BLIPは、ゼロショット方式でビデオ・言語タスクに直接適用した場合にも強い汎化能力を示します。コード、モデル、データセットが公開されています。
💻 使用例
基本的な使用法
このモデルを使用して、条件付きおよび非条件付きの画像キャプショニングを行うことができます。
CPUでのモデル実行
クリックして展開
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
text = "a photography of"
inputs = processor(raw_image, text, return_tensors="pt")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
inputs = processor(raw_image, return_tensors="pt")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
GPUでのモデル実行
フル精度での実行
クリックして展開
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large").to("cuda")
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
text = "a photography of"
inputs = processor(raw_image, text, return_tensors="pt").to("cuda")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
inputs = processor(raw_image, return_tensors="pt").to("cuda")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
半精度(float16
)での実行
クリックして展開
import torch
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large", torch_dtype=torch.float16).to("cuda")
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
text = "a photography of"
inputs = processor(raw_image, text, return_tensors="pt").to("cuda", torch.float16)
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
>>> a woman sitting on the beach with her dog
📚 詳細ドキュメント
BibTexと引用情報
@misc{https://doi.org/10.48550/arxiv.2201.12086,
doi = {10.48550/ARXIV.2201.12086},
url = {https://arxiv.org/abs/2201.12086},
author = {Li, Junnan and Li, Dongxu and Xiong, Caiming and Hoi, Steven},
keywords = {Computer Vision and Pattern Recognition (cs.CV), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation},
publisher = {arXiv},
year = {2022},
copyright = {Creative Commons Attribution 4.0 International}
}
📄 ライセンス
このモデルはBSD 3条項ライセンス(bsd-3-clause)の下で提供されています。