This commit is contained in:
2025-08-26 21:07:42 +08:00
parent d6798ef1ee
commit 61e7ffc03b
6 changed files with 13 additions and 13 deletions
+5 -5
View File
@@ -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 {
+3 -3
View File
@@ -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);没传则回退用包自带模型