模型简介
模型特点
模型能力
使用案例
库名称:transformers
许可证:gemma
流水线标签:图像文本到文本
额外授权标题:在Hugging Face上访问PaliGemma
额外授权提示:要在Hugging Face上访问PaliGemma,您需要审阅并同意Google的使用许可。请确保您已登录Hugging Face账号,并点击下方按钮。请求将立即处理。
额外授权按钮内容:确认许可
PaliGemma 2 模型卡
模型页面: PaliGemma
Transformers PaliGemma 2 3B权重,预训练时使用224*224输入图像和128个标记的输入/输出文本序列。
该模型以bfloat16
格式提供,适用于微调。
资源与技术文档:
使用条款: 条款
作者: Google
模型信息
模型概述
PaliGemma 2是PaliGemma视觉语言模型(VLM)的更新版本,融合了Gemma 2模型的能力。PaliGemma系列模型受PaLI-3启发,基于开放组件如SigLIP视觉模型和Gemma 2语言模型。它接受图像和文本作为输入,生成文本输出,支持多语言。该模型设计用于在广泛的视觉语言任务(如图像和短视频描述、视觉问答、文本阅读、目标检测和分割)上实现领先的微调性能。
模型架构
PaliGemma 2由Transformer解码器和Vision Transformer图像编码器组成。文本解码器初始化自Gemma 2的2B、9B和27B参数规模。图像编码器初始化自SigLIP-So400m/14。与原始PaliGemma模型类似,PaliGemma 2的训练遵循PaLI-3的配方。
输入与输出
- 输入: 图像和文本字符串,例如描述图像的提示或问题。
- 输出: 根据输入生成的文本响应,如图像描述、问题答案、目标边界框坐标列表或分割编码词。
引用
@article{
title={PaliGemma 2: A Family of Versatile VLMs for Transfer},
author={Andreas Steiner and André Susano Pinto and Michael Tschannen and Daniel Keysers and Xiao Wang and Yonatan Bitton and Alexey Gritsenko and Matthias Minderer and Anthony Sherbondy and Shangbang Long and Siyang Qin and Reeve Ingle and Emanuele Bugliarello and Sahar Kazemzadeh and Thomas Mesnard and Ibrahim Alabdulmohsin and Lucas Beyer and Xiaohua Zhai},
year={2024},
journal={arXiv preprint arXiv:2412.03555}
}
模型数据
预训练数据集
PaliGemma 2在以下混合数据集上进行了预训练:
- WebLI: WebLI(Web语言图像)是从公共网络构建的大规模多语言图像-文本数据集。使用多种WebLI分割来获取多样化的模型能力,如视觉语义理解、目标定位、视觉文本理解和多语言性。
- CC3M-35L: 从网页中筛选的英语图像-替代文本对(Sharma等,2018)。使用Google Cloud Translation API翻译为34种其他语言。
- VQ²A-CC3M-35L/VQG-CC3M-35L: VQ2A-CC3M的子集(Changpinyo等,2022a),翻译为与CC3M-35L相同的34种语言。
- OpenImages: 基于OpenImages数据集的手工规则生成的检测和目标感知问答(Piergiovanni等,2022)。
- WIT: 从维基百科收集的图像和文本(Srinivasan等,2021)。
PaliGemma 2基于Gemma 2,关于Gemma 2的预训练数据集信息可在Gemma 2模型卡中找到。
数据责任过滤
对WebLI应用了以下过滤器,以确保PaliGemma 2在安全负责的数据上训练:
- 色情图像过滤: 移除被判定为色情性质的图像。
- 文本安全过滤: 识别并过滤与不安全文本配对的图像。不安全文本包括儿童性虐待内容、色情、粗俗或其他冒犯性内容。
- 文本毒性过滤: 使用Perspective API识别并过滤与侮辱性、淫秽、仇恨或其他有毒文本配对的图像。
- 文本个人信息过滤: 使用Cloud Data Loss Prevention (DLP) API过滤某些个人信息和敏感数据,以保护个人隐私。移除了如社会安全号码等标识符和其他敏感信息类型。
- 其他方法: 根据我们的政策和实践,基于内容质量和安全性进行过滤。
在Transformers中使用
以下代码片段使用google/paligemma2-3b-pt-224
模型作为参考。这是一个基础模型,建议在下游任务微调后使用。
这里有一个笔记本展示了如何微调PaliGemma 2。
from transformers import (
PaliGemmaProcessor,
PaliGemmaForConditionalGeneration,
)
from transformers.image_utils import load_image
import torch
model_id = "google/paligemma2-3b-pt-224"
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg"
image = load_image(url)
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto").eval()
processor = PaliGemmaProcessor.from_pretrained(model_id)
# 预训练模型留空提示
prompt = ""
model_inputs = processor(text=prompt, images=image, return_tensors="pt").to(torch.bfloat16).to(model.device)
input_len = model_inputs["input_ids"].shape[-1]
with torch.inference_mode():
generation = model.generate(**model_inputs, max_new_tokens=100, do_sample=False)
generation = generation[0][input_len:]
decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
实现信息
硬件
PaliGemma 2使用最新一代Tensor Processing Unit(TPU)硬件(TPUv5e)训练。
软件
训练使用JAX、Flax、TFDS和big_vision
完成。
JAX允许研究人员利用包括TPU在内的最新硬件,更快更高效地训练大型模型。
TFDS用于访问数据集,Flax用于模型架构。PaliGemma 2的微调代码和推理代码在big_vision
GitHub仓库中发布。
评估信息
基准测试结果
为验证PaliGemma 2在多种学术任务上的可迁移性,我们在每个任务上微调预训练模型。我们报告了不同分辨率的结果,以展示哪些任务受益于更高的分辨率。重要的是,这些任务或数据集均未包含在预训练数据混合中,其图像已明确从网络规模预训练数据中移除。
PaliGemma 2按模型分辨率和规模的结果
基准测试 | 224-3B | 224-10B | 224-28B | 448-3B | 448-10B | 448-28B |
---|---|---|---|---|---|---|
[AI2D][ai2d] | 74.7 | 83.1 | 83.2 | 76.0 | 84.4 | 84.6 |
[AOKVQA-DA][aokvqa-da] (val) | 64.2 | 68.9 | 70.2 | 67.9 | 70.8 | 71.2 |
[AOKVQA-MC][aokvqa-mc] (val) | 79.7 | 83.7 | 84.7 | 82.5 | 85.9 | 87.0 |
[ActivityNet-CAP][anet-cap] | 34.2 | 35.9 | - | - | - | - |
[ActivityNet-QA][anet-qa] | 51.3 | 53.2 | - | - | - | - |
[COCO-35L][coco-35l] (avg34) | 113.9 | 115.8 | 116.5 | 115.8 | 117.2 | 117.2 |
[COCO-35L][coco-35l] (en) | 138.4 | 140.8 | 142.4 | 140.4 | 142.4 | 142.3 |
[COCOcap][coco-cap] | 141.3 | 143.7 | 144.0 | 143.4 | 145.0 | 145.2 |
[ChartQA][chartqa] (aug) | 74.4 | 74.2 | 68.9 | 89.2 | 90.1 | 85.1 |
[ChartQA][chartqa] (human) | 42.0 | 48.4 | 46.8 | 54.0 | 66.4 | 61.3 |
[CountBenchQA][countbenchqa] | 81.0 | 84.0 | 86.4 | 82.0 | 85.3 | 87.4 |
[DocVQA][docvqa] (val) | 39.9 | 43.9 | 44.9 | 73.6 | 76.6 | 76.1 |
[GQA][gqa] | 66.2 | 67.2 | 67.3 | 68.1 | 68.3 | 68.3 |
[InfoVQA][info-vqa] (val) | 25.2 | 33.6 | 36.4 | 37.5 | 47.8 | 46.7 |
[MARVL][marvl] (avg5) | 83.5 | 89.5 | 90.6 | 82.7 | 89.1 | 89.7 |
[MSRVTT-CAP][msrvtt] | 68.5 | 72.1 | - | - | - | - |
[MSRVTT-QA][msrvtt] | 50.5 | 51.9 | - | - | - | - |
[MSVD-QA][msvd-qa] | 61.1 | 62.5 | - | - | - | - |
[NLVR2][nlvr2] | 91.4 | 93.9 | 94.2 | 91.6 | 93.7 | 94.1 |
[NoCaps][nocaps] | 123.1 | 126.3 | 127.1 | 123.5 | 126.9 | 127.0 |
[OCR-VQA][ocr-vqa] | 73.4 | 74.7 | 75.3 | 75.7 | 76.3 | 76.6 |
[OKVQA][okvqa] | 64.2 | 68.0 | 71.2 | 64.1 | 68.6 | 70.6 |
[RSVQA-hr][rsvqa-hr] (test) | 92.7 | 92.6 | 92.7 | 92.8 | 92.8 | 92.8 |
[RSVQA-hr][rsvqa-hr] (test2) | 90.9 | 90.8 | 90.9 | 90.7 | 90.7 | 90.8 |
[RSVQA-lr][rsvqa-lr] | 93.0 | 92.8 | 93.5 | 92.7 | 93.1 | 93.7 |
[RefCOCO][refcoco] (testA) | 75.7 | 77.2 | 76.8 | 78.6 | 79.7 | 79.3 |
[RefCOCO][refcoco] (testB) | 71.0 | 74.2 | 73.9 | 73.5 | 76.2 | 74.8 |
[RefCOCO][refcoco] (val) | 73.4 | 75.9 | 75.0 | 76.3 | 78.2 | 77.3 |
[RefCOCO+][refcoco+] (testA) | 72.7 | 74.7 | 73.6 | 76.1 | 77.7 | 76.6 |
[RefCOCO+][refcoco+] (testB) | 64.2 | 68.4 | 67.1 | 67.0 | 71.1 | 68.6 |
[RefCOCO+][refcoco+] (val) | 68.6 | 72.0 | 70.3 | 72.1 | 74.4 | 72.8 |
[RefCOCOg][refcocog] (test) | 69.0 | 71.9 | 70.7 | 72.7 | 74.8 | 73.7 |
[RefCOCOg][refcocog] (val) | 68.3 | 71.4 | 70.5 | 72.3 | 74.4 | 73.0 |
[ST-VQA][st-vqa] (val) | 61.9 | 64.3 | 65.1 | 80.5 | 82.0 | 81.8 |
[SciCap][scicap] | 165.1 | 159.5 | 156.9 | 183.3 | 177.2 | 172.7 |
[ScienceQA][scienceqa] | 96.1 | 98.2 | 98.2 | 96.2 | 98.5 | 98.6 |
[Screen2Words][screen2words] | 113.3 | 117.8 | 122.8 | 114.0 | 119.1 | 123.4 |
[TallyQA][tallyqa] (complex) | 70.3 | 73.4 | 74.2 | 73.6 | 76.7 | 76.8 |
[TallyQA][tallyqa] (simple) | 81.8 | 83.2 | 83.4 | 85.3 | 86.2 | 85.7 |
[TextCaps][textcaps] | 127.5 | 137.9 | 139.9 | 152.1 | 157.7 | 153.6 |
[TextVQA][textvqa] (val) | 59.6 | 64.0 | 64.7 | 75.2 | 76.6 | 76. |








