infinitered /nsfwjs

NSFW detection on the client-side via TensorFlow.js

★ 9,030⑂ 598👁 87⑃ 697● 215▤ 15
TypeScriptMITCreated 2019-02-13nsfwjs.com/
下载:v4.4.0v4.4.0 ↓4.4.02026-08-04
+1
日增长
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 model

Top issues

Discussions

Latest release

v4.4.0 v4.4.0 2026-08-04
What'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

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON