From 61e7ffc03bd0eb5e31a9e0e3914e29270806770b Mon Sep 17 00:00:00 2001 From: Odboy Date: Tue, 26 Aug 2025 21:07:42 +0800 Subject: [PATCH] upd --- README.md | 6 +++--- application.properties | 2 +- internal/nsfw/detector.go | 10 +++++----- internal/nsfw/server.py | 6 +++--- lib/{nwfs => human_nwfs}/320n.onnx | Bin x20260829.md | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) rename lib/{nwfs => human_nwfs}/320n.onnx (100%) diff --git a/README.md b/README.md index a579ca0..bf66151 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ lightScore = 亮度 > 175 的像素占比 - **开启**:`application.properties` 设 `nsfw.enabled=true` - **依赖**:本机安装 Python 并 `pip install nudenet` -- **模型**:优先加载程序运行目录下 `lib/nwfs/320n.onnx`(本仓库已附带,约 11.6MB,离线可用);本地缺失时自动下载到该位置,下载失败再回退用 nudenet 包自带模型 +- **模型**:优先加载程序运行目录下 `lib/human_nwfs/320n.onnx`(本仓库已附带,约 11.6MB,离线可用);本地缺失时自动下载到该位置,下载失败再回退用 nudenet 包自带模型 - **可调**:`nsfw.python`(python 路径)、`nsfw.threshold`(判定阈值) - **敏感类**:`FEMALE_GENITALIA_EXPOSED` / `MALE_GENITALIA_EXPOSED` / `ANUS_EXPOSED` / `FEMALE_BREAST_EXPOSED`,任一分数达标即判定 - **降级**:未装 python / nudenet 时打印警告并跳过识别,图片按普通流程整理,不影响其它功能 @@ -186,7 +186,7 @@ Remove-Item Env:CGO_ENABLED,Env:GOOS,Env:GOARCH sudo yum install -y python3 pip3 install nudenet ``` - 模型文件 `lib/nwfs/320n.onnx` 需与二进制放在同一目录(没有会自动下载)。 + 模型文件 `lib/human_nwfs/320n.onnx` 需与二进制放在同一目录(没有会自动下载)。 3. **二次元识别(可选)**:Linux 上同样要装 Python 与依赖,并在 `application.properties` 里配 `hentai.python`(如 `/usr/bin/python3`): ```shell pip3 install onnxruntime Pillow numpy @@ -212,7 +212,7 @@ npm install && npm run dev ```text ├── main.go # 程序入口(Gin + 内嵌前端产物) ├── application.properties # 运行配置(端口 / 数据库 / 旋转开关 / 色情识别) -├── lib/nwfs/320n.onnx # 色情识别模型(随仓库分发,离线可用) +├── lib/human_nwfs/320n.onnx # 色情识别模型(随仓库分发,离线可用) ├── lib/wd-tagger/ # 二次元识别模型(首次启动自动下载,约 1.5GB) ├── build.sh # 编译脚本 ├── internal/ diff --git a/application.properties b/application.properties index 9a17a73..b1738b6 100644 --- a/application.properties +++ b/application.properties @@ -14,7 +14,7 @@ organize.rotateImages=false organize.workers=8 # 色情图片识别(需本机安装 python 与 nudenet:pip install nudenet) # true=开启,判为色情的图片移入「图片_敏感_*」目录(明暗子目录照常);false=关闭(默认) -# 模型:优先加载程序运行目录下 lib/nwfs/320n.onnx(推荐随程序分发,离线可用); +# 模型:优先加载程序运行目录下 lib/human_nwfs/320n.onnx(推荐随程序分发,离线可用); # 本地没有会自动下载到该位置,下载失败再回退用 nudenet 自带模型 # NSFW是用来识别真人图片的 nsfw.enabled=false diff --git a/internal/nsfw/detector.go b/internal/nsfw/detector.go index 037cc8b..e82a412 100644 --- a/internal/nsfw/detector.go +++ b/internal/nsfw/detector.go @@ -92,7 +92,7 @@ func Start(pythonPath string, threshold float64) (*Detector, error) { } // 模型目录:程序运行目录下的 lib(和 application.properties / media-info.db 同一根目录)。 - // 服务脚本优先加载 lib/nwfs/320n.onnx;本地没有会自己下载到那里,下载失败再回退用 pip 自带模型。 + // 服务脚本优先加载 lib/human_nwfs/320n.onnx;本地没有会自己下载到那里,下载失败再回退用 pip 自带模型。 modelDir := "" if wd, err := os.Getwd(); err == nil { modelDir = filepath.Join(wd, "lib") @@ -285,10 +285,10 @@ func (d *Detector) detectOnce(path string) (score float64, nsfw bool, err error) return 0, false, err } var out struct { - Ok bool `json:"ok"` - Error string `json:"error"` - Nsfw bool `json:"nsfw"` - Score float64 `json:"score"` + Ok bool `json:"ok"` + Error string `json:"error"` + Nsfw bool `json:"nsfw"` + Score float64 `json:"score"` Detections []map[string]interface{} `json:"detections"` } if err := json.Unmarshal(data, &out); err != nil { diff --git a/internal/nsfw/server.py b/internal/nsfw/server.py index e7428c6..67356e7 100644 --- a/internal/nsfw/server.py +++ b/internal/nsfw/server.py @@ -6,9 +6,9 @@ onnxruntime 的 InferenceSession 不是线程安全的,同一个实例并发 所以这里用一个固定大小的推理线程池:每个 worker 线程各持一份独立模型实例, N 个请求可以真·并行推理。收到 /detect 就把图片喂给 NudeDetector,返回结果 JSON。 -模型加载优先级(模型放在 <程序运行目录>/lib/nwfs/320n.onnx): +模型加载优先级(模型放在 <程序运行目录>/lib/human_nwfs/320n.onnx): 1. 本地已有该文件 → 直接加载(离线可用,适合随程序分发); - 2. 本地没有 → 自动下载到 lib/nwfs/320n.onnx 再加载(仅第一次需要网络); + 2. 本地没有 → 自动下载到 lib/human_nwfs/320n.onnx 再加载(仅第一次需要网络); 3. 下载失败 → 回退用 nudenet 包自带的模型。 下载地址是 NudeNet 官方 release 的 320n.onnx(约 11.6MB)。 @@ -49,7 +49,7 @@ SENSITIVE = { } # 模型文件与官方下载地址 -MODEL_FILENAME = "nwfs/320n.onnx" +MODEL_FILENAME = "human_nwfs/320n.onnx" MODEL_URL = "https://github.com/notAI-tech/NudeNet/releases/download/v3.4-weights/320n.onnx" # 模型目录由 Go 侧作为第二个参数传入(程序运行目录下的 lib);没传则回退用包自带模型 diff --git a/lib/nwfs/320n.onnx b/lib/human_nwfs/320n.onnx similarity index 100% rename from lib/nwfs/320n.onnx rename to lib/human_nwfs/320n.onnx diff --git a/x20260829.md b/x20260829.md index 0dfc256..474d116 100644 --- a/x20260829.md +++ b/x20260829.md @@ -19,7 +19,7 @@ |------|------|------| | 真人 vs 动漫 | `dghs-imgutils` `anime_real` | 二分类,输出 real/anime 概率 | | 真人 vs 风景 | 真人检测器 | 检测到人脸/人物 → 真人,否则风景 | -| 真人鉴黄 | NudeNet(已有 `lib/nwfs/320n.onnx`) | 保持现状 | +| 真人鉴黄 | NudeNet(已有 `lib/human_nwfs/320n.onnx`) | 保持现状 | | 动漫鉴黄 | `dghs-imgutils` `anime_rating` / `nsfw_pred` | danbooru 评级:safe/questionable/explicit 分数 | - `dghs-imgutils`(`pip install dghs-imgutils`)一个包覆盖「真人/动漫判定」+「动漫鉴黄」+「动漫分类」,