🚀 SigLIP (基礎規模模型)
SigLIP是一種多模態模型,它在分辨率為512x512的WebLi數據集上進行了預訓練。該模型引入了更優的損失函數,能在圖像 - 文本對任務上表現出色,可用於零樣本圖像分類和圖像 - 文本檢索等任務。
🚀 快速開始
SigLIP是一種改進版的CLIP多模態模型,它採用了更優的損失函數。Sigmoid損失僅作用於圖像 - 文本對,無需對成對相似度進行全局歸一化,這使得它在擴大批量大小的同時,在小批量下也能有出色表現。
✨ 主要特性
- 更優損失函數:Sigmoid損失無需全局歸一化,可擴大批量大小,小批量表現也佳。
- 多用途:可用於零樣本圖像分類和圖像 - 文本檢索等任務。
📦 安裝指南
文檔未提及安裝步驟,可參考Hugging Face的通用安裝方法安裝相關依賴庫。
💻 使用示例
基礎用法
以下是使用該模型進行零樣本圖像分類的示例代碼:
from PIL import Image
import requests
from transformers import AutoProcessor, AutoModel
import torch
model = AutoModel.from_pretrained("google/siglip-base-patch16-512")
processor = AutoProcessor.from_pretrained("google/siglip-base-patch16-512")
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)
print(f"{probs[0][0]:.1%} that image 0 is '{texts[0]}'")
高級用法
也可以使用pipeline API簡化操作:
from transformers import pipeline
from PIL import Image
import requests
image_classifier = pipeline(task="zero-shot-image-classification", model="google/siglip-base-patch16-512")
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
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數據集的英文圖像 - 文本對上進行預訓練,相關論文為(Chen et al., 2023)。
預處理
- 圖像:將圖像調整/縮放至相同分辨率(512x512),並在RGB通道上進行歸一化,均值為(0.5, 0.5, 0.5),標準差為(0.5, 0.5, 0.5)。
- 文本:對文本進行分詞並填充至相同長度(64個標記)。
計算資源
該模型在16個TPU - v4芯片上訓練了三天。
評估結果
SigLIP與CLIP的評估對比結果如下(取自論文):

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}
}
📄 許可證
本模型採用Apache 2.0許可證。