Downloads · 30 days
13
20% of all-time downloads
theusamaaslam/vit-base-nsfw-detection-224
vit-base-nsfw-detection-224 is a image classification model from theusamaaslam. Use it when you need a label for an image. It is set up for transformers. The card lists the license as mit.
This is a fine-tuned version of google/vit-base-patch16-224, optimized for NSFW (Not Safe For Work) content detection. It leverages the high-resolution (224x224) Vision Transformer architecture to capture fine-grained…
Downloads · 30 days
13
20% of all-time downloads
All-time downloads
65
Public
Parameters
85.8M
343 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors343 MB · 100%
From the Hugging Face model README
This is a fine-tuned version of google/vit-base-patch16-224, optimized for NSFW (Not Safe For Work) content detection. It leverages the high-resolution (224x224) Vision Transformer architecture to capture fine-grained visual details, making it highly effective for content moderation workflows.
google/vit-large-patch16-224NSFW vs Safe)This model is designed for developers and platforms needing automated content safety systems.
You can run inference using the Hugging Face transformers library.
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import torch
# Load model and processor
model_name = "theusamaaslam/vit-base-nsfw-detection-224"
processor = AutoImageProcessor.from_pretrained(model_name)
model = AutoModelForImageClassification.from_pretrained(model_name)
# Load your image
image = Image.open("path/to/your/image.jpg")
# Preprocess
inputs = processor(images=image, return_tensors="pt")
# Inference
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
# Get label
label = model.config.id2label[predicted_class_idx]
print(f"Prediction: {label}")
Usage for a distant image:
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import requests
import torch
# URL of the image to test
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
# Load image from URL
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
# Load Processor and Model from your Hub repo
repo_id = "theusamaaslam/vit-base-nsfw-detection-224"
processor = AutoImageProcessor.from_pretrained(repo_id)
model = AutoModelForImageClassification.from_pretrained(repo_id)
# Process image and inference
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
# Get probabilities and predicted label
logits = outputs.logits
probs = logits.softmax(dim=1)
predicted_class_idx = logits.argmax(-1).item()
predicted_label = model.config.id2label[predicted_class_idx]
print(f"Predicted class: {predicted_label}")
print(f"Probabilities: {probs}")
Author: @theusamaaslam
Email: [[email protected]]
Organization: Nayatel (Pvt Ltd) AI & DevOps Team