Downloads · 30 days
25
2% of all-time downloads
acaciabengo/nsfw_image_detection
nsfw_image_detection is a image classification model from acaciabengo. Use it when you need a label for an image. The card lists the license as apache-2.0.
This model is a Vision Transformer (ViT) with a base size and a patch size of 16 (ViT-B/16), pre-trained on a large dataset. It has been fine-tuned for the purpose of NSFW (Not Safe For Work) content detection in imag…
Downloads · 30 days
25
2% of all-time downloads
All-time downloads
1.4K
Public
Parameters
85.8M
1 GB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors343 MB · 100%
From the Hugging Face model README
This model is a Vision Transformer (ViT) with a base size and a patch size of 16 (ViT-B/16), pre-trained on a large dataset. It has been fine-tuned for the purpose of NSFW (Not Safe For Work) content detection in images, classifying them into specific categories.
The model was fine-tuned using the nsfw_dataset_v1 dataset. This dataset comprises five distinct classes:
drawingshentaineutralpornsexyThe dataset was split into training, validation, and test sets with the following sizes:
Training Set Size: 19600 images
Validation Set Size: 4200 images
Test Set Size: 4200 images
Classes:
classes: {'drawings': 0, 'hentai': 1, 'neutral': 2, 'porn': 3, 'sexy': 4}
The model was trained with the following configurations:
The fine-tuned model's performance was evaluated on the test set, yielding the following metrics:
precision recall f1-score support
0 0.85 0.88 0.87 807
1 0.94 0.88 0.91 839
2 0.90 0.93 0.92 870
3 0.98 0.94 0.96 861
4 0.92 0.97 0.94 823
accuracy 0.92 4200
macro avg 0.92 0.92 0.92 4200
weighted avg 0.92 0.92 0.92 4200

from transformers import ViTImageProcessor, ViTForImageClassification
from PIL import Image
import requests
import torch
# Load the model and processor
model_name = "acaciabengo/nsfw_image_detection"
processor = ViTImageProcessor.from_pretrained(model_name)
model = ViTForImageClassification.from_pretrained(model_name)
# Mapping IDs to human-readable labels
labels = {'drawings': 0, 'hentai': 1, 'neutral': 2, 'porn': 3, 'sexy': 4}
id_to_label = {v: k for k, v in labels.items()}
# Load an image from a URL or local path
url = "https://example.com/sample_image.jpg"
image = Image.open(requests.get(url, stream=True).raw)
# Preprocess image and perform inference
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
# Calculate probabilities and get the top prediction
probabilities = logits.softmax(dim=-1).squeeze().tolist()
predicted_class_idx = logits.argmax(-1).item()
print(f"Predicted label: {id_to_label[predicted_class_idx]}")
print("\nProbabilities:")
for i, prob in enumerate(probabilities):
print(f"- {id_to_label[i]}: {prob:.2%}")
This model is available via a high-availability, low-latency API for production use cases on RapidApi
This model is intended for the automatic detection and categorization of NSFW content in images. It can be used in applications requiring content moderation, filtering, or analysis to identify images belonging to 'drawings', 'hentai', 'neutral', 'porn', or 'sexy' categories.