Add automatic NSFW image filtering to a user-generated content platform without sending images to a server.
Screen profile photo uploads client-side in the browser before they reach your backend.
Run server-side NSFW image moderation in a Node.js pipeline to process images at upload time.
Build a browser extension that flags explicit images on web pages using on-device machine learning.
Requires downloading a pre-trained model file of several MB on first use, caching in IndexedDB is recommended to avoid re-downloading on every page load.
NSFWJS is a TypeScript library that checks whether an image contains adult or explicit content, and it does this work entirely inside the user's web browser using TensorFlow.js. No image is sent to a server. The library runs a machine-learning model locally, so user photos stay private and the detection happens as fast as the device can run it. The library sorts any image into one of five categories: Drawing (safe artwork, including anime), Hentai (explicit drawings), Neutral (ordinary safe-for-work photos), Porn (explicit photographic content), and Sexy (suggestive but not explicitly pornographic). It returns a confidence percentage for each category, so the calling application can decide how to act on the result. Accuracy is around 90 percent with the smaller model and around 93 percent with the mid-sized one. Three pre-trained models ship with the package: MobileNetV2 (the default, small and fast), MobileNetV2Mid (a graph-based mid-sized model), and InceptionV3 (a larger model expecting 299 by 299 pixel input). You load one with a single function call, classify an image element, and get back an array of predictions. The library can also run in Node.js for server-side processing, and it supports optional WebAssembly and WebGPU backends for faster inference on hardware that can take advantage of them. To avoid downloading the model on every page load, the library supports caching it in the browser's IndexedDB storage. Developers who want a smaller app bundle can host the model files themselves instead of relying on the bundled base64 copies, which reduces the download by roughly a third. For teams who need tree-shaking, a separate core entry point lets you import only the model definitions you actually use. The project is open source and maintained by Infinite Red. It works in standard browsers, in React Native via a community package, and in Node.js applications. The README includes working code examples for each environment.
← infinitered on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.