Skip to content

Commit

Permalink
added feature for choosing different face recognition models
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Visor committed May 5, 2022
1 parent 76ea966 commit b532d77
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions detect-face.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os

backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']
models = ['VGG-Face', 'Facenet', 'Facenet512', 'OpenFace', 'DeepFace', 'DeepID', 'ArcFace', 'Dlib']
models = ['VGG-Face', 'Facenet512', 'ArcFace', 'Dlib']



Expand All @@ -25,14 +25,16 @@ def main():
source_image = arguments.source_image[0]
database_path = arguments.database_path[0]
k_value = arguments.k_value[0]
model = arguments.model[0]
output_file = arguments.output_file[0]

identities = []

results_dataframe = DeepFace.find(img_path = source_image,
db_path = database_path,
enforce_detection = False,
detector_backend = backends[3])
detector_backend = backends[3],
model_name=model)

# Get the first 'K' results from the facial recognition system.
for i, row in results_dataframe.iloc[:k_value].iterrows():
Expand Down Expand Up @@ -99,6 +101,9 @@ def parse_command_line_arguments() -> argparse.ArgumentParser:
parser.add_argument('-k', '--k_value', type=int, nargs=1, required=True,
help='Determines the value used for Top-K Accuracy.')

parser.add_argument('-m', '--model', choices=['VGG-Face', 'Facenet512', 'ArcFace', 'Ensemble'], nargs=1, required=True,
help='Face recognition model to use.')

parser.add_argument('-o', '--output_file', nargs=1, required=True,
help='Output file to write accuracy results to (Ex. "output.txt")')

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tensorflow
deepface
tqdm
lightgbm
7 changes: 5 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def main():
source_directory = arguments.source_directory[0]
database_path = arguments.database_path[0]
k_value = arguments.k_value[0]
model = arguments.model[0]
output_file = arguments.output_file[0]

#results = [os.path.join(dp, f) for dp, dn, fn in os.walk(source_directory) for f in fn]
results = get_an_image_from_each_class(source_directory)
source_images_count = len(results)
correct_predictions = 0
Expand All @@ -43,7 +43,7 @@ def main():
out_file.write('\n' + str(count) + '.\n')
out_file.close()

correct_predictions += subprocess.call([sys.executable, 'detect-face.py', '-s', item, '-d', database_path, '-k', str(k_value), '-o', output_file])
correct_predictions += subprocess.call([sys.executable, 'detect-face.py', '-s', item, '-d', database_path, '-k', str(k_value), '-m', model, '-o', output_file])

count += 1
progress_bar.update(1)
Expand Down Expand Up @@ -77,6 +77,9 @@ def parse_command_line_arguments() -> argparse.ArgumentParser:
parser.add_argument('-k', '--k_value', type=int, nargs=1, required=True,
help='Determines the value used for Top-K Accuracy.')

parser.add_argument('-m', '--model', choices=['VGG-Face', 'Facenet512', 'ArcFace', 'Ensemble'], nargs=1, required=True,
help='Face recognition model to use.')

parser.add_argument('-o', '--output_file', nargs=1, required=True,
help='Output file to write accuracy results to (Ex. "output.txt")')

Expand Down

0 comments on commit b532d77

Please sign in to comment.