库名称:transformers
许可证:gemma
流水线标签:图像文本到文本
额外授权标题:在Hugging Face上访问PaliGemma
额外授权提示:要访问Hugging Face上的PaliGemma,您需要审阅并同意Google的使用许可。请确保您已登录Hugging Face账号并点击下方按钮。请求将立即处理。
额外授权按钮内容:确认许可
PaliGemma模型卡
模型页面: PaliGemma
Transformers PaliGemma 3B权重,预训练时使用448*448输入图像和512个标记的输入/输出文本序列。模型提供float32、bfloat16和float16格式用于微调。
资源与技术文档:
使用条款: 条款
作者: Google
模型信息
模型概述
描述
PaliGemma是一款多功能轻量级视觉语言模型(VLM),灵感来自PaLI-3,基于SigLIP视觉模型和Gemma语言模型等开放组件。它接受图像和文本输入并生成文本输出,支持多语言。专为在图像/短视频描述、视觉问答、文本阅读、目标检测和分割等广泛视觉语言任务上实现领先的微调性能而设计。
模型架构
PaliGemma由Transformer解码器和Vision Transformer图像编码器组成,总计30亿参数。文本解码器初始化自Gemma-2B,图像编码器初始化自SigLIP-So400m/14。训练遵循PaLI-3方案。
输入输出
- 输入: 图像和文本字符串(如图像描述提示或问题)
- 输出: 生成的响应文本(如图像描述、问题答案、目标边界框坐标列表或分割代码)
模型数据
预训练数据集
PaliGemma在以下混合数据集上预训练:
- WebLI: 从公开网络构建的网页级多语言图文数据集,用于获取视觉语义理解、目标定位、视觉文本理解等能力
- CC3M-35L: 网页英文图像-替代文本对,通过Google翻译API扩展至34种语言
- VQ²A-CC3M-35L/VQG-CC3M-35L: VQ2A-CC3M子集,翻译为相同34种语言
- OpenImages: 基于OpenImages数据集的手工规则生成的检测和对象感知问答
- WIT: 维基百科收集的图像和文本
数据责任过滤
对WebLI应用以下过滤:
- 色情图像过滤
- 文本安全过滤(移除涉及CSAI、色情、粗俗等内容)
- 文本毒性过滤(使用Perspective API识别侮辱性、淫秽、仇恨等内容)
- 文本个人信息过滤(使用Cloud DLP API移除社保号等敏感信息)
- 其他基于内容质量和安全策略的方法
使用方式
PaliGemma是单轮视觉语言模型,不适合对话场景,在特定用例微调后表现最佳。可通过任务前缀(如"detect"或"segment")配置模型任务。预训练模型通过此类提示结构获得丰富能力,但设计初衷是通过类似提示结构的微调迁移至特定任务。交互测试可使用"mix"系列模型(经多任务混合微调)。
Transformers中使用
以下示例使用google/paligemma-3b-mix-224
模型:
CPU运行默认精度(float32)
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
from PIL import Image
import requests
import torch
model_id = "google/paligemma-3b-mix-224"
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id).eval()
processor = AutoProcessor.from_pretrained(model_id)
prompt = "caption es"
model_inputs = processor(text=prompt, images=image, return_tensors="pt")
input_len = model_inputs["input_ids"].shape[-1]
with torch.inference_mode():
generation = model.generate(**model_inputs, max_new_tokens=100, do_sample=False)
print(processor.decode(generation[0][input_len:], skip_special_tokens=True))
输出:Un auto azul estacionado frente a un edificio.
CUDA运行其他精度
使用bfloat16
或float16
修订版本减少下载大小:
model = PaliGemmaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="cuda:0",
revision="bfloat16",
).eval()
4-bit/8-bit加载
需安装bitsandbytes
:
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
model = PaliGemmaForConditionalGeneration.from_pretrained(
model_id, quantization_config=quantization_config
)
实现信息
硬件
使用最新TPUv5e硬件训练。
软件
使用JAX、Flax、TFDS和big_vision
训练。微调代码和推理代码发布于big_vision
仓库。
评估信息
基准结果
在学术任务上微调预训练模型后评估(所有评估数据集均未出现在预训练数据中):
单任务微调
基准测试 |
指标 |
pt-224 |
pt-448 |
pt-896 |
COCO描述 |
CIDEr |
141.92 |
144.60 |
- |
文本VQA |
准确率 |
55.47 |
73.15 |
76.48 |
文档VQA |
ANLS |
43.74 |
78.02 |
84.77 |
RefCOCO分割 |
MIoU |
73.40 |
75.57 |
76.94 |
混合任务微调
基准测试 |
指标 |
mix-224 |
mix-448 |
MMVP |
配对准确率 |
46.00 |
45.33 |
POPE |
准确率 |
88.00 |
89.37 |
伦理与安全
评估方法
包括结构化评估和内部红队测试,涉及儿童安全、内容安全和表征危害等类别。使用FairFace数据集等基准评估图像到文本生成。
评估结果
- 伦理安全评估结果符合内部政策阈值
- 使用Perspective API测量FairFace图像描述的毒性指标(最大/中位值):
指标 |
感知性别 |
种族 |
年龄组 |
毒性 |
0.04% |
0.08% |
0.09% |
侮辱 |
0.06% |
0.09% |
0.16% |
使用与限制
预期用途
- 微调特定视觉语言任务(图像描述、视觉问答等)
- 视觉语言研究基础
伦理考量与风险
- 偏见与公平性:训练数据可能反映社会文化偏见
- 错误信息与滥用:可能生成虚假/有害内容
- 透明度与问责:本模型卡详述架构/能力/限制
局限性
- 继承Gemma模型多数限制(难以处理微妙语言、常识推理等)
- 主要设计为通用预训练模型,零样本性能可能不及专用模型
- 非多轮对话模型,仅支持单轮图像文本输入
引用
@article{beyer2024paligemma,
title={{PaliGemma: A versatile 3B VLM for transfer}},
author={Lucas Beyer* and Andreas Steiner* and André Susano Pinto* and Alexander Kolesnikov* and Xiao Wang* and Daniel Salz and Maxim Neumann and Ibrahim Alabdulmohsin and Michael Tschannen and Emanuele Bugliarello and Thomas Unterthiner and Daniel Keysers and Skanda Koppula and Fangyu Liu and Adam Grycner and Alexey Gritsenko and Neil Houlsby and Manoj Kumar and Keran Rong and Julian Eisenschlos and Rishabh Kabra and Matthias Bauer and Matko Bošnjak and Xi Chen and Matthias Minderer and Paul Voigtlaender and Ioana Bica and Ivana Balazevic and Joan Puigcerver and Pinelopi Papalampidi and Olivier Henaff and Xi Xiong and Radu Soricut and Jeremiah Harmsen and Xiaohua Zhai*},
year={2024},
journal={arXiv preprint arXiv:2407.07726}
}
论文链接:arXiv