From 76ae2ac70128e2d3f18900d747b4770682406610 Mon Sep 17 00:00:00 2001 From: Adrian Bulat Date: Wed, 16 Dec 2020 13:17:44 +0000 Subject: [PATCH 1/2] Fix #226 #210 --- face_alignment/detection/blazeface/detect.py | 5 +---- face_alignment/detection/sfd/detect.py | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/face_alignment/detection/blazeface/detect.py b/face_alignment/detection/blazeface/detect.py index 6258a92c..b1b2dfe1 100644 --- a/face_alignment/detection/blazeface/detect.py +++ b/face_alignment/detection/blazeface/detect.py @@ -14,7 +14,7 @@ def detect(net, img, device): preds = net.predict_on_image(img) if 0 == len(preds): - return np.zeros((1, 1, 5)) + return [[]] shift = np.array([xshift, yshift] * 2) scores = preds[:, -1:] @@ -48,9 +48,6 @@ def batch_detect(net, img_batch, device): locs = np.concatenate((pred[:, 1:2], pred[:, 0:1], pred[:, 3:4], pred[:, 2:3]), axis=1) bboxlists.append(np.concatenate((locs * orig_size + shift, scores), axis=1)) - if 0 == len(bboxlists): - bboxlists = np.zeros((1, 1, 5)) - return bboxlists diff --git a/face_alignment/detection/sfd/detect.py b/face_alignment/detection/sfd/detect.py index 35263e4d..162d2311 100644 --- a/face_alignment/detection/sfd/detect.py +++ b/face_alignment/detection/sfd/detect.py @@ -72,10 +72,6 @@ def batch_detect(net, img_batch, device): bboxlists.append(bboxlist) bboxlists = np.array(bboxlists) - - if 0 == len(bboxlists): - bboxlists = np.zeros((1, 1, 5)) - return bboxlists From 0bcf64874ff6cbcd4c46b1ddd4995e1fcf8de08a Mon Sep 17 00:00:00 2001 From: Adrian Bulat Date: Wed, 16 Dec 2020 13:34:09 +0000 Subject: [PATCH 2/2] Fix no detection case --- face_alignment/api.py | 4 ++-- face_alignment/detection/sfd/detect.py | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/face_alignment/api.py b/face_alignment/api.py index 2cadf683..2e138c93 100644 --- a/face_alignment/api.py +++ b/face_alignment/api.py @@ -247,8 +247,8 @@ def get_landmarks_from_batch(self, image_batch, detected_faces=None): else: pts, pts_img = pts.view(-1, 68, 2) * 4, pts_img.view(-1, 68, 2) landmark_set.append(pts_img.numpy()) - - landmark_set = np.concatenate(landmark_set, axis=0) + if 0 != len(landmark_set): + landmark_set = np.concatenate(landmark_set, axis=0) landmarks.append(landmark_set) return landmarks diff --git a/face_alignment/detection/sfd/detect.py b/face_alignment/detection/sfd/detect.py index 162d2311..1b75e8f1 100644 --- a/face_alignment/detection/sfd/detect.py +++ b/face_alignment/detection/sfd/detect.py @@ -22,9 +22,6 @@ def detect(net, img, device): # Creates a batch of 1 img = img.reshape((1,) + img.shape) - if 'cuda' in device: - torch.backends.cudnn.benchmark = True - img = torch.from_numpy(img).float().to(device) return batch_detect(net, img, device)