What is NSFWJS?
NSFWJS is a free, open-source (MIT) JavaScript library that flags NSFW, nude, and pornographic images. It runs a TensorFlow.js model right in the browser or in Node.js, so images never have to be uploaded to a server. The demo above runs NSFWJS on your device: your images stay private.
Install
npm install nsfwjs @tensorflow/tfjs
Quick start
import * as nsfwjs from "nsfwjs";
const img = document.getElementById("img");
const model = await nsfwjs.load();
const predictions = await model.classify(img);
// [{ className: "Neutral", probability: 0.93 }, ...]
Full API docs, caching, backend selection (WebGL, WebGPU, WASM, Node), and self-hosting the model are in the NSFWJS README on GitHub.
Image categories
- Drawing: safe-for-work drawings, including anime
- Hentai: hentai and pornographic drawings
- Neutral: safe-for-work neutral images
- Porn: pornographic images and sexual acts
- Sexy: sexually explicit images that are not pornography
Models
| Model | Accuracy | Size |
|---|---|---|
MobileNetV2 (default) |
~90% | 2.6 MB |
MobileNetV2Mid |
~93% | 4.2 MB |
InceptionV3 |
~93% | Large |
FAQ
Are my images uploaded anywhere?
No. Classification happens entirely on your device with TensorFlow.js. Nothing is sent to a server.
Does NSFWJS work in Node.js?
Yes. Pair it with @tensorflow/tfjs-node for fast server-side classification.
Can I use it in a mobile app?
Yes. See the NSFWJS mobile demo for React Native.
How accurate is it?
About 90% with the small model and about 93% with the mid-sized model. It isn't perfect, but it gets more accurate all the time.