Skip to content

NSFW 图片审核 API

Tensorflow 模型来自 NSFWJS,可以在 Demo 网页在线测试效果。由 NSFWAPI 提供 API 供 HTTP 调用。

可以对接兰空图床作为低成本审核 API 使用,目前清北图床已接入。

1/ 请求接口

目前有两种模型:

html
https://api.tsinbei.com/v2/image/nsfwapi/ # Default 模型
https://api.tsinbei.com/v2/image/nsfwapi/lite/ # Min 模型
https://api.tsinbei.com/v2/image/nsfwapi/ # Default 模型
https://api.tsinbei.com/v2/image/nsfwapi/lite/ # Min 模型

在内存占用上,defaultmin模型少 10%(参考相关 Issue),然而在识别精确度上二者并无显著区别。由于后者模型更小,理论上识别速度更快。

2/ 请求方法

单次请求支持单张识别多张识别

单张识别:

html
POST /classify HTTP/1.1
Content-Type: multipart/form-data
POST /classify HTTP/1.1
Content-Type: multipart/form-data

image字段中提供需审核的图片。

示例返回:

json
HTTP/1.1 200 OK
Content-Type: application/json
{
    "porn": 0.59248286485672,
    "sexy": 0.39802199602127075,
    "hentai": 0.006243097595870495,
    "neutral": 0.0031403270550072193,
    "drawing": 0.00011181648733327165
}
HTTP/1.1 200 OK
Content-Type: application/json
{
    "porn": 0.59248286485672,
    "sexy": 0.39802199602127075,
    "hentai": 0.006243097595870495,
    "neutral": 0.0031403270550072193,
    "drawing": 0.00011181648733327165
}

多张识别:

html
POST /classify-many HTTP/1.1
Content-Type: multipart/form-data
POST /classify-many HTTP/1.1
Content-Type: multipart/form-data

images字段中提供需审核的图片。

WARNING

此处字段名(images)与单张识别接口(image)不同,是复数形式,请注意辨别。

示例返回(以三张为例,结果顺序与上传顺序相同):

json
HTTP/1.1 200 OK
Content-Type: application/json
[
    {
        "porn": 0.3996206820011139,
        "neutral": 0.388679563999176,
        "sexy": 0.19470958411693573,
        "hentai": 0.015063910745084286,
        "drawing": 0.001926235854625702
    },
    {
        "sexy": 0.8366416692733765,
        "porn": 0.13645528256893158,
        "neutral": 0.0222245492041111,
        "hentai": 0.004213324282318354,
        "drawing": 0.0004651622730307281
    },
    {
        "sexy": 0.8017168045043945,
        "porn": 0.1770564466714859,
        "neutral": 0.015829339623451233,
        "hentai": 0.005097625777125359,
        "drawing": 0.00029983260901644826
    }
]
HTTP/1.1 200 OK
Content-Type: application/json
[
    {
        "porn": 0.3996206820011139,
        "neutral": 0.388679563999176,
        "sexy": 0.19470958411693573,
        "hentai": 0.015063910745084286,
        "drawing": 0.001926235854625702
    },
    {
        "sexy": 0.8366416692733765,
        "porn": 0.13645528256893158,
        "neutral": 0.0222245492041111,
        "hentai": 0.004213324282318354,
        "drawing": 0.0004651622730307281
    },
    {
        "sexy": 0.8017168045043945,
        "porn": 0.1770564466714859,
        "neutral": 0.015829339623451233,
        "hentai": 0.005097625777125359,
        "drawing": 0.00029983260901644826
    }
]

3/ 部署方法

目前本 API 使用的是HuggingFace的免费模型(2vCPU,12GB RAM),如果有更高要求可以尝试自部署。

Docker 部署

使用启动命令:

bash
docker run -p 3000:3000 ghcr.io/arnidan/nsfw-api:latest
docker run -p 3000:3000 ghcr.io/arnidan/nsfw-api:latest

或 Docker Compose 文件:

yml
version: "3.9"

services:
  nsfw-api:
    image: "ghcr.io/arnidan/nsfw-api:latest"
    ports:
      - "3000:3000"
    restart: always
version: "3.9"

services:
  nsfw-api:
    image: "ghcr.io/arnidan/nsfw-api:latest"
    ports:
      - "3000:3000"
    restart: always

手动部署

使用启动命令:

bash
git clone https://github.com/arnidan/nsfw-api
mv ./nsfw-api/* .
yarn
yarn build
yarn start
git clone https://github.com/arnidan/nsfw-api
mv ./nsfw-api/* .
yarn
yarn build
yarn start

如果模型有更新,可以到模型仓库下载并替换models文件夹中的模型文件。

一键部署

推荐订阅清北科技 SaaS 服务,付费计划参考计划比较 - Tsinbei Tech Team