A mobile-friendly visual content moderation model, based on the work of
F. C. Akyon obtained by fine-tuning
EfficientNet-b0 on nsfw images to detect nudity and sexual content in images or video frames
with high accuracy.
Nsfw image detection performance of
nsfw-detector-nano compared with
Azure Content Safety AI and
Falconsai nsfw image detection model.
F_safe and
F_nsfw below are class-wise F1 scores for safe and nsfw classes, respectively.
Results show that
nsfw-detector-nano performs better than Falconsai and is comparable to Azure AI with less number of parameters.
1from moderators import AutoModerator
2
3model = AutoModerator.from_pretrained("viddexa/nsfw-detection-nano")
4results = model("<path-to-image-file>")
5
6probs = {k: v for r in results for k, v in r.classifications.items()}
7predicted_label = max(probs, key=probs.get)
1from transformers import (
2 AutoImageProcessor,
3 AutoModelForImageClassification)
4from PIL import Image
5import torch
6
7img = Image.open("<path-to-image-file>")
8
9processor = AutoImageProcessor.from_pretrained("viddexa/nsfw-detection-nano", use_fast = False)
10model= AutoModelForImageClassification.from_pretrained("viddexa/nsfw-detection-nano")
11
12with torch.no_grad():
13 inputs = processor(images=img, return_tensors="pt")
14 outputs = model(**inputs)
15 logits = outputs.logits
16 probs = torch.softmax(logits, dim=-1)
17 pred_id = int(probs.argmax())
18 print(model.config.id2label[pred_id])
A binary nudity and sexual content classification model that classifies images either as Safe or NSFW.
Model is obtained by fine-tuning google's Efficientnet-b0.
This model is designed to detect explicit nudity alone. An image containing
suggestive nudity or risqué clothing is labeled as safe if there is no explicit nudity in the image.
1@article{akyon2023nudity,
2 title={State-of-the-art in nudity classification: A comparative analysis},
3 author={Akyon, Fatih Cagatay and Temizel, Alptekin},
4 booktitle={2023 IEEE International Conference on Acoustics, Speech, and Signal Processing Workshops (ICASSPW)},
5 pages={1--5},
6 year={2023},
7 organization={IEEE}
8}