From d1e16f68b5df5d62224b265fa29bb2fed33ea150 Mon Sep 17 00:00:00 2001 From: Sefik Ilkin Serengil Date: Sun, 1 Aug 2021 22:51:55 +0300 Subject: [PATCH] normalize_input simplified --- deepface/commons/functions.py | 59 ++++++++++++++++------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/deepface/commons/functions.py b/deepface/commons/functions.py index a35f8bc4d..07f3b9bd8 100644 --- a/deepface/commons/functions.py +++ b/deepface/commons/functions.py @@ -110,47 +110,42 @@ def normalize_input(img, normalization = 'base'): if normalization == 'base': return img - else: #@trevorgribble recommend the following idea - + else: + #@trevorgribble and @davedgd contributed this feature + img *= 255 #restore input in scale of [0, 255] because it was normalized in scale of [0, 1] in preprocess_face - if normalization == 'Facenet': + if normalization == 'raw': + pass #return just restored pixels + + elif normalization == 'Facenet': mean, std = img.mean(), img.std() img = (img - mean) / std - elif normalization == 'v1': - #BGR mean subtraction / 255 normalization - img[..., 0]-= 131.0912 - img[..., 1] -= 103.8827 - img[..., 2] -= 91.4953 - img = img[..., ::-1] - img /= 255 - - elif(normalization =="v2"): - #RGB mean subtraction / 255 normalization - img[..., 0]-= 131.0912 - img[..., 1] -= 103.8827 - img[..., 2] -= 91.4953 - img /= 255 - - elif(normalization =="v3"): - #BGR mean subtraction normalization - img[..., 0]-= 131.0912 - img[..., 1] -= 103.8827 - img[..., 2] -= 91.4953 - img = img[..., ::-1] - - elif(normalization =="v4"): - #RGB mean subtraction normalization - img[..., 0]-= 131.0912 - img[..., 1] -= 103.8827 - img[..., 2] -= 91.4953 - - elif(normalization=="v6"): + elif(normalization=="Facenet2018"): # simply / 127.5 - 1 (similar to facenet 2018 model preprocessing step as @iamrishab posted) img /= 127.5 img -= 1 + elif normalization == 'VGGFace': + # mean subtraction based on VGGFace1 training data + img[..., 0] -= 93.5940 + img[..., 1] -= 104.7624 + img[..., 2] -= 129.1863 + + elif(normalization == 'VGGFace2'): + # mean subtraction based on VGGFace2 training data + img[..., 0] -= 91.4953 + img[..., 1] -= 103.8827 + img[..., 2] -= 131.0912 + + elif(normalization == 'ArcFace'): + #Reference study: The faces are cropped and resized to 112×112, + #and each pixel (ranged between [0, 255]) in RGB images is normalised + #by subtracting 127.5 then divided by 128. + img -= 127.5 + img /= 128 + #----------------------------- return img