Zero-shot Image Classification with SigLIP2
Zero-shot image classification is a computer vision task with the goal to classify images into one of several classes without any prior training or knowledge of these classes.
Content
Zero-shot Image Classification with SigLIP2
Zero-shot image classification is a computer vision task with the goal to classify images into one of several classes without any prior training or knowledge of these classes.
In this tutorial, you will use the SigLIP2 model to perform zero-shot image classification.
Notebook Contents
The SigLIP model was proposed in Sigmoid Loss for Language Image Pre-Training. SigLIP proposes to replace the loss function used in CLIP (Contrastive Language–Image Pre-training) by a simple pairwise sigmoid loss. This results in better performance in terms of zero-shot classification accuracy on ImageNet.
The abstract from the paper is the following:
We propose a simple pairwise Sigmoid loss for Language-Image Pre-training (SigLIP). Unlike standard contrastive learning with softmax normalization, the sigmoid loss operates solely on image-text pairs and does not require a global view of the pairwise similarities for normalization. The sigmoid loss simultaneously allows further scaling up the batch size, while also performing better at smaller batch sizes.
You can find more information about this model in the research paper, GitHub repository, Hugging Face model page.
SigLIP 2 extends the pretraining objective of SigLIP with prior, independently developed techniques into a unified recipe, 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). More details about SigLIP 2 can be found in blog post
.
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). A cherry on top is the dynamic resolution (naflex) variant. This is useful for downstream tasks sensitive to aspect ratio and resolution.
In this notebook, we will use google/siglip2-base-patch16-224 by default, but the same steps are applicable for other SigLIP family models.
The notebook contains the following steps:
- Instantiate model.
- Run PyTorch model inference.
- Convert the model to OpenVINO Intermediate Representation (IR) format.
- Run OpenVINO model.
- Apply post-training quantization using NNCF:
- Prepare dataset.
- Quantize model.
- Run quantized OpenVINO model.
- Compare File Size.
- Compare inference time of the FP16 IR and quantized models.
The results of the SigLIP model's performance in zero-shot image classification from this notebook are demonstrated in the image below. !image
Installation Instructions
This is a self-contained example that relies solely on its own code.</br> We recommend running the notebook in a virtual environment. You only need a Jupyter server to start. For details, please refer to [Installation Guide](../../README.md).
Source and license
- Source
- Intel OpenVINO Notebooks
- Original
- openvinotoolkit/openvino_notebooks/notebooks/siglip-zero-shot-image-classification
- License
- Apache-2.0