From b2139db9a8ffb4707832106a58f519bbd04e6118 Mon Sep 17 00:00:00 2001 From: Sida Liu Date: Tue, 13 Aug 2024 01:38:01 +0800 Subject: [PATCH] #12 but only works when there's one face selected --- Pytorch_Retinaface/pytorch_retinaface.py | 2 +- __init__.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Pytorch_Retinaface/pytorch_retinaface.py b/Pytorch_Retinaface/pytorch_retinaface.py index 0d9e2c3..91c6400 100644 --- a/Pytorch_Retinaface/pytorch_retinaface.py +++ b/Pytorch_Retinaface/pytorch_retinaface.py @@ -106,7 +106,7 @@ class Pytorch_RetinaFace: # Crop the region and add padding to form a square cropped_imgs.append(image[crop_y1:crop_y2, crop_x1:crop_x2]) - bbox_infos.append((original_crop_x1, original_crop_y1, original_crop_x2, original_crop_y2)) + bbox_infos.append(((original_crop_x2-original_crop_x1, original_crop_y2-original_crop_y1),(original_crop_x1, original_crop_y1, original_crop_x2, original_crop_y2))) return cropped_imgs, bbox_infos def detect_faces(self, img): diff --git a/__init__.py b/__init__.py index 8af29fc..582fd8d 100644 --- a/__init__.py +++ b/__init__.py @@ -132,13 +132,14 @@ class AutoCropFaces: # If we haven't selected anything, then return original images. if len(selected_faces) == 0: - selected_crop_data = [(0, 0, img.shape[3], img.shape[2]) for img in original_images] - return (image, selected_crop_data) + # selected_crop_data = [(0, 0, img.shape[3], img.shape[2]) for img in original_images] + return (image, None) # If there is only one detected face in batch of images, just return that one. elif len(selected_faces) <= 1: out = selected_faces[0] - return (out, selected_crop_data) + crop_data = selected_crop_data[0] # to be compatible with WAS + return (out, crop_data) # Determine the index of the face with the maximum width max_width_index = max(range(len(selected_faces)), key=lambda i: selected_faces[i].shape[1]) @@ -165,6 +166,7 @@ class AutoCropFaces: else: out = torch.cat((out, face_image), dim=0) + #TODO: WAS doesn't not support multiple faces, so this won't work with WAS. return (out, selected_crop_data) NODE_CLASS_MAPPINGS = {