According to recent reports, today Google releases a new and better family of multilingual vision-language encoders, SigLIP 2. The authors have extended the training objective of SigLIP (sigmoid loss) with additional objectives for improved semantic understanding, localization, and dense features.

SigLIP 2 models outperform the older SigLIP ones at all model scales in core capabilities, including zero-shot classification, image-text retrieval, and transfer performance when extracting visual representations for Vision-Language Models (VLMs). (Related: Introducing RTEB: A Fresh Standard for Retrieval Evalua...)

A cherry on top is the dynamic resolution (naflex) variant. This is useful for downstream tasks sensitive to aspect ratio and resolution.

Here is a list of all the models released:. (Related: Supercharge your OCR Pipelines with Open Models...)

It has been revealed that vision encoders are simple - they take an image, encode it into a representation, and that representation is used for downstream tasks like classification, object detection, image segmentation, and more vision tasks. Researchers are always in pursuit of visual representations that are dense, locality-aware, and semantically rich.

Sources indicate that CLIP and ALIGN are the first examples of image encoders and text encoders aligned together through joint training. This approach opened new ways to train vision models. SigLIP took it further, replacing CLIP's contrastive loss with sigmoid loss for even better encoders.

Recent findings suggest that the takeaway? With smarter training objectives, we keep building vision encoders that are more structured, fine-grained, and powerful. SigLIP 2 is just that, a bunch of really interesting and smart training objectives applied on top of that of SigLIP's to provide better and stronger vision language encoders.

We will try something latest with this blog post. Rather than stating what is new and where to find it, we will go through a little exercise together. We start off with SigLIP and then brainstorm a series of questions (prefixed with πŸ€”) and answers (a new heading) to gradually cover all the updates in SigLIP 2. Sounds good?

Sources indicate that we will begin our journey with the vision encoder where the patch size is 16, and the image resolution is 256. We have four variants to start our training:.

πŸ€” Question 1: What is a (low effort) auxiliary training objective that we can use to learn better visual representations (in terms of location awareness and sense of locality)?

Let’s add a decoder to the mix. Now we have an image encoder, a text encoder, and a text decoder. The text decoder will have three objectives:.

It has been revealed that the decoder provides an additional signal to the vision encoder, making it location-aware. This marks the first improvement to the training recipe in SigLIP 2.

πŸ€” Question 2: How do we improve fine-grained local semantics of the image representation?

To improve fine-grained local semantics in image representation, we introduce two key training objectives, Global-Local Loss, and Masked Prediction Loss. Taking inspiration from self-supervised learning literature, we use self-distillation. We can use a model as a teacher, and the same model as a student. Upon each iteration the teacher will be the moving average of the student's parameters.

It has been revealed that these objectives teach the vision encoder to be spatially aware and improve its local semantics. The authors add this loss only after 80% of the training is done with the sigmoid and decoder loss. This is done in order to save compute (additional losses are pretty expensive) and to not negatively affect the encoders.

πŸ€” Question 3: How to adapt models to different resolutions?

In a recent development, it is a known fact that image models can be very sensitive to varying resolutions and aspect ratios. Here we can leverage two distinct methodologies to adapt these models on different resolutions and patch sizes.

Models with the -naflex suffix are the dynamic resolution variants. While the fixed-resolution models can be used out of the box with the existing SiglipModel class, you would need to use Siglip2Model to use the naflex variants. We handle this automatically when you use the pipeline API!

This brings us to the end of the evolution from SigLIP to SigLIP 2. In the next sections we will look at applications with SigLIP 2.

Sources indicate that running inference on the models is pretty straightforward. You can copy paste the code below and run inference on a free tier Colab notebook πŸš€.

To run inference on SigLIP 2, please install transformers from main or from this stable branch: pip install git+https://github.com/huggingface/transformers@v4.49.0-SigLIP-2.

Here we use the handy pipeline API to showcase zero-shot classification capabilities for SigLIP 2.

You can also encode images using the following:.

Looking at the table of all the SigLIP 2 models released, we see two distinct changes from SigLIP:.

The evaluation table of SigLIP 2 demonstrates its superiority over SigLIP.

Here is a demo where one can compare the zero-shot classification results of SigLIP 1 and SigLIP 2.

Vision encoders aligned to textual information have become increasingly vital in the development of Vision Language Models (VLMs). A common approach to building VLMs involves combining a pretrained vision encoder with a pretrained LLM, and training them together using multimodal data across a diverse set of vision-language tasks.

One standout example of a VLM leveraging the SigLIP family of vision encoders is PaliGemma. One can dive deeper into PaliGemma's capabilities in this PaliGemma blog post. Building on this foundation, the recently introduced PaliGemma 2 takes it a step further by integrating SigLIP with the advanced Gemma 2 LLM. It would be really exciting to swap out SigLIP with SigLIP 2 in a PaliGemma like setting and see how that model fares.

We would like to thank Michael Tschannen (first author of SigLIP 2), Vaibhav Srivastav and Sayak Paul for feedback on this blog post. A huge shout out to the Google team for releasing this amazing, and open, model family.

In no particular order we would like to thank Pavel, Ross, Pablo, Pedro, Lysandre and the rest of the Hugging Face team for their immense support and contribution towards this project.

Might want to check something: The demo at the bottom hangs with "Uploading 1 file..." and none of the premade examples load or execute. 6 different Javascript console errors are thrown. (Chrome, Mac).

OpenCLIP & timm weights are up now, https://huggingface.co/collections/timm/siglip-2-67b8e72ba08b09dd97aecaf9.

It has been revealed that siglip2 does not include 'spiece.model' as in Siglip. Is this expected? The processor raises an error indicating that the vocab file is a NoneType object, which may suggest a missing spiece model. Any ideas?

Could you install transformers from main?

pip install git+https://github.com/huggingface/transformers@main.

Sources indicate that let us know if this solves the issue. πŸ€—.

I tried running the zeroshot classification example and got ValueError: Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' 'truncation=True' to have batched tensors with the same length. Perhaps your features (input_idsin this case) have excessive nesting (inputs typelistwhere typeintis expected). transformers version=4.49.0.dev0.

Recent findings suggest that I tried adding both padding=True and truncation=True to no avail. i also tried padding="max_length".

According to recent reports, EDIT:it seems to work if my labels are all the same length. doing some debugging, i see that in zero_shot_image_classification.py, the padding provided to the tokenizer is forced to be max_length anyway here (L148-149).

Sources indicate that and yet, if my labels have variable lengths, the outputs are not the same length, and so calling torch.tensor on that ultimately failsi did spot this warning in my terminal as well:Asking to pad to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no padding.

The warning gives you the answer: pass max_length=64.

"When using the standalone GemmaTokenizerFast make sure to pass padding="max_length" and max_length=64 as that’s how the model was trained." Does Siglip2 support longer text input? If the max_length is set to 256 or 512, will text exceeding 64 be truncated?

According to recent reports, yes. If you want longer text, what I'd do is chunk it into pieces of 64 tokens (possibly even overlapping), embed those separately, and either average their endings or dot them with the image embedding individually and take max or average score, depending on your use case.

Recent findings suggest that I'm actually curious what kind of queries you're dealing with that are longer than 64 tokens? All use cases of siglip i can think of almost always fit in way below 64.

/lib/python3.10/site-packages/transformers/models/siglip/tokenization_siglip.py", line 139, in get_spm_processor with open(self.vocab_file, "rb") as f:TypeError: expected str, bytes or os.PathLike object, not NoneType.

Could you install transformers from main?

pip install git+https://github.com/huggingface/transformers@main.

Let us know if this solves the glitch. πŸ€—.

There are really 3 cats, it's just that one of them is pregnant.

According to recent reports, does anyone know where to find benchmarks for the naflex variants? I could be blind, but it seems they're not in the graph?Edit: nvm, just go to the appendix.

when i input an img and a text to model.

the output logits isSiglipOutput(loss=None, logits_per_image=tensor([[-15.5217]], device='cuda:0'), logits_per_text=tensor([[-15.5217]], device='cuda:0').

after sigmoid the output is ~0.

Is there any examples provided for fine-tuning on a custom dataset?

@nielsr has a great notebook on fine tuning siglip and similar models.

https://github.com/NielsRogge/Transformers-Tutorials/tree/master/SigLIP.

It has been revealed that hello everyone,am I wrong or is the zero shot classification not really working. You can take a look at the provided example, we replaced the original image with another one and added the text "golf" to the text corpus. Also with other examples, and different backbones, it seems like that zero shot is not really working.

(try it here: https://colab.research.google.com/github/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/siglip-zero-shot-image-classification/siglip-zero-shot-image-classification.ipynb).

Also the code provided here: https://huggingface.co/docs/transformers/main/en/model_doc/siglip2 never works, at least not with using sigmoid.

Industry observers note that indeed. If you want lengthier text, I would divide it into 64-token chunks.... (perhaps even overlapping), embed each one separately, and then either average.... the ends or, depending on your use case, dot each one with the picture..... embedding and calculate the maximum or average score.

Actually, I'm wondering what kinds of searches longer than 64 tokens you deal with. Almost every Siglip.... use case that comes to mind falls well below 64.

β†’ Read original article