mirror of
https://github.com/serengil/deepface.git
synced 2025-06-08 20:45:22 +00:00
represent function referenced in verify
This commit is contained in:
parent
badc4d4dc6
commit
45b4714f47
@ -139,28 +139,14 @@ def verify(img1_path, img2_path = '', model_name = 'VGG-Face', distance_metric =
|
|||||||
for i in model_names:
|
for i in model_names:
|
||||||
custom_model = models[i]
|
custom_model = models[i]
|
||||||
|
|
||||||
#decide input shape
|
#img_path, model_name = 'VGG-Face', model = None, enforce_detection = True, detector_backend = 'mtcnn'
|
||||||
input_shape = functions.find_input_shape(custom_model)
|
img1_representation = represent(img_path = img1_path
|
||||||
input_shape_x = input_shape[0]; input_shape_y = input_shape[1]
|
, model_name = model_name, model = custom_model
|
||||||
|
, enforce_detection = enforce_detection, detector_backend = detector_backend)
|
||||||
|
|
||||||
#----------------------
|
img2_representation = represent(img_path = img2_path
|
||||||
#detect and align faces
|
, model_name = model_name, model = custom_model
|
||||||
|
, enforce_detection = enforce_detection, detector_backend = detector_backend)
|
||||||
img1 = functions.preprocess_face(img=img1_path
|
|
||||||
, target_size=(input_shape_y, input_shape_x)
|
|
||||||
, enforce_detection = enforce_detection
|
|
||||||
, detector_backend = detector_backend)
|
|
||||||
|
|
||||||
img2 = functions.preprocess_face(img=img2_path
|
|
||||||
, target_size=(input_shape_y, input_shape_x)
|
|
||||||
, enforce_detection = enforce_detection
|
|
||||||
, detector_backend = detector_backend)
|
|
||||||
|
|
||||||
#----------------------
|
|
||||||
#find embeddings
|
|
||||||
|
|
||||||
img1_representation = custom_model.predict(img1)[0,:]
|
|
||||||
img2_representation = custom_model.predict(img2)[0,:]
|
|
||||||
|
|
||||||
#----------------------
|
#----------------------
|
||||||
#find distances between embeddings
|
#find distances between embeddings
|
||||||
@ -570,20 +556,10 @@ def find(img_path, db_path, model_name ='VGG-Face', distance_metric = 'cosine',
|
|||||||
for j in model_names:
|
for j in model_names:
|
||||||
custom_model = models[j]
|
custom_model = models[j]
|
||||||
|
|
||||||
#----------------------------------
|
representation = represent(img_path = employee
|
||||||
#decide input shape
|
, model_name = model_name, model = custom_model
|
||||||
|
, enforce_detection = enforce_detection, detector_backend = detector_backend)
|
||||||
|
|
||||||
input_shape = functions.find_input_shape(custom_model)
|
|
||||||
input_shape_x = input_shape[0]; input_shape_y = input_shape[1]
|
|
||||||
|
|
||||||
#----------------------------------
|
|
||||||
|
|
||||||
img = functions.preprocess_face(img = employee
|
|
||||||
, target_size = (input_shape_y, input_shape_x)
|
|
||||||
, enforce_detection = enforce_detection
|
|
||||||
, detector_backend = detector_backend)
|
|
||||||
|
|
||||||
representation = custom_model.predict(img)[0,:]
|
|
||||||
instance.append(representation)
|
instance.append(representation)
|
||||||
|
|
||||||
#-------------------------------
|
#-------------------------------
|
||||||
@ -620,19 +596,10 @@ def find(img_path, db_path, model_name ='VGG-Face', distance_metric = 'cosine',
|
|||||||
|
|
||||||
for j in model_names:
|
for j in model_names:
|
||||||
custom_model = models[j]
|
custom_model = models[j]
|
||||||
|
|
||||||
#--------------------------------
|
target_representation = represent(img_path = img_path
|
||||||
#decide input shape
|
, model_name = model_name, model = custom_model
|
||||||
input_shape = functions.find_input_shape(custom_model)
|
, enforce_detection = enforce_detection, detector_backend =detector_backend)
|
||||||
input_shape_x = input_shape[0]; input_shape_y = input_shape[1]
|
|
||||||
|
|
||||||
#--------------------------------
|
|
||||||
|
|
||||||
img = functions.preprocess_face(img = img_path, target_size = (input_shape_y, input_shape_x)
|
|
||||||
, enforce_detection = enforce_detection
|
|
||||||
, detector_backend = detector_backend)
|
|
||||||
|
|
||||||
target_representation = custom_model.predict(img)[0,:]
|
|
||||||
|
|
||||||
for k in metric_names:
|
for k in metric_names:
|
||||||
distances = []
|
distances = []
|
||||||
@ -723,7 +690,7 @@ def find(img_path, db_path, model_name ='VGG-Face', distance_metric = 'cosine',
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def represent(img_path, model_name = 'VGG-Face', distance_metric = 'euclidean', model = None, enforce_detection = True, detector_backend = 'mtcnn'):
|
def represent(img_path, model_name = 'VGG-Face', model = None, enforce_detection = True, detector_backend = 'mtcnn'):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This function represents facial images as vectors.
|
This function represents facial images as vectors.
|
||||||
@ -733,8 +700,6 @@ def represent(img_path, model_name = 'VGG-Face', distance_metric = 'euclidean',
|
|||||||
|
|
||||||
model_name (string): VGG-Face, Facenet, OpenFace, DeepFace, DeepID, Dlib, ArcFace.
|
model_name (string): VGG-Face, Facenet, OpenFace, DeepFace, DeepID, Dlib, ArcFace.
|
||||||
|
|
||||||
distance_metric (string): cosine, euclidean, euclidean_l2
|
|
||||||
|
|
||||||
model: Built deepface model. A face recognition model is built every call of verify function. You can pass pre-built face recognition model optionally if you will call verify function several times. Consider to pass model if you are going to call represent function in a for loop.
|
model: Built deepface model. A face recognition model is built every call of verify function. You can pass pre-built face recognition model optionally if you will call verify function several times. Consider to pass model if you are going to call represent function in a for loop.
|
||||||
|
|
||||||
model = DeepFace.build_model('VGG-Face')
|
model = DeepFace.build_model('VGG-Face')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user