mirror of
https://github.com/serengil/deepface.git
synced 2025-07-29 14:21:39 +00:00
update
This commit is contained in:
parent
ba136ad1d3
commit
75d7404873
@ -1,10 +1,10 @@
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
import pickle
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import cv2
|
||||
import time
|
||||
import re
|
||||
import os
|
||||
import os
|
||||
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
||||
@ -18,9 +18,13 @@ def analysis(db_path, model_name = 'VGG-Face', detector_backend = 'opencv', dist
|
||||
|
||||
face_detector = FaceDetector.build_model(detector_backend)
|
||||
print("Detector backend is ", detector_backend)
|
||||
model = DeepFace.build_model(model_name)
|
||||
print(model_name, "is built")
|
||||
threshold = dst.findThreshold(model_name, distance_metric)
|
||||
input_shape = (224, 224); input_shape_x = input_shape[0]; input_shape_y = input_shape[1]
|
||||
|
||||
text_color = (255, 255, 255)
|
||||
|
||||
employees = []
|
||||
if os.path.isdir(db_path) == True:
|
||||
for r, d, f in os.walk(db_path):
|
||||
@ -28,39 +32,48 @@ def analysis(db_path, model_name = 'VGG-Face', detector_backend = 'opencv', dist
|
||||
if('.jpg' in file):
|
||||
exact_path = r + "/" + file
|
||||
employees.append(exact_path)
|
||||
|
||||
if len(employees) == 0:
|
||||
print("WARNING: There is no image in this path ( ", db_path,") . Face recognition will not be performed.")
|
||||
|
||||
if len(employees) > 0:
|
||||
model = DeepFace.build_model(model_name)
|
||||
print(model_name, "is built")
|
||||
if os.path.isdir(db_path) == True:
|
||||
file_name = "representations_%s.pkl" % (model_name)
|
||||
file_name = file_name.replace("-", "_").lower()
|
||||
|
||||
input_shape = functions.find_input_shape(model)
|
||||
input_shape_x = input_shape[0]; input_shape_y = input_shape[1]
|
||||
if os.path.exists(db_path+"/"+file_name):
|
||||
|
||||
threshold = dst.findThreshold(model_name, distance_metric)
|
||||
|
||||
tic = time.time()
|
||||
print("Representations for images in ",db_path," folder were previously stored in ", file_name, ". If you added new instances after this file creation, then please delete this file and call find function again. It will create it again.")
|
||||
|
||||
pbar = tqdm(range(0, len(employees)), desc='Finding embeddings')
|
||||
embeddings = []
|
||||
for index in pbar:
|
||||
employee = employees[index]
|
||||
pbar.set_description("Finding embedding for %s" % (employee.split("/")[-1]))
|
||||
embedding = []
|
||||
img = functions.preprocess_face(img = employee, target_size = (input_shape_y, input_shape_x), enforce_detection = False, detector_backend = detector_backend)
|
||||
img_representation = model.predict(img)[0,:]
|
||||
f = open(db_path+'/'+file_name, 'rb')
|
||||
embeddings = pickle.load(f)
|
||||
|
||||
embedding.append(employee)
|
||||
embedding.append(img_representation)
|
||||
embeddings.append(embedding)
|
||||
print("There are ", len(embeddings)," representations found in ",file_name)
|
||||
|
||||
else:
|
||||
if len(employees) == 0:
|
||||
print("WARNING: There is no image in this path ( ", db_path,") . Face recognition will not be performed.")
|
||||
|
||||
if len(employees) > 0:
|
||||
input_shape = functions.find_input_shape(model)
|
||||
input_shape_x = input_shape[0]; input_shape_y = input_shape[1]
|
||||
|
||||
tic = time.time()
|
||||
pbar = tqdm(range(0, len(employees)), desc='Finding embeddings')
|
||||
embeddings = []
|
||||
for index in pbar:
|
||||
employee = employees[index]
|
||||
pbar.set_description("Finding embedding for %s" % (employee.split("/")[-1]))
|
||||
embedding = []
|
||||
img = functions.preprocess_face(img = employee, target_size = (input_shape_y, input_shape_x), enforce_detection = False, detector_backend = detector_backend)
|
||||
img_representation = model.predict(img)[0,:]
|
||||
embedding.append(employee)
|
||||
embedding.append(img_representation)
|
||||
embeddings.append(embedding)
|
||||
f = open(db_path+'/'+file_name, "wb")
|
||||
pickle.dump(embeddings, f)
|
||||
f.close()
|
||||
toc = time.time()
|
||||
print("Embeddings found for given data set in ", toc-tic," seconds")
|
||||
|
||||
df = pd.DataFrame(embeddings, columns = ['employee', 'embedding'])
|
||||
df['distance_metric'] = distance_metric
|
||||
|
||||
toc = time.time()
|
||||
print("Embeddings found for given data set in ", toc-tic," seconds")
|
||||
frame_count = 0
|
||||
start_time = time.time()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user