Publish: 2022-04-18 | Modify: 2022-07-10
NSFW JS is a simple JavaScript library that has been open sourced on Github to help you quickly identify inappropriate images. NSFWJS is not perfect, but it is very accurate (about 90% for the small model and about 93% for the medium model) and it is constantly becoming more accurate.
Currently, some netizens have packaged NSFW JS into a Docker image and provided REST API support. After deployment, it can be called through the HTTP API. In addition, ImgURL Pro will also support NSFW JS image filtering, with Docker private deployment of NSFW JS as a prerequisite. Let's install it together.
# Copy the command below to deploy NSFW JS
docker run -d -p 127.0.0.1:5000:5000/tcp \
--env PORT=5000 \
--restart=always \
eugencepoi/nsfw_api:latest
Note: After the above deployment, only local 127.0.0.1
access is supported and cannot be accessed publicly. If you need public access, remove 127.0.0.1:
After deployment, you can test whether it is successful using the curl
command:
curl -X GET -H 'Content-Type: application/json' "http://127.0.0.1:5000?url=https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
If successful, it will return JSON content in the following format:
{
"score": 0.00016061133646871895,
"url": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
}
Note: According to Xiaoz's test, if the image URL contains a port number, it will not be recognized and an error will occur.
score
is the image score, ranging from 0
to 1
, where 1
means it is definitely adult content and 0
is not. According to Xiaoz's test, a score greater than 0.9
can be considered adult content.
For more usage instructions, you can check the introduction on Docker Hub: https://hub.docker.com/r/eugencepoi/nsfw_api
If you don't want to build your own image filtering API, you can also take a look at two other free image filtering APIs: "Sharing 2 free image recognition (image filtering) APIs from overseas". Unfortunately, the free ones have quota limitations.
By deploying NSFW JS with Docker, you can easily set up an image filtering server with HTTP API support, without any quota or quantity limitations. According to Xiaoz's test, the accuracy is average, but it is free and open source.
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.