Load models to memory

2 new functions:
verify_init(model_name)
analyze_init(models)

The functions created in order to pre load models to memory for shorter analzye / verify first time
Ex:
Real time analyze waiting for first face to show
without analyze_init()
first analyze takes 1.5 sec
with analyze_init()
first analyze takes 0.3 sec
This commit is contained in:
Uria Franko 2020-04-16 10:37:23 +03:00
parent 8cc09f4314
commit 93c9462161

View File

@ -21,6 +21,50 @@ 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 analyze_init(models = []):
#---------------------------------
#if a specific target is not passed, then find them all
if len(models) == 0:
models = ['emotion', 'age', 'gender', 'race']
print("Models to initialize: ", models)
#---------------------------------
if 'emotion' in models:
emotion_model = Emotion.loadModel()
if 'age' in models:
age_model = Age.loadModel()
if 'gender' in models:
gender_model = Gender.loadModel()
if 'race' in models:
race_model = Race.loadModel()
def verify_init(model_name = 'VGG-Face'):
if model_name == 'VGG-Face':
print("Loading %s model" % model_name)
model = VGGFace.loadModel()
elif model_name == 'OpenFace':
print("Loading %s model" % model_name)
model = OpenFace.loadModel()
elif model_name == 'Facenet':
print("Loading %s model" % model_name)
model = Facenet.loadModel()
elif model_name == 'DeepFace':
print("Loading %s model" % model_name)
model = FbDeepFace.loadModel()
else:
raise ValueError("Invalid model_name passed - ", model_name)
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):