infinitered /nsfwjs
NSFW detection on the client-side via TensorFlow.js
★ 9,030⑂ 598👁 87⑃ 697● 215▤ 15
machine-learningmachinelearningjavascripttensorflowjstensorflow-jsnode-modulecontent-managementnsfw-recognition
More from this author
+1
Daily
9,030
stars
598
forks
87
watchers
697
prs
215
issues
15
releases
README
Client-side indecent content checking
A simple JavaScript library to help you quickly identify unseemly images; all in the client's browser. NSFWJS isn't perfect, but it's pretty accurate (~90% with small and ~93% with midsized model)... and it's getting more accurate all the time.
Why would this be useful? Check out the announcement blog post.
NOTE
If you're trying to access the Cloudfront hosted model and are running into an error, it's likely due to the fact that the model has been moved to a new location. Please take a look at our Host your own model section. We will be returning the model after some hotlinkers have been dealt with.
Table of Contents
- QUICK: How to use the module
- Selective model bundles (tree-shaking)
- Library API
- load the model
- Caching
- classify an image
- dispose a loaded model
- Production
- Backend selection
- WASM backend (optional)
- WebGPU backend (optional)
- Node.js backend
- Install
- Host your own model
- Run the Examples
- Tensorflow.js in the browser
- Browserify
- React Native
- Node JS App
- NSFW Filter
- Learn TensorFlow.js
- More!
- Open Source
- Need the experts? Hire Infinite Red for your next project
- Contributors
The library categorizes image probabilities in the following 5 classes:
- Drawing - safe for work drawings (including anime)
- Hentai - hentai and pornographic drawings
- Neutral - safe for work neutral images
- Porn - pornographic images, sexual acts
- Sexy - sexually explicit images, not pornography
_The demo is a continuous deployment source - Give it a go: http://nsfwjs.com_
QUICK: How to use the module
js
import as nsfwjs from "nsfwjs";
const img = document.getElementById("img");
// If you want to host models on your own or use different model from the ones available, see the section "Host your own model".
const model = await nsfwjs.load();
// Classify the image
const predictions = await model.classify(img);
console.log("Predictions: ", predictions);
Selective model bundles (tree-shaking)
nsfwjs keeps the default behavior and includes built-in model definitions. For selective bundling, import from nsfwjs/core and pass only the models you want in modelDefinitions.
js
import { load } from "nsfwjs/core";
import { MobileNetV2Model } from "nsfwjs/models/mobilenet_v2";
import { MobileNetV2MidModel } from "nsfwjs/models/mobilenet_v2_mid";
const model = await load("MobileNetV2", {
modelDefinitions: [MobileNetV2Model, MobileNetV2MidModel],
});
If you pass an empty model registry, named bundled model loads will fail:
js
await load("MobileNetV2", { modelDefinitions: [] }); // throws
Library API
load the model
Before you can classify any image, you'll need to load the model.
js
const model = nsfwjs.load(); // Default: "MobileNetV2"
You can use the optional first parameter to specify which model you want to use from the three built-in bundled models. Defaults to: "MobileNetV2".
For tree-shaken selective modelTop issues
#945-6 seconds - or more, before model load and client (user) can use the page - how to improve?34 comments · 2019-04-23#39Run on every frame in Video18 comments · 2019-03-04#485[Question] Nodejs server side prediction12 comments · 2021-03-18#522Cannot load model from file11 comments · 2021-06-21#659Package vulnerabilities10 comments · 2022-09-01#741[Node.JS] Memory leak - Server reaches 100% memory after 5 or 6 days8 comments · 2023-04-28#689Failed to load model from local (nodejs)9 comments · 2022-11-15#512Cannot load latest (v1.1) nsfw_model from local file8 comments · 2021-05-07
Discussions
#938NSFW1 comments · 2026-09-02#928Converting mobilenet_v2_mid to tflite0 comments · 2025-12-24#919when i start up the suika/nsfwjs docker, i can't invoke the api.0 comments · 2025-01-30#917I want to know if the model has been updated?0 comments · 2025-01-10#892Is there a way to check multiple images inm a folder0 comments · 2024-09-28#856EICAR-like Images?0 comments · 2024-04-24#829Why doesn't it work with multiple images in one image?1 comments · 2024-02-26#738Local model import not implemented3 comments · 2023-04-25
Latest release
v4.4.0 v4.4.0 2026-08-04What's Changed fix: clamp topK to available classes in classify() by @GantMan with @Copilot in https://github.com/infinitered/nsfwjs/pull/933 fix: publish source maps and add package regression check by @luojiyin1987 in https://github.com/infinitered/nsfwjs/pull/935 fix source map error and added tool-versions by @jonmajorc in https://github.com/infinitered/nsfwjs/pull/936 exclude .tool-versions from published npm package by @jonmajorc in https://github.com/infinitered/nsfwjs/pull/937 New Contributors @GantMan with @Copilot made their first contribution in https://github.com/infinitered