SigLIP#
This example demonstrates using the SigLIP model to perform image classification.
Parameters#
- model_name (
str
, optional): The name of the pre-trained model to use. Defaults to"google/siglip-base-patch16-224"
. - device (
Device
, optional): The device to run the model on. If not specified, it will default to GPU if available, otherwise CPU. - image (
Image.Image
): The image to classify. - labels (
List[str]
): The list of candidate labels to classify the image.
Perform Zero-Shot Image Classification#
The model processes a given image and provided labels and produces classification scores for each candidate label. These scores represent the model's confidence in each label being the correct classification for the image. To perform zero-shot image classification using the SigLIP model, follow these steps:
-
Initialize the Model:
-
Prepare the Image and Labels:
-
Run the Classification:
-
Interpret the Results:
The higher the score, the more confident the model is that the label is the correct classification. This information can be used to understand the model's decision-making process and to evaluate its performance.
Example: - Label: A, 0.85% - Label: B, 0.10% - Label: C, 0.05%
In this example, the model is most confident that the image belongs to Label A.