库名称:transformers
许可证:gemma
流水线标签:图像文本到文本
额外授权标题:在Hugging Face上访问PaliGemma
额外授权提示:要在Hugging Face上访问PaliGemma,您需要审阅并同意Google的使用许可。请确保您已登录Hugging Face账号,并点击下方按钮。请求将立即处理。
额外授权按钮内容:确认许可
PaliGemma 2 模型卡
模型页面: PaliGemma
Transformers PaliGemma 2 10B权重,预训练输入为448*448像素图像和512个令牌的输入/输出文本序列。模型以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在以下混合数据集上预训练:
PaliGemma 2基于Gemma 2,其预训练数据集信息见Gemma 2模型卡。
数据责任过滤
对WebLI应用以下过滤,以确保PaliGemma 2训练数据的安全性与责任性:
在Transformers中使用
以下代码片段使用google/paligemma2-10b-pt-448
模型作为参考。这是基础模型,建议在下游任务微调后使用。
此处提供展示PaliGemma 2微调的笔记本。
from transformers import (
PaliGemmaProcessor,
PaliGemmaForConditionalGeneration,
)
from transformers.image_utils import load_image
import torch
model_id = "google/paligemma2-10b-pt-448"
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] (验证) |
64.2 |
68.9 |
70.2 |
67.9 |
70.8 |
71.2 |
[AOKVQA-MC][aokvqa-mc] (验证) |
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] (平均34) |
113.9 |
115.8 |
116.5 |
115.8 |
117.2 |
117.2 |
[COCO-35L][coco-35l] (英文) |
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] (增强) |
74.4 |
74.2 |
68.9 |
89.2 |
90.1 |
85.1 |
[ChartQA][chartqa] (人工) |
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] (验证) |
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] (验证) |
25.2 |
33.6 |
36.4 |
37.5 |
47.8 |
46.7 |
[MARVL][marvl] (平均5) |
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] |
|
|
|
|
|
|