fix: handle dynamic dimensions in Math output shape
Build and Deploy / build (push) Successful in 2m42s
Build and Deploy / deploy (push) Successful in 9s

This commit is contained in:
2026-07-17 10:24:41 +00:00
parent 61f3223885
commit 0c2225bdbb
+21
View File
@@ -343,10 +343,31 @@ func preprocessMath(img image.Image) ([]float32, error) {
func decodeMath(output []float32, outputShape []int64) string {
// 输出格式: [num_chars, batch, timesteps] = [51, 1, 19]
// 需要转置为 [batch, timesteps, num_chars] = [1, 19, 51]
if len(outputShape) < 3 || len(output) == 0 {
return ""
}
numChars := int(outputShape[0]) // 51
batch := int(outputShape[1]) // 1
timesteps := int(outputShape[2]) // 19
// 处理动态维度(可能返回 -1
if numChars <= 0 {
numChars = 51 // 默认字符数
}
if batch <= 0 {
batch = 1
}
if timesteps <= 0 {
// 从输出大小推断
timesteps = len(output) / (numChars * batch)
}
// 边界检查
if numChars <= 0 || batch <= 0 || timesteps <= 0 {
return ""
}
// 转置: output[c*batch*t + b*t + t] -> transposed[b*timesteps*numChars + t*numChars + c]
transposed := make([]float32, batch*timesteps*numChars)
for b := 0; b < batch; b++ {