nsfw-image-detection 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.
1 Classification 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
8 Enticing 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
1 import gradio as gr
2 from transformers import AutoImageProcessor , SiglipForImageClassification
3 from PIL import Image
4 import torch
5
6 # Load model and processor
7 model_name = "strangerguardhf/nsfw-image-detection" # Replace with your model path if needed
8 model = SiglipForImageClassification . from_pretrained ( model_name )
9 processor = AutoImageProcessor . from_pretrained ( model_name )
10
11 # ID to Label mapping
12 id2label = {
13 "0" : "Anime Picture" ,
14 "1" : "Hentai" ,
15 "2" : "Normal" ,
16 "3" : "Pornography" ,
17 "4" : "Enticing or Sensual"
18 }
19
20 def 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
36 iface = 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 = "nsfw-image-detection" ,
41 description = "Classifies images into explicit, suggestive, or safe categories (e.g., Hentai, Pornography, Normal)."
42 )
43
44 if __name__ == "__main__" :
45 iface . launch ( )
Class 0: "Anime Picture"
Class 1: "Hentai"
Class 2: "Normal"
Class 3: "Pornography"
Class 4: "Enticing or Sensual"