PACS-DG-SigLIP2 is a vision-language encoder model fine-tuned from google/siglip2-base-patch16-224 for multi-class domain generalization classification. It is trained to distinguish visual domains such as art paintings, cartoons, photos, and sketches using the SiglipForImageClassification architecture.
[!note]
SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Featureshttps://arxiv.org/pdf/2502.14786
1from datasets import load_dataset
23# Load the dataset4dataset = load_dataset("flwrlabs/pacs")56# Extract unique masterCategory values (assuming it's a string field)7labels =sorted(set(example["domain"]for example in dataset["train"]))89# Create id2label mapping10id2label ={str(i): label for i, label inenumerate(labels)}1112# Print the mapping13print(id2label)
Label Space: 4 Domain Categories
The model predicts the most probable visual domain from the following:
Class 0: "art_painting"
Class 1: "cartoon"
Class 2: "photo"
Class 3: "sketch"
Install dependencies
pip install -q transformers torch pillow gradio
Inference Code
python
1import gradio as gr
2from transformers import AutoImageProcessor, SiglipForImageClassification
3from PIL import Image
4import torch
56# Load model and processor7model_name ="prithivMLmods/PACS-DG-SigLIP2"# Update to your actual model path on Hugging Face8model = SiglipForImageClassification.from_pretrained(model_name)9processor = AutoImageProcessor.from_pretrained(model_name)1011# Label map12id2label ={13"0":"art_painting",14"1":"cartoon",15"2":"photo",16"3":"sketch"17}1819defclassify_pacs_image(image):20 image = Image.fromarray(image).convert("RGB")21 inputs = processor(images=image, return_tensors="pt")2223with torch.no_grad():24 outputs = model(**inputs)25 logits = outputs.logits
26 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()2728 prediction ={29 id2label[str(i)]:round(probs[i],3)for i inrange(len(probs))30}3132return prediction
3334# Gradio Interface35iface = gr.Interface(36 fn=classify_pacs_image,37 inputs=gr.Image(type="numpy"),38 outputs=gr.Label(num_top_classes=4, label="Predicted Domain Probabilities"),39 title="PACS-DG-SigLIP2",40 description="Upload an image to classify its visual domain: Art Painting, Cartoon, Photo, or Sketch."41)4243if __name__ =="__main__":44 iface.launch()
Intended Use
The PACS-DG-SigLIP2 model is designed to support tasks in domain generalization, particularly:
Cross-domain Visual Recognition – Identify the domain style of an image.
Robust Representation Learning – Aid in training or evaluating models on domain-shifted inputs.
Dataset Characterization – Use as a tool to explore domain imbalance or drift.
Educational Tools – Help understand how models distinguish between stylistic image variations.