image-classification Β· vision Β· WASM Β· ~88 MB
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.
| Model | AdamCodd/vit-base-nsfw-detector |
|---|---|
| Task / pipeline | image-classification Β· single-label (softmax over 2 classes) |
| Labels | sfw / nsfw |
| Architecture | ViT-B/16 (86M params) fine-tuned for NSFW detection |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~88 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, 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.
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.

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.
| Class | logit | softmax |
|---|
NSFW probability along the safeβunsafe scale (needle):
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.
Screen a single image and read the safe/NSFW probabilities.
An upload-gate gallery: screen many images at a threshold, auto-blur what's withheld.
Ambiguous and artistic edge cases β watch confidence wobble and see calibration limits.
A safety gate in front of captioning: only safe images get described.
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.