Views
No views yet

SigLIP2-ImageShield-2n-large-256 is a vision-language encoder model fine-tuned from google/siglip2-large-patch16-256 for binary image classification. Built on the SiglipForImageClassification architecture, the model is designed to identify and categorize visual content into safe/normal and unsafe/sensual categories for media filtering.
[!IMPORTANT] This model is experimental. Expert multimodal models are available here: ImageShield Multimodal SFT Collection.
[!note] SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features https://arxiv.org/pdf/2502.14786
1Class 0: "Safe and Normal"
2Class 1: "Unsafe and Sensual"pip install transformers torch torchvision pillow gradio1import gradio as gr
2from transformers import AutoImageProcessor, SiglipForImageClassification
3from PIL import Image
4import torch
5
6# Load model and processor
7model_name = "prithivMLmods/SigLIP2-ImageShield-2n-large-256" # Replace with your model path if needed
8model = SiglipForImageClassification.from_pretrained(model_name)
9processor = AutoImageProcessor.from_pretrained(model_name)
10
11# ID to Label mapping
12id2label = {
13 "0": "Safe and Normal",
14 "1": "Unsafe and Sensual"
15}
16
17def classify_image(image):
18 image = Image.fromarray(image).convert("RGB")
19 inputs = processor(images=image, return_tensors="pt")
20
21 with torch.no_grad():
22 outputs = model(**inputs)
23 logits = outputs.logits
24 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
25
26 prediction = {
27 id2label[str(i)]: round(probs[i], 3)
28 for i in range(len(probs))
29 }
30
31 return prediction
32
33# Gradio Interface
34iface = gr.Interface(
35 fn=classify_image,
36 inputs=gr.Image(type="numpy"),
37 outputs=gr.Label(
38 num_top_classes=2,
39 label="Predicted Content Type"
40 ),
41 title="SigLIP2-ImageShield-2n-large-256",
42 description="Classifies images into Safe and Normal or Unsafe and Sensual categories."
43)
44
45if __name__ == "__main__":
46 iface.launch()




