siglip_400m
收藏SigLIP (shape-optimized model)
模型描述
SigLIP 是一个多模态模型,基于 CLIP 模型改进,采用了一种更好的损失函数。该模型在图像-文本对上操作,不需要全局视图来进行归一化,从而允许进一步扩大批量大小,同时在较小的批量大小下表现更好。
预期用途与限制
该模型可用于零样本图像分类和图像-文本检索等任务。
如何使用
以下是如何使用该模型进行零样本图像分类的示例:
python from PIL import Image import requests from transformers import AutoProcessor, AutoModel import torch
model = AutoModel.from_pretrained("google/siglip-so400m-patch14-384") processor = AutoProcessor.from_pretrained("google/siglip-so400m-patch14-384")
url = "http://images.cocodataset.org/val2017/000000039769.jpg" image = Image.open(requests.get(url, stream=True).raw)
texts = ["a photo of 2 cats", "a photo of 2 dogs"] inputs = processor(text=texts, images=image, padding="max_length", return_tensors="pt")
with torch.no_grad(): outputs = model(**inputs)
logits_per_image = outputs.logits_per_image probs = torch.sigmoid(logits_per_image) # these are the probabilities print(f"{probs[0][0]:.1%} that image 0 is {texts[0]}")
或者使用 pipeline API 简化使用:
python from transformers import pipeline from PIL import Image import requests
load pipe
image_classifier = pipeline(task="zero-shot-image-classification", model="google/siglip-so400m-patch14-384")
load image
url = http://images.cocodataset.org/val2017/000000039769.jpg image = Image.open(requests.get(url, stream=True).raw)
inference
outputs = image_classifier(image, candidate_labels=["2 cats", "a plane", "a remote"]) outputs = [{"score": round(output["score"], 4), "label": output["label"] } for output in outputs] print(outputs)
训练过程
训练数据
SigLIP 在 WebLI 数据集上进行了预训练。
预处理
图像被调整/缩放到相同的分辨率(384x384),并在 RGB 通道上进行归一化,均值为 (0.5, 0.5, 0.5),标准差为 (0.5, 0.5, 0.5)。文本被标记化并填充到相同的长度(64 个标记)。
计算资源
该模型在 16 个 TPU-v4 芯片上训练了三天。
评估结果
SigLIP 与 CLIP 的评估结果如下(摘自论文):
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/siglip_table.jpeg" alt="drawing" width="600"/>
BibTeX 条目和引用信息
bibtex @misc{zhai2023sigmoid, title={Sigmoid Loss for Language Image Pre-Training}, author={Xiaohua Zhai and Basil Mustafa and Alexander Kolesnikov and Lucas Beyer}, year={2023}, eprint={2303.15343}, archivePrefix={arXiv}, primaryClass={cs.CV} }




