Downloads · 30 days
0
Pankaj8922/nsfw-detector-tiny
nsfw-detector-tiny is a image classification model from Pankaj8922. Use it when you need a label for an image. It is set up for timm. The card lists the license as apache-2.0.
A fine-tuned ConvNeXt model for binary NSFW/SFW image classification. This model distinguishes between safe-for-work and not-safe-for-work content in real-world images, including photographs, illustrations, and animat…
Downloads · 30 days
0
Access
Public
Updated May 24, 2026
Repo size
334 MB
Likes
1
Public
Click a slice to open those files.
.pth334 MB · 100%
From the Hugging Face model README
A fine-tuned ConvNeXt model for binary NSFW/SFW image classification. This model distinguishes between safe-for-work and not-safe-for-work content in real-world images, including photographs, illustrations, and animated content.
This model classifies images as either SFW (0) or NSFW (1). Built on the ConvNeXt architecture family from timm, pre-trained on ImageNet-22k and fine-tuned on a diverse dataset of real images including photographs, animated content, and various image formats.
| Variant | Model ID | Parameters | Status |
|---|---|---|---|
| Tiny | Pankaj8922/nsfw-detector-tiny | ~28M | ✅ Uploaded |
| Small | Pankaj8922/nsfw-detector-small | ~50M | ✅ Uploaded |
| Base | Pankaj8922/nsfw-detector-base | ~89M | ✅ Uploaded |
This model is designed for automated NSFW content detection in various image types including:
Images are resized to 224×224 and normalized using ImageNet statistics. Training augmentations include:
| Epoch | Loss | Accuracy |
|---|---|---|
| 1 | 0.0343 | 98.81% |
| 2 | 0.0180 | 99.37% |
Note: This model was trained on the entire dataset without a validation split. The reported metrics are training metrics and may overestimate real-world performance. For production use, consider evaluating on a held-out test set.
pip install timm torch torchvision pillow
import torch
import timm
from PIL import Image
from torchvision import transforms
from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
from huggingface_hub import hf_hub_download
# Download model from Hub
model_path = hf_hub_download(
repo_id="Pankaj8922/nsfw-detector-tiny",
filename="convnext_tiny_stickers_final.pth"
)
# Load model
model = timm.create_model("convnext_tiny.fb_in22k", pretrained=False, num_classes=2)
checkpoint = torch.load(model_path)
# Handle both formats: direct state dict or wrapped in checkpoint dict
if 'model_state_dict' in checkpoint:
model.load_state_dict(checkpoint['model_state_dict'])
else:
model.load_state_dict(checkpoint)
model.eval()
# Preprocess
transform = transforms.Compose([
transforms.Resize(224),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=IMAGENET_DEFAULT_MEAN, std=IMAGENET_DEFAULT_STD),
])
# Predict
image = Image.open("image.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
output = model(input_tensor)
prediction = output.argmax().item()
probability = torch.softmax(output, dim=1)
labels = {0: "SFW", 1: "NSFW"}
print(f"Prediction: {labels[prediction]}")
print(f"Confidence: {probability[0][prediction]:.2%}")