diff --git a/Dockerfile b/Dockerfile index 2418323..69ba396 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ wget \ && rm -rf /var/lib/apt/lists/* -# 安装 ONNX Runtime -RUN wget -q https://github.com/microsoft/onnxruntime/releases/download/v1.16.3/onnxruntime-linux-x64-1.16.3.tgz \ - && tar -xzf onnxruntime-linux-x64-1.16.3.tgz \ - && mv onnxruntime-linux-x64-1.16.3 /usr/local/onnxruntime \ - && rm onnxruntime-linux-x64-1.16.3.tgz +# 安装 ONNX Runtime 1.18.0 (支持 IR version 10) +RUN wget -q https://github.com/microsoft/onnxruntime/releases/download/v1.18.0/onnxruntime-linux-x64-1.18.0.tgz \ + && tar -xzf onnxruntime-linux-x64-1.18.0.tgz \ + && mv onnxruntime-linux-x64-1.18.0 /usr/local/onnxruntime \ + && rm onnxruntime-linux-x64-1.18.0.tgz ENV ONNXRUNTIME_DIR=/usr/local/onnxruntime ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig diff --git a/internal/captcha/handler.go b/internal/captcha/handler.go index b829172..fe08b05 100644 --- a/internal/captcha/handler.go +++ b/internal/captcha/handler.go @@ -25,15 +25,18 @@ type Handler struct { mu sync.RWMutex } -// 模型配置:本地文件名 -> 远程文件名 -var modelConfigs = map[string]string{ - "CRNN_Math.onnx": "[AntiCAP]-CRNN_Math.onnx", - "OCR.onnx": "[Dddd]-OCR.onnx", - "Rotation-RotNetR.onnx": "[AntiCAP]-Rotation-RotNetR.onnx", - "Siamese-ResNet18.onnx": "[AntiCAP]-Siamese-ResNet18.onnx", - "CharSets.txt": "[Dddd]-CharSets.txt", - "Detection_Icon.onnx": "Detection_Icon.onnx", - "Detection_Text.onnx": "Detection_Text.onnx", +// 模型配置:本地文件名 -> 远程文件名(可选模型用 optional 标记) +var modelConfigs = map[string]struct { + remote string + optional bool +}{ + "CRNN_Math.onnx": {remote: "[AntiCAP]-CRNN_Math.onnx", optional: false}, + "OCR.onnx": {remote: "[Dddd]-OCR.onnx", optional: false}, + "Rotation-RotNetR.onnx": {remote: "[AntiCAP]-Rotation-RotNetR.onnx", optional: false}, + "Siamese-ResNet18.onnx": {remote: "[AntiCAP]-Siamese-ResNet18.onnx", optional: false}, + "CharSets.txt": {remote: "[Dddd]-CharSets.txt", optional: false}, + "Detection_Icon.onnx": {remote: "Detection_Icon.onnx", optional: true}, + "Detection_Text.onnx": {remote: "Detection_Text.onnx", optional: true}, } // 从 Gitea 仓库下载(公开仓库,无需认证) @@ -119,12 +122,16 @@ func (h *Handler) ensureModels() { return } - for localName, remoteName := range modelConfigs { + for localName, cfg := range modelConfigs { localPath := filepath.Join(h.modelPath, localName) if _, err := os.Stat(localPath); os.IsNotExist(err) { - fmt.Printf("下载模型: %s -> %s\n", remoteName, localName) - if err := h.downloadModel(remoteName, localPath); err != nil { - fmt.Printf("警告: 下载模型 %s 失败: %v\n", remoteName, err) + fmt.Printf("下载模型: %s -> %s\n", cfg.remote, localName) + if err := h.downloadModel(cfg.remote, localPath); err != nil { + if cfg.optional { + fmt.Printf("提示: 可选模型 %s 下载失败,相关功能不可用: %v\n", localName, err) + } else { + fmt.Printf("警告: 下载模型 %s 失败: %v\n", cfg.remote, err) + } } else { fmt.Printf("模型下载完成: %s\n", localName) }