Views
No views yet
1from transformers import pipeline
2
3# load pipeline
4ckpt = "google/siglip2-base-patch32-256"
5image_classifier = pipeline(model=ckpt, task="zero-shot-image-classification")
6
7# load image and candidate labels
8url = "http://images.cocodataset.org/val2017/000000039769.jpg"
9candidate_labels = ["2 cats", "a plane", "a remote"]
10
11# run inference
12outputs = image_classifier(image, candidate_labels)
13print(outputs)1import torch
2from transformers import AutoModel, AutoProcessor
3from transformers.image_utils import load_image
4
5# load the model and processor
6ckpt = "google/siglip2-base-patch32-256"
7model = AutoModel.from_pretrained(ckpt, device_map="auto").eval()
8processor = AutoProcessor.from_pretrained(ckpt)
9
10# load the image
11image = load_image("https://huggingface.co/datasets/merve/coco/resolve/main/val2017/000000000285.jpg")
12inputs = processor(images=[image], return_tensors="pt").to(model.device)
13
14# run infernece
15with torch.no_grad():
16 image_embeddings = model.get_image_features(**inputs)
17
18print(image_embeddings.shape)
1@misc{tschannen2025siglip2multilingualvisionlanguage,
2 title={SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features},
3 author={Michael Tschannen and Alexey Gritsenko and Xiao Wang and Muhammad Ferjad Naeem and Ibrahim Alabdulmohsin and Nikhil Parthasarathy and Talfan Evans and Lucas Beyer and Ye Xia and Basil Mustafa and Olivier Hénaff and Jeremiah Harmsen and Andreas Steiner and Xiaohua Zhai},
4 year={2025},
5 eprint={2502.14786},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2502.14786},
9}