Fix numpy 2.x compatibility in face3d utilities#1040
Open
AbdullahKhan123-tis wants to merge 1 commit into
Open
Fix numpy 2.x compatibility in face3d utilities#1040AbdullahKhan123-tis wants to merge 1 commit into
AbdullahKhan123-tis wants to merge 1 commit into
Conversation
- preprocess.py: wrap VisibleDeprecationWarning filter in try/except (np.VisibleDeprecationWarning was removed in numpy 2.0); use .item() instead of float() on multi-element arrays; explicitly cast t[0]/t[1] to scalar floats to avoid inhomogeneous array shape error in np.array([w0, h0, s, t[0], t[1]]) - my_awing_arch.py: replace removed np.float alias with built-in float - extract_kp_videos_safe.py: add fallback confidence thresholds (0.5, 0.2) when RetinaFace finds no faces at the default 0.97 threshold, preventing IndexError on portraits with less-than-ideal framing Tested with numpy 1.26.4 and numpy 2.x on PyTorch 2.5.1+cu121. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three files in src/face3d/ crash or raise warnings when running with numpy 2.x. This PR fixes all of them.
src/face3d/util/preprocess.py
p.VisibleDeprecationWarning in ry/except AttributeError - this warning class was removed in numpy 2.0 and raises AttributeError on import
p.array(...).item() to avoid the numpy 2.0 error "only size-1 arrays can be converted to Python scalars" when [0] is a 1-element array
p.array([w0, h0, s, t[0], t[1]]), fixing the "setting an array element with a sequence" inhomogeneous shape error
src/face3d/util/my_awing_arch.py
p.float was deprecated in numpy 1.20 and removed in numpy 2.0
src/face3d/extract_kp_videos_safe.py
Test plan