Fix numpy 2.x compatibility: remove deprecated type aliases and fix scalar conversion#1045
Open
trungkienkts-creator wants to merge 1 commit into
Open
Fix numpy 2.x compatibility: remove deprecated type aliases and fix scalar conversion#1045trungkienkts-creator wants to merge 1 commit into
trungkienkts-creator wants to merge 1 commit into
Conversation
…float() casts numpy 2.0 removed the deprecated scalar aliases (np.float, np.int, np.bool, etc.) and tightened float()/int() conversion to reject non-0-dimensional arrays. - np.float -> np.float64 (my_awing_arch.py, torch2onnx.py) - np.int -> np.int_ (eval_ijbc.py, onnx_ijbc.py, plot.py) - np.VisibleDeprecationWarning -> DeprecationWarning (preprocess.py) - resize_n_crop_img: extract scalar s/t0/t1 via np.squeeze() before int() arithmetic so PIL.Image.resize() receives plain Python ints - align_img: wrap t[0]/t[1]/s in float(np.squeeze()) before np.array() to avoid inhomogeneous-shape error - CropAndExtract: use .item() instead of float() on np.hsplit() sub-arrays 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
numpy 2.0 made two breaking changes that crash SadTalker on import and during inference:
np.float,np.int,np.bool,np.complex,np.object,np.strare gone.float()/int()conversion - these now only accept 0-dimensional arrays; passing a 1-element 1-D array raisesTypeError: only 0-dimensional arrays can be converted to Python scalars.Files changed
src/face3d/util/my_awing_arch.pynp.float?np.float64src/face3d/models/arcface_torch/torch2onnx.pynp.float?np.float64src/face3d/models/arcface_torch/eval_ijbc.pynp.int?np.int_(x4)src/face3d/models/arcface_torch/onnx_ijbc.pynp.int?np.int_(x4)src/face3d/models/arcface_torch/utils/plot.pynp.int?np.int_(x3)src/face3d/util/preprocess.pynp.VisibleDeprecationWarning; extract scalar s/t vianp.squeeze()beforeint()inresize_n_crop_img; wrap t/s infloat(np.squeeze(...))inalign_imgsrc/utils/preprocess.pyfloat(item)withitem.item()fornp.hsplitresults inCropAndExtractTesting
Verified end-to-end with:
Environment: Python 3.14, numpy 2.4.6, torch 2.12.0+cpu, Windows 11.