Merge pull request #17 from uriafranko/uria-franko

passing already built models to analyze function as well
This commit is contained in:
Sefik Ilkin Serengil 2020-04-17 15:20:10 +03:00 committed by GitHub
commit fc70aa0aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 77 deletions

1
Contributors.md Normal file
View File

@ -0,0 +1 @@
uriafranko

View File

@ -20,6 +20,7 @@ from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace
from deepface.extendedmodels import Age, Gender, Race, Emotion from deepface.extendedmodels import Age, Gender, Race, Emotion
from deepface.commons import functions, realtime, distance as dst from deepface.commons import functions, realtime, distance as dst
def verify(img1_path, img2_path='' def verify(img1_path, img2_path=''
, model_name ='VGG-Face', distance_metric = 'cosine', model = None): , model_name ='VGG-Face', distance_metric = 'cosine', model = None):
@ -148,7 +149,8 @@ def verify(img1_path, img2_path=''
return resp_obj return resp_obj
#return resp_objects #return resp_objects
def analyze(img_path, actions= []):
def analyze(img_path, actions= [], models= {}):
if type(img_path) == list: if type(img_path) == list:
img_paths = img_path.copy() img_paths = img_path.copy()
@ -168,15 +170,27 @@ def analyze(img_path, actions= []):
#--------------------------------- #---------------------------------
if 'emotion' in actions: if 'emotion' in actions:
if 'emotion' in models:
emotion_model = models['emotion']
else:
emotion_model = Emotion.loadModel() emotion_model = Emotion.loadModel()
if 'age' in actions: if 'age' in actions:
if 'age' in models:
age_model = models['age']
else:
age_model = Age.loadModel() age_model = Age.loadModel()
if 'gender' in actions: if 'gender' in actions:
if 'gender' in models:
gender_model = models['gender']
else:
gender_model = Gender.loadModel() gender_model = Gender.loadModel()
if 'race' in actions: if 'race' in actions:
if 'race' in models:
race_model = models['race']
else:
race_model = Race.loadModel() race_model = Race.loadModel()
#--------------------------------- #---------------------------------
@ -289,13 +303,16 @@ def analyze(img_path, actions= []):
return resp_obj return resp_obj
#return resp_objects #return resp_objects
def detectFace(img_path): def detectFace(img_path):
img = functions.detectFace(img_path)[0] #detectFace returns (1, 224, 224, 3) img = functions.detectFace(img_path)[0] #detectFace returns (1, 224, 224, 3)
return img[:, :, ::-1] #bgr to rgb return img[:, :, ::-1] #bgr to rgb
def stream(db_path, model_name ='VGG-Face', distance_metric = 'cosine', enable_face_analysis = True): def stream(db_path, model_name ='VGG-Face', distance_metric = 'cosine', enable_face_analysis = True):
realtime.analysis(db_path, model_name, distance_metric, enable_face_analysis) realtime.analysis(db_path, model_name, distance_metric, enable_face_analysis)
#--------------------------- #---------------------------
functions.initializeFolder() functions.initializeFolder()