🚀 SigLIP (形狀優化模型)
SigLIP是一種多模態模型,它改進了損失函數,可用於零樣本圖像分類和圖像 - 文本檢索等任務,在圖像相關任務上表現出色。
🚀 快速開始
你可以使用這個原始模型進行零樣本圖像分類和圖像 - 文本檢索等任務。可查看模型中心,尋找你感興趣的其他版本。
✨ 主要特性
- SigLIP是CLIP的改進版,採用了更好的損失函數。
- 其使用的sigmoid損失僅在圖像 - 文本對上操作,無需對成對相似性進行全局歸一化,可進一步擴大批量大小,且在小批量時也表現良好。
📦 安裝指南
文檔未提及具體安裝步驟,可參考transformers
庫的安裝方式。
💻 使用示例
基礎用法
from PIL import Image
import requests
from transformers import AutoProcessor, AutoModel
import torch
model = AutoModel.from_pretrained("google/siglip-so400m-patch14-224")
processor = AutoProcessor.from_pretrained("google/siglip-so400m-patch14-224")
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]}'")
高級用法
from transformers import pipeline
from PIL import Image
import requests
image_classifier = pipeline(task="zero-shot-image-classification", model="google/siglip-so400m-patch14-224")
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是一種多模態模型,它改進了CLIP的損失函數。sigmoid損失僅在圖像 - 文本對上操作,無需對成對相似性進行全局歸一化,這使得在進一步擴大批量大小的同時,在小批量時也能有更好的表現。一位作者對SigLIP的簡要總結可在此處找到。
預期用途和侷限性
可使用原始模型進行零樣本圖像分類和圖像 - 文本檢索等任務。可查看模型中心,尋找你感興趣的其他版本。
訓練過程
訓練數據
SigLIP在WebLI數據集(Chen et al., 2023)上進行預訓練。
預處理
- 圖像被調整大小/重新縮放至相同分辨率(384x384),並在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}
}
🔧 技術細節
SigLIP模型在分辨率為224x224的WebLi上進行預訓練。它由Zhai等人在論文Sigmoid Loss for Language Image Pre-Training中提出,並首次在此倉庫發佈。該模型採用SoViT - 400m架構,這是Alabdulmohsin等人在Getting ViT in Shape: Scaling Laws for Compute-Optimal Model Design中提出的形狀優化版本。
📄 許可證
本模型使用Apache - 2.0許可證。
⚠️ 重要提示
發佈SigLIP的團隊未為此模型編寫模型卡片,此模型卡片由Hugging Face團隊編寫。