From 4bb49ab446553446df6d7dce1abaa57062d8d103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eefik=20Serangil?= Date: Wed, 17 Jun 2020 09:05:34 +0300 Subject: [PATCH] deepid in api and stream --- api/api.py | 9 +++++++-- deepface/commons/realtime.py | 16 ++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/api/api.py b/api/api.py index 07073d8..8b1229b 100644 --- a/api/api.py +++ b/api/api.py @@ -9,7 +9,7 @@ from tqdm import tqdm import tensorflow as tf from deepface import DeepFace -from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace +from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace, DeepID from deepface.extendedmodels import Age, Gender, Race, Emotion #import DeepFace @@ -26,7 +26,7 @@ tic = time.time() print("Loading Face Recognition Models...") -pbar = tqdm(range(0,4), desc='Loading Face Recognition Models...') +pbar = tqdm(range(0,5), desc='Loading Face Recognition Models...') for index in pbar: if index == 0: @@ -41,6 +41,9 @@ for index in pbar: elif index == 3: pbar.set_description("Loading Facebook DeepFace") deepface_model = FbDeepFace.loadModel() + elif index == 4: + pbar.set_description("Loading DeepID DeepFace") + deepid_model = DeepID.loadModel() toc = time.time() @@ -195,6 +198,8 @@ def verify(): resp_obj = DeepFace.verify(instances, model_name = model_name, distance_metric = distance_metric, model = openface_model) elif model_name == "DeepFace": resp_obj = DeepFace.verify(instances, model_name = model_name, distance_metric = distance_metric, model = deepface_model) + elif model_name == "DeepID": + resp_obj = DeepFace.verify(instances, model_name = model_name, distance_metric = distance_metric, model = deepid_model) elif model_name == "Ensemble": models = {} models["VGG-Face"] = vggface_model diff --git a/deepface/commons/realtime.py b/deepface/commons/realtime.py index 8f5ee5f..7531c64 100644 --- a/deepface/commons/realtime.py +++ b/deepface/commons/realtime.py @@ -9,11 +9,7 @@ import re import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' -#from basemodels import VGGFace, OpenFace, Facenet, FbDeepFace -#from extendedmodels import Age, Gender, Race, Emotion -#from commons import functions, realtime, distance as dst - -from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace +from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace, DeepID from deepface.extendedmodels import Age, Gender, Race, Emotion from deepface.commons import functions, realtime, distance as dst @@ -57,10 +53,18 @@ def analysis(db_path, model_name, distance_metric, enable_face_analysis = True): model = FbDeepFace.loadModel() input_shape = (152, 152) + elif model_name == 'DeepID': + print("Using DeepID model backend", distance_metric,"distance.") + model = DeepID.loadModel() + input_shape = (55, 47) + else: raise ValueError("Invalid model_name passed - ", model_name) #------------------------ + input_shape_x = input_shape[0] + input_shape_y = input_shape[1] + #tuned thresholds for model and metric pair threshold = functions.findThreshold(model_name, distance_metric) @@ -341,7 +345,7 @@ def analysis(db_path, model_name, distance_metric, enable_face_analysis = True): #------------------------------- #face recognition - custom_face = functions.detectFace(custom_face, input_shape) + custom_face = functions.detectFace(custom_face, (input_shape_y, input_shape_x)) #check detectFace function handled if custom_face.shape[1:3] == input_shape: