MCPcopy
hub / github.com/Rudrabha/Wav2Lip / face_detect

Function face_detect

evaluation/real_videos_inference.py:73–106  ·  view source on GitHub ↗
(images)

Source from the content-addressed store, hash-verified

71
72
73def face_detect(images):
74 batch_size = args.face_det_batch_size
75 images = rescale_frames(images)
76
77 while 1:
78 predictions = []
79 try:
80 for i in range(0, len(images), batch_size):
81 predictions.extend(detector.get_detections_for_batch(np.array(images[i:i + batch_size])))
82 except RuntimeError:
83 if batch_size == 1:
84 raise RuntimeError('Image too big to run face detection on GPU')
85 batch_size //= 2
86 print('Recovering from OOM error; New batch size: {}'.format(batch_size))
87 continue
88 break
89
90 results = []
91 pady1, pady2, padx1, padx2 = args.pads
92 for rect, image in zip(predictions, images):
93 if rect is None:
94 raise ValueError('Face not detected!')
95
96 y1 = max(0, rect[1] - pady1)
97 y2 = min(image.shape[0], rect[3] + pady2)
98 x1 = max(0, rect[0] - padx1)
99 x2 = min(image.shape[1], rect[2] + padx2)
100
101 results.append([x1, y1, x2, y2])
102
103 boxes = get_smoothened_boxes(np.array(results), T=5)
104 results = [[image[y1: y2, x1:x2], (y1, y2, x1, x2), True] for image, (x1, y1, x2, y2) in zip(images, boxes)]
105
106 return results, images
107
108def datagen(frames, face_det_results, mels):
109 img_batch, mel_batch, frame_batch, coords_batch = [], [], [], []

Callers 1

mainFunction · 0.70

Calls 3

rescale_framesFunction · 0.85
get_smoothened_boxesFunction · 0.70

Tested by

no test coverage detected