mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
normalize_input simplified
This commit is contained in:
parent
7743629762
commit
d1e16f68b5
@ -110,47 +110,42 @@ def normalize_input(img, normalization = 'base'):
|
|||||||
|
|
||||||
if normalization == 'base':
|
if normalization == 'base':
|
||||||
return img
|
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
|
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()
|
mean, std = img.mean(), img.std()
|
||||||
img = (img - mean) / std
|
img = (img - mean) / std
|
||||||
|
|
||||||
elif normalization == 'v1':
|
elif(normalization=="Facenet2018"):
|
||||||
#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"):
|
|
||||||
# simply / 127.5 - 1 (similar to facenet 2018 model preprocessing step as @iamrishab posted)
|
# simply / 127.5 - 1 (similar to facenet 2018 model preprocessing step as @iamrishab posted)
|
||||||
img /= 127.5
|
img /= 127.5
|
||||||
img -= 1
|
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
|
return img
|
||||||
|
Loading…
x
Reference in New Issue
Block a user