diff --git a/internal/captcha/handler.go b/internal/captcha/handler.go index 219ae2b..7add83e 100644 --- a/internal/captcha/handler.go +++ b/internal/captcha/handler.go @@ -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("无法识别表达式") }