🚀 BLIP: 統一されたビジョン言語理解と生成のための言語画像事前学習のブートストラッピング
このモデルは、画像をテキストに変換するためのもので、COCOデータセットで事前学習された画像キャプショニングモデルです。バックエンドのパラメータを少し調整してテスト用にしています。特に、返答の長さを増やしています。
 |
画像はBLIPの公式リポジトリから引用。画像ソース: https://github.com/salesforce/BLIP |
🚀 クイックスタート
このモデルは、条件付きおよび条件なしの画像キャプショニングに使用できます。
✨ 主な機能
- 柔軟にビジョン言語理解と生成タスクに転用できる新しいVLPフレームワークです。
- ノイズの多いウェブデータを効果的に利用し、合成キャプションを生成し、ノイズを除去します。
- 幅広いビジョン言語タスクで最先端の結果を達成します。
📚 ドキュメント
TL;DR
論文の著者は、概要で次のように書いています。
ビジョン言語事前学習(VLP)は、多くのビジョン言語タスクのパフォーマンスを向上させています。しかし、ほとんどの既存の事前学習モデルは、理解ベースのタスクまたは生成ベースのタスクのいずれかでのみ優れています。さらに、パフォーマンスの向上は、ウェブから収集されたノイズの多い画像テキストペアを使用してデータセットを拡大することで主に達成されていますが、これは最適な監督ソースではありません。この論文では、BLIPという新しいVLPフレームワークを提案します。これは、ビジョン言語理解と生成タスクの両方に柔軟に転用できます。BLIPは、キャプショナーが合成キャプションを生成し、フィルターがノイズを除去することで、ノイズの多いウェブデータを効果的に利用します。画像テキスト検索(平均recall@1で+2.7%)、画像キャプショニング(CIDErで+2.8%)、VQA(VQAスコアで+1.6%)など、幅広いビジョン言語タスクで最先端の結果を達成します。また、BLIPは、ゼロショット方式でビデオ言語タスクに直接転用する際にも強い汎化能力を示します。コード、モデル、データセットが公開されています。
💻 使用例
基本的な使用法
PyTorchモデルを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))
PyTorchモデルを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))
📄 ライセンス
このモデルは、BSD 3条項ライセンスの下で提供されています。
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}
}