Skip to content

fix: Correct detector preprocessing, postprocessing, and resize edge cases - #168

Merged
yakhyo merged 3 commits into
yakhyo:mainfrom
M-Colley:fix/detector-bugs
Nov 28, 2026
Merged

yakhyo merged 3 commits into
yakhyo:mainfrom
M-Colley:fix/detector-bugs

Conversation

@M-Colley

Copy link
Copy Markdown
Contributor

Summary

Fixes preprocessing, postprocessing, and aspect-ratio resize bugs across SCRFD, CenterFace, YOLOv5Face, YOLOv8Face, and shared resize helpers:

  • SCRFD:
    • Convert BGR input to RGB (swapRB=True) and scale by 1 / 128.0 in preprocess to match InsightFace's SCRFD training pipeline.
    • Compute FPN feature-map sizes with math.ceil(dim / stride) instead of floor division (// stride), fixing ValueError shape mismatches on non-multiple-of-32 resolutions such as 720p (1280, 720) and (640, 360).
    • Validate input_size dimensions are positive multiples of 8, slice pos_indices before anchor decoding, and validate input images before unpacking image.shape[:2].
  • CenterFace:
    • Compute x2, y2 and 5-point landmarks from unclipped raw_x1, raw_y1 before clamping box edges to [0, width] / [0, height], preventing rightward/downward shifts on border faces.
  • YOLOv8Face & YOLOv5Face:
    • Return float32 detections and landmarks consistently (and (0, 5) / (0, 5, 2) float32 on empty frames), clip cls_conf before exp in YOLOv8Face, filter by confidence before DFL softmax (6.4x faster YOLOv8Face.postprocess), and run validate_image before unpacking image.shape[:2].
  • resize_image & letterbox_resize:
    • Clamp resized dimensions to >= 1 pixel on extreme aspect ratios / thin crops and derive resize_factor from the active constrained axis.

Testing

  • Added regression tests in tests/test_scrfd.py, tests/test_centerface.py, and tests/test_yolo.py.
  • Full test suite and ruff pass.

@yakhyo

yakhyo commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Thanks for the fixes! I kept the SCRFD colour and 16:9 fixes, the YOLOv8 float32 and warning fixes, and the thin-image guard, and dropped the other changes to stay close to the original code.

@yakhyo
yakhyo merged commit 2d7ceb9 into yakhyo:main Nov 28, 2026
8 checks passed
@yakhyo

yakhyo commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants