Skip to content

Commit

Permalink
initialize input moved to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil committed Dec 7, 2020
1 parent 71e72d6 commit 7b34c89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
29 changes: 3 additions & 26 deletions deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def verify(img1_path, img2_path = '', model_name = 'VGG-Face', distance_metric =

tic = time.time()

img_list, bulkProcess = initialize_input(img1_path, img2_path)
img_list, bulkProcess = functions.initialize_input(img1_path, img2_path)
functions.initialize_detector(detector_backend = detector_backend)

resp_objects = []
Expand Down Expand Up @@ -304,7 +304,7 @@ def analyze(img_path, actions = [], models = {}, enforce_detection = True
"""

img_paths, bulkProcess = initialize_input(img_path)
img_paths, bulkProcess = functions.initialize_input(img_path)
functions.initialize_detector(detector_backend = detector_backend)

#---------------------------------
Expand Down Expand Up @@ -470,7 +470,7 @@ def find(img_path, db_path, model_name ='VGG-Face', distance_metric = 'cosine',

tic = time.time()

img_paths, bulkProcess = initialize_input(img_path)
img_paths, bulkProcess = functions.initialize_input(img_path)
functions.initialize_detector(detector_backend = detector_backend)

#-------------------------------
Expand Down Expand Up @@ -756,29 +756,6 @@ def detectFace(img_path, detector_backend = 'mtcnn'):

img = functions.preprocess_face(img = img_path, detector_backend = detector_backend)[0] #preprocess_face returns (1, 224, 224, 3)
return img[:, :, ::-1] #bgr to rgb

def initialize_input(img1_path, img2_path = None):

"""
verify, analyze and find functions build complex machine learning models in every call.
To avoid memory problems, you can pass image pairs as array. This function manages this usage is enabled or not
E.g.
result = DeepFace.verify("img1.jpg", "img2.jpg")
results = DeepFace.verify([['img1.jpg', 'img2.jpg'], ['img1.jpg', 'img3.jpg']])
"""

if type(img1_path) == list:
bulkProcess = True
img_list = img1_path.copy()
else:
bulkProcess = False
if img2_path != None:
img_list = [[img1_path, img2_path]]
else:
img_list = [img1_path]

return img_list, bulkProcess

#---------------------------
#main
Expand Down
14 changes: 14 additions & 0 deletions deepface/commons/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
from deepface.commons import distance
from mtcnn import MTCNN #0.1.0

def initialize_input(img1_path, img2_path = None):

if type(img1_path) == list:
bulkProcess = True
img_list = img1_path.copy()
else:
bulkProcess = False
if img2_path != None:
img_list = [[img1_path, img2_path]]
else:
img_list = [img1_path]

return img_list, bulkProcess

def initialize_detector(detector_backend):

global face_detector
Expand Down

0 comments on commit 7b34c89

Please sign in to comment.