diff --git a/src/face3d/extract_kp_videos_safe.py b/src/face3d/extract_kp_videos_safe.py index 5141ba3a..dafaedca 100644 --- a/src/face3d/extract_kp_videos_safe.py +++ b/src/face3d/extract_kp_videos_safe.py @@ -71,7 +71,10 @@ def extract_keypoint(self, images, name=None, info=True): # face detection -> face alignment. img = np.array(images) bboxes = self.det_net.detect_faces(images, 0.97) - + if len(bboxes) == 0: + bboxes = self.det_net.detect_faces(images, 0.5) + if len(bboxes) == 0: + bboxes = self.det_net.detect_faces(images, 0.2) bboxes = bboxes[0] img = img[int(bboxes[1]):int(bboxes[3]), int(bboxes[0]):int(bboxes[2]), :] diff --git a/src/face3d/util/my_awing_arch.py b/src/face3d/util/my_awing_arch.py index cd565617..308752f6 100644 --- a/src/face3d/util/my_awing_arch.py +++ b/src/face3d/util/my_awing_arch.py @@ -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(float, copy=False) inr = indexes.ravel() diff --git a/src/face3d/util/preprocess.py b/src/face3d/util/preprocess.py index b77a3a40..cf002ea8 100644 --- a/src/face3d/util/preprocess.py +++ b/src/face3d/util/preprocess.py @@ -9,7 +9,10 @@ from skimage import transform as trans import torch import warnings -warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) +try: + warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) +except AttributeError: + pass # numpy 2.x removed VisibleDeprecationWarning warnings.filterwarnings("ignore", category=FutureWarning) @@ -43,9 +46,9 @@ def resize_n_crop_img(img, lm, t, s, target_size=224., mask=None): w0, h0 = img.size w = (w0*s).astype(np.int32) h = (h0*s).astype(np.int32) - left = (w/2 - target_size/2 + float((t[0] - w0/2)*s)).astype(np.int32) + left = (w/2 - target_size/2 + np.array((t[0] - w0/2)*s).item()).astype(np.int32) right = left + target_size - up = (h/2 - target_size/2 + float((h0/2 - t[1])*s)).astype(np.int32) + up = (h/2 - target_size/2 + np.array((h0/2 - t[1])*s).item()).astype(np.int32) below = up + target_size img = img.resize((w, h), resample=Image.BICUBIC) @@ -98,6 +101,6 @@ def align_img(img, lm, lm3D, mask=None, target_size=224., rescale_factor=102.): # 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]]) + trans_params = np.array([w0, h0, float(s), float(np.array(t[0]).flat[0]), float(np.array(t[1]).flat[0])]) return trans_params, img_new, lm_new, mask_new