Compare commits

...

5 Commits

Author SHA1 Message Date
sugarBecomer e38a1a4480 🐛 取消临时err 2025-11-07 00:14:41 +08:00
sugarBecomer b112f45264 🐛 onnx运行路径问题 2025-11-06 23:50:10 +08:00
sugarBecomer 6fad80b5cd 🐛 onnx运行路径问题 2025-11-06 22:39:02 +08:00
sugarBecomer 1d0e1812c8 🐛 onnx运行路径问题 2025-11-06 22:25:58 +08:00
RecordingTheSmile 40490ffe43 fix: update Dockerfile to install packages non-interactively 2025-11-06 21:31:02 +08:00
4 changed files with 28 additions and 6 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
FROM golang:latest AS backend-builder
RUN apt update
RUN apt install build-essential
RUN apt install -y build-essential
WORKDIR /build
COPY . .
ENV CGO_ENABLED=1
RUN go build -ldflags="-s -w" -o bin/server
RUN apt install upx-ucl
RUN apt install -y upx-ucl
RUN upx --best --lzma bin/server
+24 -1
View File
@@ -5,9 +5,14 @@ import (
"fmt"
_ "image/jpeg"
_ "image/png"
"likedream-goframe/internal/framework/logger"
"os"
"path/filepath"
"runtime"
"strings"
ort "github.com/yalue/onnxruntime_go"
"go.uber.org/zap"
)
type ImageClassifier struct {
@@ -21,7 +26,25 @@ type ImageClassifier struct {
// NewImageClassifier 创建新的图片分类器
func NewImageClassifier(modelPath, classesPath string) (*ImageClassifier, error) {
// 初始化ONNX Runtime
err := ort.InitializeEnvironment()
exePath := strings.ToLower(os.Args[0])
// 获取绝对路径
absPath, err := filepath.Abs(exePath)
dir := filepath.Dir(absPath)
systemOS := runtime.GOOS
switch systemOS {
case "windows":
dir = filepath.Join(dir, "onnxruntime.dll")
break
case "darwin":
dir = filepath.Join(dir, "onnxruntime.dylib")
break
case "linux":
dir = filepath.Join(dir, "onnxruntime.so")
break
}
logger.Logger.Info("初始化onnx:", zap.String("绝对路径", absPath), zap.String("父文件夹", dir))
ort.SetSharedLibraryPath(dir)
err = ort.InitializeEnvironment()
if err != nil {
return nil, fmt.Errorf("初始化ONNX Runtime失败: %v", err)
}
@@ -64,7 +64,7 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
e = db.Global.CpTaskLog.Create().
SetCpTaskID(taskPayload.CpTaskID).
SetCpUserID(targetTask.Edges.CpUser.ID).
SetSystemUserID(targetTask.Edges.CpUser.Edges.Sysuser.ID).
SetSystemUserID(targetTask.Edges.SysUser.ID).
SetIsSuccess(false).
SetRealName("").
SetErrorMessage(errorMessage).
@@ -127,7 +127,6 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
}
submitForm := taskExecutor.FillCustomForm(ctx, cpdailyRealTask, customFormItems, deviceID, targetTask.Edges.CpUser.Username)
utils.OkOrPanic(errors.NewBusinessError(400, "临时错误"))
taskExecutor.Submit(ctx, submitForm, targetTask.Edges.CpUser.Username, deviceID)
db.Global.CpTask.UpdateOneID(taskPayload.CpTaskID).SetTaskStatus(cptask.TaskStatusDone).AddSuccessCount(1).ExecX(ctx)
+1 -1
View File
@@ -118,7 +118,7 @@ func (ts *TaskScanner) scanCpdailyTask() {
queue.AddTask(ts.ctx, asynq.NewTask(cst.TaskCpdaily, payloadWriter.Bytes()),
asynq.TaskID(fmt.Sprintf("cpdaily:task:%d", task.ID)),
asynq.MaxRetry(3),
asynq.Unique(10*time.Minute),
asynq.Unique(1*time.Minute),
asynq.ProcessAt(execTime),
asynq.Deadline(execTime.Add(12*time.Minute)),
asynq.Queue(cst.TaskQueueCpdaily),