模型:
Salesforce/blip-itm-large-flickr
预印本库:
arxiv:2201.12086许可:
bsd-3-clauseBLIP(Bootstrapping Language-Image Pre-training)基于图像-文本匹配进行训练,使用了大规模架构(ViT 大型骨干网络)在 Flickr30k 数据集上进行了训练。
Pull figure from BLIP official repo |
来自 paper 的作者在摘要中写道:
视觉-语言预训练(VLP)已经提升了许多视觉-语言任务的性能。然而,大多数已有的预训练模型只在理解型任务或生成型任务中表现出色。此外,通过扩大使用从网络上收集的嘈杂的图像-文本对数据集来改善性能,这种方式并不是最优的监督来源。在本文中,我们提出了 BLIP,这是一个新的 VLP 框架,可以灵活地转移到视觉-语言理解和生成任务中。BLIP 通过引导标题来高效地利用嘈杂的网络数据,其中一个标题生成器生成合成标题,而一个过滤器则删除噪音标题。我们在广泛的视觉-语言任务上取得了最先进的结果,例如图像-文本检索(平均召回率 @ 1 提高了 2.7%)、图像字幕生成(CIDEr 提高了 2.8%)和视觉问答(VQA 评分提高了 1.6%)。BLIP 还展示了强大的泛化能力,在零-shot 方式下直接转移到视频-语言任务上。代码、模型和数据集已发布。
您可以将此模型用于有条件和无条件的图像字幕生成。
在 CPU 上运行模型
点击扩展
import requests from PIL import Image from transformers import BlipProcessor, BlipForImageTextRetrieval processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-large-flickr") model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-large-flickr") 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') question = "A woman and a dog sitting together in a beach." inputs = processor(raw_image, question, return_tensors="pt") itm_scores = model(**inputs)[0] cosine_score = model(**inputs, use_itm_head=False)[0]
在 GPU 上运行模型
以全精度运行
点击扩展
import requests from PIL import Image from transformers import BlipProcessor, BlipForImageTextRetrieval processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-large-flickr") model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-large-flickr").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') question = "A woman and a dog sitting together in a beach." inputs = processor(raw_image, question, return_tensors="pt").to("cuda") itm_scores = model(**inputs)[0] cosine_score = model(**inputs, use_itm_head=False)[0]
以半精度(float16)运行
点击扩展
import torch import requests from PIL import Image from transformers import BlipProcessor, BlipForImageTextRetrieval processor = BlipProcessor.from_pretrained("Salesforce/blip-itm-large-flickr") model = BlipForImageTextRetrieval.from_pretrained("Salesforce/blip-itm-large-flickr", 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') question = "A woman and a dog sitting together in a beach." inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.float16) itm_scores = model(**inputs)[0] cosine_score = model(**inputs, use_itm_head=False)[0]
@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} }