debug: add logging for Math ONNX output
Build and Deploy / build (push) Successful in 2m41s
Build and Deploy / deploy (push) Successful in 9s

This commit is contained in:
2026-07-17 12:12:48 +00:00
parent a3665ed63a
commit 0145bf9e44
+20 -6
View File
@@ -311,16 +311,30 @@ func (h *Handler) Math(imageBase64 string) (result string, err error) {
return "", err
}
// 不调用 GetOutputShape,直接从 output 大小推断
// Math 模型输出固定为 [51, 1, 19] = 969 个元素 或 [19, 1, 51] = 969 个元素
outputLen := len(output)
if outputLen == 0 {
// DEBUG: 打印输出前10个值
debugStr := "ONNX output first 10: "
for i := 0; i < 10 && i < len(output); i++ {
debugStr += fmt.Sprintf("%.4f ", output[i])
}
fmt.Println(debugStr)
// DEBUG: 对第一个位置 argmax
maxIdx := 0
maxProb := float32(-math.MaxFloat32)
for c := 0; c < 19; c++ {
if output[c] > maxProb {
maxProb = output[c]
maxIdx = c
}
}
fmt.Printf("DEBUG: Position 0 argmax = %d (char: %s)\n", maxIdx, string("0123456789+-*/÷×=?."[maxIdx-1]))
if len(output) == 0 {
return "", fmt.Errorf("模型输出为空")
}
// 推断输出形状:已知 numChars=51, batch=1, timesteps=19, total=969
// 尝试两种格式
expr := decodeMathFromOutput(output)
fmt.Printf("DEBUG: Decoded expression = '%s'\n", expr)
if expr == "" {
return "", fmt.Errorf("无法识别表达式")
}