Skip to content

Commit

Permalink
normalize_input simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Aug 1, 2021
1 parent 7743629 commit d1e16f6
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions deepface/commons/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1e16f6

Please sign in to comment.