SigLIP (base-sized model)
SigLIP model pre-trained on WebLi at resolution 384x384. It was introduced in the paper
Sigmoid Loss for Language Image Pre-Training by Zhai et al. and first released in
this repository.
Disclaimer: The team releasing SigLIP did not write a model card for this model so this model card has been written by the Hugging Face team.
Model description
SigLIP is CLIP, a multimodal model, with a better loss function. The sigmoid loss operates solely on image-text pairs and does not require a global view of the pairwise similarities for normalization. This allows further scaling up the batch size, while also performing better at smaller batch sizes.
A TLDR of SigLIP by one of the authors can be found
here.
Intended uses & limitations
You can use the raw model for tasks like zero-shot image classification and image-text retrieval. See the model hub to look for
other versions on a task that interests you.
How to use
Here is how to use this model to perform zero-shot image classification:
1from PIL import Image
2import requests
3from transformers import AutoProcessor, AutoModel
4import torch
5
6model = AutoModel.from_pretrained("google/siglip-base-patch16-384")
7processor = AutoProcessor.from_pretrained("google/siglip-base-patch16-384")
8
9url = "http://images.cocodataset.org/val2017/000000039769.jpg"
10image = Image.open(requests.get(url, stream=True).raw)
11
12texts = ["a photo of 2 cats", "a photo of 2 dogs"]
13inputs = processor(text=texts, images=image, padding="max_length", return_tensors="pt")
14
15with torch.no_grad():
16 outputs = model(**inputs)
17
18logits_per_image = outputs.logits_per_image
19probs = torch.sigmoid(logits_per_image) # these are the probabilities
20print(f"{probs[0][0]:.1%} that image 0 is '{texts[0]}'")
Alternatively, one can leverage the pipeline API which abstracts away the complexity for the user:
1from transformers import pipeline
2from PIL import Image
3import requests
4
5# load pipe
6image_classifier = pipeline(task="zero-shot-image-classification", model="google/siglip-base-patch16-384")
7
8# load image
9url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
10image = Image.open(requests.get(url, stream=True).raw)
11
12# inference
13outputs = image_classifier(image, candidate_labels=["2 cats", "a plane", "a remote"])
14outputs = [{"score": round(output["score"], 4), "label": output["label"] } for output in outputs]
15print(outputs)
For more code examples, we refer to the
documentation.
Training procedure
Training data
SigLIP is pre-trained on the English image-text pairs of the WebLI dataset
(Chen et al., 2023).
Preprocessing
Images are resized/rescaled to the same resolution (384x384) and normalized across the RGB channels with mean (0.5, 0.5, 0.5) and standard deviation (0.5, 0.5, 0.5).
Texts are tokenized and padded to the same length (64 tokens).
Compute
The model was trained on 16 TPU-v4 chips for three days.
Evaluation results
Evaluation of SigLIP compared to CLIP is shown below (taken from the paper).
BibTeX entry and citation info
1@misc{zhai2023sigmoid,
2 title={Sigmoid Loss for Language Image Pre-Training},
3 author={Xiaohua Zhai and Basil Mustafa and Alexander Kolesnikov and Lucas Beyer},
4 year={2023},
5 eprint={2303.15343},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV}
8}