Skip to content

Commit 2d990f5

Browse files
committed
Fix an issue where faces are not correctly detected in images with high resolution when using RetinaFace detector
1 parent 7f7a144 commit 2d990f5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

liveportrait/utils/cropper_face_alignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, **kwargs) -> None:
6868
if face_detector == 'blazeface':
6969
face_detector_kwargs = {'back_model': face_detector_dtype == 'blazeface_back_camera'}
7070
elif face_detector == 'retinaface':
71-
face_detector_kwargs = {'fp16': face_detector == torch.float16}
71+
face_detector_kwargs = {'fp16': face_detector == torch.float16, 'max_size': 1280}
7272
else:
7373
face_detector_kwargs = {}
7474

liveportrait/utils/dependencies/face_alignment/detection/retinaface/retinaface_detector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ class RetinaFaceDetector(FaceDetector):
2626
'''RetinaFace Detector.
2727
'''
2828

29-
def __init__(self, device, path_to_detector=None, verbose=False, threshold=0.5, fp16=True):
29+
def __init__(self, device, path_to_detector=None, verbose=False, threshold=0.5, max_size=-1, fp16=True):
3030
super(RetinaFaceDetector, self).__init__(device, verbose)
3131

3232
# Initialise the face detector
3333
if path_to_detector is None:
3434
path_to_detector = self.load_from_url(models_urls['retinaface'], model_dir)
3535

3636
self.threshold = threshold
37+
self.max_size = max_size
3738
self.fp16 = fp16
3839

3940
self.face_detector = load_net(path_to_detector, self.device)
@@ -46,6 +47,7 @@ def detect_from_image(self, tensor_or_path):
4647
detected_faces = batch_detect(
4748
self.face_detector,
4849
[image],
50+
max_size=self.max_size,
4951
threshold=self.threshold,
5052
return_dict=True,
5153
fp16=self.fp16,
@@ -60,6 +62,7 @@ def detect_from_batch(self, tensor):
6062
self.face_detector,
6163
tensor,
6264
is_tensor=True,
65+
max_size=self.max_size,
6366
threshold=self.threshold,
6467
return_dict=True,
6568
fp16=self.fp16,

0 commit comments

Comments
 (0)