MCPcopy
hub / github.com/1adrianb/face-alignment / get_landmarks_from_batch

Method get_landmarks_from_batch

face_alignment/api.py:294–358  ·  view source on GitHub ↗

Predict the landmarks for each face present in the image. This function predicts a set of 68 2D or 3D images, one for each image in a batch in parallel. If detect_faces is None the method will also run a face detector. Arguments: image_batch {torch.tensor

(self, image_batch, detected_faces=None, return_bboxes=False,
                                 return_landmark_score=False)

Source from the content-addressed store, hash-verified

292
293 @torch.no_grad()
294 def get_landmarks_from_batch(self, image_batch, detected_faces=None, return_bboxes=False,
295 return_landmark_score=False):
296 """Predict the landmarks for each face present in the image.
297
298 This function predicts a set of 68 2D or 3D images, one for each image in a batch in parallel.
299 If detect_faces is None the method will also run a face detector.
300
301 Arguments:
302 image_batch {torch.tensor} -- The input images batch
303
304 Keyword Arguments:
305 detected_faces {list of numpy.array} -- list of bounding boxes, one for each face found
306 in the image (default: {None})
307 return_bboxes {boolean} -- If True, return the face bounding boxes in addition to the keypoints.
308 return_landmark_score {boolean} -- If True, return the keypoint scores along with the keypoints.
309
310 Return:
311 result:
312 1. if both return_bboxes and return_landmark_score are False, result will be:
313 landmarks
314 2. Otherwise, result will be one of the following, depending on the actual value of return_* arguments.
315 (landmark, landmark_score, detected_face)
316 (landmark, None, detected_face)
317 (landmark, landmark_score, None )
318 """
319
320 if detected_faces is None:
321 detected_faces = self.face_detector.detect_from_batch(image_batch)
322
323 if len(detected_faces) == 0:
324 warnings.warn("No faces were detected.")
325 if return_bboxes or return_landmark_score:
326 return None, None, None
327 else:
328 return None
329
330 landmarks = []
331 landmarks_scores_list = []
332 # A batch for each frame
333 for i, faces in enumerate(detected_faces):
334 res = self.get_landmarks_from_image(
335 image_batch[i].cpu().numpy().transpose(1, 2, 0),
336 detected_faces=faces,
337 return_landmark_score=return_landmark_score,
338 )
339 if return_landmark_score:
340 landmark_set, landmarks_scores, _ = res
341 landmarks_scores_list.append(landmarks_scores)
342 else:
343 landmark_set = res
344 # Bacward compatibility
345 if landmark_set is not None:
346 landmark_set = np.concatenate(landmark_set, axis=0)
347 else:
348 landmark_set = []
349 landmarks.append(landmark_set)
350
351 if not return_bboxes:

Callers 1

Calls 2

detect_from_batchMethod · 0.45

Tested by 1