🚀 SigLIP (形狀優化模型)
SigLIP 是一種零樣本圖像分類模型,它基於多語言語料庫進行預訓練,在圖像分類和圖像 - 文本檢索等任務中表現出色。該模型由 Zhai 等人提出,為相關領域的研究和應用提供了新的解決方案。
🚀 快速開始
你可以使用此原始模型進行零樣本圖像分類和圖像 - 文本檢索等任務。更多版本可在 模型中心 查找。
✨ 主要特性
- SigLIP 是一種多模態模型,它在 CLIP 的基礎上採用了更好的損失函數。
- 其使用的 sigmoid 損失僅在圖像 - 文本對上操作,無需對成對相似度進行全局歸一化,這使得它在擴大批量大小時表現出色,同時在小批量大小下也能有良好性能。
💻 使用示例
基礎用法
以下是使用該模型進行零樣本圖像分類的示例代碼:
from PIL import Image
import requests
from transformers import AutoProcessor, AutoModel
import torch
model = AutoModel.from_pretrained("google/siglip-so400m-patch16-256-i18n")
processor = AutoProcessor.from_pretrained("google/siglip-so400m-patch16-256-i18n")
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-so400m-patch16-256-i18n")
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 模型採用 SoViT - 400m 架構,這是一種形狀優化版本,相關內容可參考論文 Getting ViT in Shape: Scaling Laws for Compute - Optimal Model Design 。該模型由 Zhai 等人在論文 Sigmoid Loss for Language Image Pre - Training 中提出,並首次在 此倉庫 發佈。
🔧 技術細節
訓練數據
SigLIP 在 WebLI 數據集 (Chen 等人, 2023) 上進行預訓練。
預處理
- 圖像被調整大小/重新縮放至相同分辨率 (384x384),並在 RGB 通道上使用均值 (0.5, 0.5, 0.5) 和標準差 (0.5, 0.5, 0.5) 進行歸一化。
- 文本被分詞並填充至相同長度 (64 個標記)。
計算資源
該模型在 16 個 TPU - v4 芯片上訓練了三天。
📄 許可證
本模型採用 Apache - 2.0 許可證。
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 的團隊未為此模型編寫模型卡片,此模型卡片由 Hugging Face 團隊編寫。