Skip to content

fix: Harden crop bounds and edge cases across landmark, attribute, matting, and store modules - #171

Merged
yakhyo merged 3 commits into
yakhyo:mainfrom
M-Colley:fix/edge-case-hardening
Nov 30, 2026
Merged

yakhyo merged 3 commits into
yakhyo:mainfrom
M-Colley:fix/edge-case-hardening

Conversation

@M-Colley

Copy link
Copy Markdown
Contributor

Summary

Hardens crop bounds, input validation, and edge cases across matting, landmark, attribute, spoofing, recognition, vector store, and CLI modules:

  • MODNet & PPMatting: Validate input_size >= 32 / max_short >= 32, validate input images via validate_image, and reject images with a side < 32 px in MODNet.preprocess instead of crashing cv2.resize with new_h == 0 when min(H, W) < 32 <= input_size <= max(H, W).
  • FaceMesh: Fall back to axis-aligned ROIs when Face.landmarks is empty (supports_landmarks = False), support single 1D (4,) bboxes arrays, reject zero/inverted boxes in roi_from_box, and clip logits before exp in postprocess.
  • PIPNet, FairFace & MiniFASNet: Validate box ordering and image overlap to prevent Python negative-slice background cropping and OpenCV !ssize.empty() crashes (including valid bottom-edge faces in PIPNet and sub-pixel boxes in MiniFASNet).
  • Landmark106: Avoid mutating caller predictions arrays in-place inside postprocess, and validate positive box dimensions and input images.
  • Emotion: Add optional device override, fix (H, W) vs (W, H) cv2.resize orientation on custom input_size, skip redundant resize at (112, 112), and call .detach() in postprocess.
  • BaseRecognizer & face_utils: Handle PreprocessConfig(input_mean=[...], input_std=float) without crashing blobFromImage, default landmarks=None on get_normalized_embedding and __call__, raise ValueError instead of internal skimage FailedEstimationAccessError in estimate_norm, and remove the unconditional + 1e-5 denominator bias in compute_similarity.
  • Model weight error handling, FAISS.load & CLI crops: Log model={model_name} instead of model_name.name before verify_model_weights so invalid string identifiers raise ValueError rather than AttributeError; verify dimension and metadata count in FAISS.load(); clamp negative detector box coordinates before slicing in tools/gaze.py and tools/headpose.py.

Testing

  • Added tests/test_edge_cases.py covering all 14 regression scenarios.

@yakhyo
yakhyo merged commit ce4e468 into yakhyo:main Nov 30, 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