NsfwSpy is a nudity/pornography image and video classifier built for .NET Core 2.0 and later, with support for Windows, macOS and Linux, to aid in moderating user-generated content for various different application types, written in C#. The ML.NET model has been trained against the ResNet V250 neural net architecture with 646,000 images (109GB), from 4 different categories:
Label | Description | Files |
---|---|---|
Pornography | Images that depict sexual acts and nudity. | 106,000 |
Sexy | Images of people in their underwear and men who are topless. | 78,000 |
Hentai | Drawings or animations of sexual acts and nudity. | 83,000 |
Neutral | Images that are not sexual in nature. | 378,000 |
Looking for a JavaScript version of NsfwSpy? We have you covered - NsfwSpy.js 😎
NsfwSpy isn't perfect, but the accuracy should be good enough to detect approximately 96% of Nsfw images, those being images that are classed as pornography, sexy or hentai.
Pornography | Sexy | Hentai | Neutral | |
---|---|---|---|---|
Is Nsfw (pornography + sexy + hentai >= 0.5) | 95.8% | 97.0% | 95.2% | 3.7% |
Correctly Predicted Label | 85.7% | 84.4% | 91.9% | 96.54% |
Looking to quickly try out NsfwSpy? Check out our steps to use NsfwSpy.App.
This project is available as a NuGet package and can be installed with the following commands:
Package Manager
Install-Package NsfwSpy
.NET CLI
dotnet add package NsfwSpy
var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyImage(@"C:\Users\username\Documents\flower.jpg");
var uri = new Uri("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.jpg");
var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyImage(uri);
var fileBytes = File.ReadAllBytes(filePath);
var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyImage(fileBytes);
var files = Directory.GetFiles(@"C:\Users\username\Pictures");
var nsfwSpy = new NsfwSpy();
var results = nsfwSpy.ClassifyImages(files, (filePath, result) =>
{
Console.WriteLine($"{filePath} - {result.PredictedLabel}");
});
var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyGif(@"C:\Users\username\Documents\happy.gif");
var uri = new Uri("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/cool.gif");
var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyGif(uri);
var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyVideo(@"C:\Users\username\Documents\happy.mp4");
var uri = new Uri("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/bikini.mp4");
var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyVideo(uri);
services.AddScoped<INsfwSpy, NsfwSpy>();
To be able to make use of the ClassifyVideo methods, FFmpeg needs to be installed and available in the command line via the 'ffmpeg' command.
Follow this guide to download FFmpeg, extract it to your C:\ drive and add the required environment path variable.
Install FFmpeg on macOS using Homebrew via the following command:
brew install ffmpeg
Install FFmpeg on Ubuntu using the following command:
sudo apt install ffmpeg
To get GPU support working, please follow the prerequisite steps here to install CUDA v10.1 and CUDNN v7.6.4 for CUDA 10.1. Later versions do not work (as I tried with CUDA v11.4). The SciSharp.TensorFlow.Redist-Windows-GPU and SciSharp.TensorFlow.Redist-Linux-GPU packages are already included as part of the NsfwSpy package.
To get NsfwSpy working on macOS, the SciSharp.TensorFlow.Redist v2.3.1 NuGet package also needs to be installed. This not included by default as it interfers with supporting GPUs on Windows and Linux. You can do this with either of the following commands:
Package Manager
Install-Package SciSharp.TensorFlow.Redist -Version 2.3.1
.NET CLI
dotnet add package SciSharp.TensorFlow.Redist --version 2.3.1
Please note that Macs that use M1 chips currently do not support TensorFlow with ML.NET and cannot make use of NsfwSpy.
Interested to get involved in the project? Whether you fancy adding features, providing images to train NsfwSpy with or something else, feel free to contact us via email at [email protected] or find us on Twitter at @nsfw_spy.
Using NsfwSpy? Let us know! We're keen to hear how the technology is being used and improving the safety of applications.
Got a feature request or found something not quite right? Report it here on GitHub and we'll try to help as best as possible.