← All models

image-classification Β· vision Β· WASM Β· ~88 MB

NSFW detector β€” is this image safe to display?

A Vision Transformer fine-tuned to sort images into sfw (safe for work) and nsfw. Drop an image and it returns a probability for each and a plain verdict β€” safe to show, or hold for review. This is defensive content-safety tooling: an upload gate you can run before an image is ever displayed or stored. Everything happens on your device; the image is never uploaded.

At a glance

ModelAdamCodd/vit-base-nsfw-detector
Task / pipelineimage-classification Β· single-label (softmax over 2 classes)
Labelssfw / nsfw
ArchitectureViT-B/16 (86M params) fine-tuned for NSFW detection
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~88 MB, cached after first load
LicenseApache-2.0
Web APIsWebAssembly, Web Workers, FileReader β€” all Baseline widely available

The bundled samples are ordinary, tasteful photos (pets, a room, a riverside). The interesting number is the classifier's confidence that they're safe β€” you can also drop your own image, and it stays entirely in the tab.

Run it

Pick or drop an image, set how much NSFW probability you're willing to tolerate, and hit Screen. The verdict is a policy decision on top of the model's score: display the image only when its NSFW probability is below your threshold.

Drop an image here, or click to choose
Two cats sleeping on a couch A cozy sunlit bedroom A riverside at golden hour
Selected image preview

See inside β€” score vs. policy

The model outputs two raw logits; a softmax turns them into two probabilities that sum to 100%. The model gives you the number; the threshold is your policy. A stricter threshold (e.g. 0.20) catches more borderline images but withholds more safe ones (false positives); a looser one (0.80) shows more but risks letting something through (false negatives). This is the moderation trade-off in one slider β€” there's no single right value, it depends on how costly each mistake is for your product.

Screen an image to see the raw numbers.

Why it matters

Any product that lets users upload images inherits a moderation problem. A fast, private, offline safe/NSFW score is a first filter that runs before an image is stored, displayed, or sent anywhere β€” no API bill, no third party seeing user content, and a latency low enough to gate an upload in real time.

Use cases

Basics

Screen a single image and read the safe/NSFW probabilities.

Practical

An upload-gate gallery: screen many images at a threshold, auto-blur what's withheld.

Wild

Ambiguous and artistic edge cases β€” watch confidence wobble and see calibration limits.

Multi-model

A safety gate in front of captioning: only safe images get described.

How the API works

The convenience path is two lines with Transformers.js:

import { pipeline } from "@huggingface/transformers";

const detect = await pipeline("image-classification", "AdamCodd/vit-base-nsfw-detector");
const out = await detect(imageURL, { top_k: 2 });
// β†’ [{ label: "sfw", score: 0.98 }, { label: "nsfw", score: 0.02 }]

This page goes one level deeper for "See inside": instead of the pipeline it runs the model's processor then model() in a single forward pass, so it can read the raw two-value logits tensor and compute the softmax itself β€” then apply your threshold. Same weights, same result. Inference runs in a Web Worker so the page never janks.

References