Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/face3d/models/arcface_torch/torch2onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def convert_onnx(net, path_module, output, opset=11, simplify=False):
assert isinstance(net, torch.nn.Module)
img = np.random.randint(0, 255, size=(112, 112, 3), dtype=np.int32)
img = img.astype(np.float)
img = img.astype(np.float64) # Fixed for numpy 2.0+ compatibility
img = (img / 255. - 0.5) / 0.5 # torch style norm
img = img.transpose((2, 0, 1))
img = torch.from_numpy(img).unsqueeze(0).float()
Expand Down
2 changes: 1 addition & 1 deletion src/face3d/util/my_awing_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def calculate_points(heatmaps):
indexes = np.argmax(heatline, axis=2)

preds = np.stack((indexes % W, indexes // W), axis=2)
preds = preds.astype(np.float, copy=False)
preds = preds.astype(np.float64, copy=False) # Fixed for numpy 2.0+ compatibility

inr = indexes.ravel()

Expand Down
23 changes: 17 additions & 6 deletions src/face3d/util/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from skimage import transform as trans
import torch
import warnings
warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)
# 兼容新版本 numpy (2.0+),VisibleDeprecationWarning 已被移除
try:
warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)
except AttributeError:
# numpy 2.0+ 不再有 VisibleDeprecationWarning,忽略即可
pass
warnings.filterwarnings("ignore", category=FutureWarning)


Expand All @@ -27,14 +32,17 @@ def POS(xp, x):

b = np.reshape(xp.transpose(), [2*npts, 1])

k, _, _, _ = np.linalg.lstsq(A, b)
k, _, _, _ = np.linalg.lstsq(A, b, rcond=None)

R1 = k[0:3]
R2 = k[4:7]
sTx = k[3]
sTy = k[7]
# Fixed for numpy 2.0+ compatibility: ensure scalars
sTx = float(k[3]) if hasattr(k[3], '__len__') else k[3]
sTy = float(k[7]) if hasattr(k[7], '__len__') else k[7]
s = (np.linalg.norm(R1) + np.linalg.norm(R2))/2
t = np.stack([sTx, sTy], axis=0)
# Ensure s is a scalar
s = float(s) if hasattr(s, '__len__') else s
t = np.array([sTx, sTy], dtype=np.float64)

return t, s

Expand Down Expand Up @@ -95,9 +103,12 @@ def align_img(img, lm, lm3D, mask=None, target_size=224., rescale_factor=102.):
# calculate translation and scale factors using 5 facial landmarks and standard landmarks of a 3D face
t, s = POS(lm5p.transpose(), lm3D.transpose())
s = rescale_factor/s
# Ensure s is a scalar
s = float(s) if hasattr(s, '__len__') else s

# processing the image
img_new, lm_new, mask_new = resize_n_crop_img(img, lm, t, s, target_size=target_size, mask=mask)
trans_params = np.array([w0, h0, s, t[0], t[1]])
# Fixed for numpy 2.0+ compatibility: ensure all values are scalars
trans_params = np.array([float(w0), float(h0), float(s), float(t[0]), float(t[1])], dtype=np.float64)

return trans_params, img_new, lm_new, mask_new