Views
No views yet
google/siglip-base-patch16-512Note: This is a stripped-down copy ofgoogle/siglip-base-patch16-512containing only the vision tower. It encodes images / video frames into the shared embedding space and is meant to be loaded on its own at indexing time, separately from the other tower. Splitting the towers lets you load only the half you need, saving memory and load time.The text tower (used at retrieval time) lives inVeritone/siglip-base-patch16-512-text.
1from PIL import Image
2import requests
3from transformers import AutoProcessor, AutoModel
4import torch
5
6model = AutoModel.from_pretrained("google/siglip-base-patch16-512")
7processor = AutoProcessor.from_pretrained("google/siglip-base-patch16-512")
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]}'")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-512")
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)
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}