feat: 二次元识别功能 + 模型目录整理(nwfs/wd-tagger 子目录),修复 wd-tagger 输入维度(NHWC)

This commit is contained in:
2025-06-25 21:10:21 +08:00
parent 4efa48f550
commit 3af2bf70b4
18 changed files with 1386 additions and 21 deletions
+17 -1
View File
@@ -22,6 +22,9 @@ import (
// - NSFWEnabled:是否开启色情图片识别(本地 python + NudeNet,默认 false)
// - NSFWPython:python 可执行文件路径;留空自动在 PATH 里找
// - NSFWThreshold:判定阈值 0~1(默认 0.5)
// - HentaiEnabled:是否开启二次元图片识别(本地 python + wd-tagger,默认 false)
// - HentaiPython:python 可执行文件路径;留空自动在 PATH 里找
// - HentaiThreshold:判定阈值 0~1(默认 0.5)
type Config struct {
Port int
Dsn string
@@ -32,6 +35,9 @@ type Config struct {
NSFWEnabled bool
NSFWPython string
NSFWThreshold float64
HentaiEnabled bool
HentaiPython string
HentaiThreshold float64
}
// appConfig 当前生效的配置(程序运行期间一直不变)。
@@ -45,7 +51,7 @@ func GetAppConfig() Config {
// LoadAppConfig 从 application.properties 读配置;文件不存在就用默认值。
func LoadAppConfig() {
// 先给一套默认值
appConfig = Config{Port: 8080, Dsn: "media-info.db", AutoOpen: true, RotateImages: true, Workers: 4, NSFWThreshold: 0.5}
appConfig = Config{Port: 8080, Dsn: "media-info.db", AutoOpen: true, RotateImages: true, Workers: 4, NSFWThreshold: 0.5, HentaiThreshold: 0.5}
p, err := properties.LoadFile("application.properties", properties.UTF8)
if err != nil {
@@ -80,6 +86,16 @@ func LoadAppConfig() {
appConfig.NSFWThreshold = t
}
}
// 二次元识别:默认关;python 路径留空自动在 PATH 找;阈值只认 0~1 之间的小数
appConfig.HentaiEnabled = p.GetBool("hentai.enabled", false)
if v, ok := p.Get("hentai.python"); ok && v != "" {
appConfig.HentaiPython = v
}
if v, ok := p.Get("hentai.threshold"); ok && strings.TrimSpace(v) != "" {
if t, err := strconv.ParseFloat(strings.TrimSpace(v), 64); err == nil && t > 0 && t < 1 {
appConfig.HentaiThreshold = t
}
}
}
// WorkerCount 返回探测/MIME/移动阶段使用的并发 worker 数: