fix: remove ImageNet normalization for YOLO (match Ultralytics default)
Build and Deploy / build (push) Successful in 2m45s
Build and Deploy / deploy (push) Successful in 10s

- Ultralytics YOLO only does /255 normalization, no ImageNet mean/std
- This was causing detection box coordinate drift
This commit is contained in:
2026-07-18 05:37:54 +00:00
parent e423f2ddd3
commit 47970834ec
2 changed files with 124 additions and 8 deletions
+6 -8
View File
@@ -982,19 +982,17 @@ func preprocessYOLO(img image.Image) ([]float32, LetterboxInfo, error) {
}
}
// YOLO 标准化参数 (ImageNet)
mean := [3]float32{0.485, 0.456, 0.406}
std := [3]float32{0.229, 0.224, 0.225}
// YOLO 归一化:只需要 /255,不需要 ImageNet 标准化
// Ultralytics YOLO 默认预处理:letterbox + /255
pixels := make([]float32, 3*targetSize*targetSize)
for y := 0; y < targetSize; y++ {
for x := 0; x < targetSize; x++ {
c := canvas.At(x, y)
r, g, b, _ := c.RGBA()
// 归一化到 [0, 1],然后标准化
pixels[0*targetSize*targetSize+y*targetSize+x] = (float32(r)/65535.0 - mean[0]) / std[0]
pixels[1*targetSize*targetSize+y*targetSize+x] = (float32(g)/65535.0 - mean[1]) / std[1]
pixels[2*targetSize*targetSize+y*targetSize+x] = (float32(b)/65535.0 - mean[2]) / std[2]
// 归一化到 [0, 1]
pixels[0*targetSize*targetSize+y*targetSize+x] = float32(r) / 65535.0
pixels[1*targetSize*targetSize+y*targetSize+x] = float32(g) / 65535.0
pixels[2*targetSize*targetSize+y*targetSize+x] = float32(b) / 65535.0
}
}