Views
No views yet

siglip2-x256-explicit-content is a vision-language encoder model fine-tuned from siglip2-base-patch16-256 for multi-class image classification. Built on the SiglipForImageClassification architecture, the model is trained to identify and categorize content types in images, especially for explicit, suggestive, or safe media filtering.
[!note] SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features https://arxiv.org/pdf/2502.14786
1Classification Report:
2 precision recall f1-score support
3
4 Anime Picture 0.8940 0.8718 0.8827 5600
5 Hentai 0.8961 0.8935 0.8948 4180
6 Normal 0.9100 0.8895 0.8997 5503
7 Pornography 0.9496 0.9654 0.9574 5600
8Enticing or Sensual 0.9132 0.9429 0.9278 5600
9
10 accuracy 0.9137 26483
11 macro avg 0.9126 0.9126 0.9125 26483
12 weighted avg 0.9135 0.9137 0.9135 26483
Class 0: "Anime Picture"
Class 1: "Hentai"
Class 2: "Normal"
Class 3: "Pornography"
Class 4: "Enticing or Sensual"pip install -q transformers torch 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-x256-explicit-content" # 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": "Anime Picture",
14 "1": "Hentai",
15 "2": "Normal",
16 "3": "Pornography",
17 "4": "Enticing or Sensual"
18}
19
20def classify_explicit_content(image):
21 image = Image.fromarray(image).convert("RGB")
22 inputs = processor(images=image, return_tensors="pt")
23
24 with torch.no_grad():
25 outputs = model(**inputs)
26 logits = outputs.logits
27 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
28
29 prediction = {
30 id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
31 }
32
33 return prediction
34
35# Gradio Interface
36iface = gr.Interface(
37 fn=classify_explicit_content,
38 inputs=gr.Image(type="numpy"),
39 outputs=gr.Label(num_top_classes=5, label="Predicted Content Type"),
40 title="siglip2-x256-explicit-content",
41 description="Classifies images into explicit, suggestive, or safe categories (e.g., Hentai, Pornography, Normal)."
42)
43
44if __name__ == "__main__":
45 iface.launch()