基于现有的轮子搭建一个自己的NSFW API来节省费用。
之前就遇到过雅虎的nsfw了,但是之前却搞不懂要如何使用,因为他是一个训练后的模型,这不在最近找图床的时候被我有幸遇见了现成的Docker镜像,这大大方便了我的搭建。。。。。。
这次发现了两个可以实现识别NSFW图片的Docker
一、eugencepoi/nsfw_api
用于检测包含成人内容的图像的 Python REST API。它依赖于 open_nsfw(就是之前找到但是我不知道怎么使用的雅虎open_nsfw),它为 Caffe 提供了一个预训练的开源神经网络模型。
启动
这次基于现有轮子,直接跑镜像就可以了:
docker run -it -p 127.0.0.1:5000:5000/tcp --env PORT=5000 eugencepoi/nsfw_api:latest
测试
容器启动后可以执行下面命令:
curl -X GET -H 'Content-Type: application/json' http://localhost:5000\?url\=https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png
返回值:
{
"score": 0.00016061133646871895,
"url": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
}
测试地址
本人搭建的,不知道能存活到什么时候。
地址:https://nsfw_api.147180.com/
单张图片
curl --location --request GET 'https://nsfw_api.147180.com/?url=https://i.886878.cn/images/2020/01/25/08828eb322b1775f2ff3cd2e4f9401c8.jpg'
{"score":0.021447615697979927,"url":"https://i.886878.cn/images/2020/01/25/08828eb322b1775f2ff3cd2e4f9401c8.jpg"}
多张图片
curl --location --request POST 'https://nsfw_api.147180.com/batch-classify' \
--header 'Content-Type: application/json' \
--data-raw '{
"images": [
{
"url": "https://i.886878.cn/images/2020/01/25/08828eb322b1775f2ff3cd2e4f9401c8.jpg",
"id": 1
},
{
"url": "https://i.886878.cn/images/2020/01/25/22c600f249131dae799dbd5f39109868.jpg",
"id": 2
}
]
}'
返回值:
{
"predictions": [
{
"url": "https://i.886878.cn/images/2020/01/25/08828eb322b1775f2ff3cd2e4f9401c8.jpg",
"score": 0.021447615697979927,
"id": 1
},
{
"url": "https://i.886878.cn/images/2020/01/25/22c600f249131dae799dbd5f39109868.jpg",
"score": 0.24648497998714447,
"id": 2
}
]
}
二、arnidan/nsfw-api
基于Keras model of NSFW detector模型的使用NSFWJS实现API
启动
docker run -p 3000:3000 ghcr.io/arnidan/nsfw-api:latest
请求示例
单张图片
POST /classify HTTP/1.1 Content-Type: multipart/form-data
在image字段添加文件
多张图片
POST /classify-many HTTP/1.1 Content-Type: multipart/form-data
在images字段添加文件
测试地址
本人搭建的,不知道能存活到什么时候。
地址:https://nsfw-api.147180.com/
单张图片:
curl --location --request POST 'https://nsfw-api.147180.com/classify' \ --form 'image=@"/C:/838ba61ea8d3fd1f437bafba71371d1694ca5f45.jpeg"'
返回值:
{
"drawing": 0.930454432964325,
"hentai": 0.036235544830560684,
"neutral": 0.01689150184392929,
"porn": 0.010260858573019505,
"sexy": 0.006157642230391502
}
多张图片
curl --location --request POST 'https://nsfw-api.147180.com/classify-many' \ --form 'images=@"/C:/1.jpeg"' \ --form 'images=@"/C:/2.jpeg"'
返回值:
[
{
"drawing": 0.930454432964325,
"hentai": 0.036235544830560684,
"neutral": 0.01689150184392929,
"porn": 0.010260858573019505,
"sexy": 0.006157642230391502
},
{
"drawing": 0.930454432964325,
"hentai": 0.036235544830560684,
"neutral": 0.01689150184392929,
"porn": 0.010260858573019505,
"sexy": 0.006157642230391502
}
]
参考
eugencepoi/nsfw_api
https://hub.docker.com/r/eugencepoi/nsfw_api
Wrapper around NSFWJS to provide API.
https://github.com/arnidan/nsfw-api
有机会有时间自己改一些加上个鉴权调用限制的功能(无限期挖坑。。。。。。)
ChiuYut
2022年09月18日