From 94236318ac1a6e268d4245c87afe7bc203913f16 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Thu, 1 Jul 2021 17:17:46 +0300 Subject: [PATCH] comments for resize --- deepface/commons/functions.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index 2e32b38..65489f4 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -123,11 +123,14 @@ def preprocess_face(img, target_size=(224, 224), grayscale = False, enforce_dete #post-processing if grayscale == True: img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + + #--------------------------------------------------- + #resize image to expected shape - # img = cv2.resize(img, target_size) + # img = cv2.resize(img, target_size) #resize causes transformation on base image, adding black pixels to resize will not deform the base image # First resize the longer side to the target size - factor = target_size[0] / max(img.shape) # Suppose target_size[0] == target_size[1] + factor = target_size[0] / max(img.shape) # Suppose target_size[0] == target_size[1]. What if this condition is not satisfied? E.g. DeepID expects 57x47 shaped inputs. dsize = (int(img.shape[1] * factor), int(img.shape[0] * factor)) img = cv2.resize(img, dsize) @@ -140,6 +143,8 @@ def preprocess_face(img, target_size=(224, 224), grayscale = False, enforce_dete else: img = np.pad(img, ((diff_0 // 2, diff_0 - diff_0 // 2), (diff_1 // 2, diff_1 - diff_1 // 2)), 'constant') + #--------------------------------------------------- + img_pixels = image.img_to_array(img) img_pixels = np.expand_dims(img_pixels, axis = 0) img_pixels /= 255 #normalize input in [0, 1]