unit tests

This commit is contained in:
Sefik Ilkin Serengil 2022-05-20 13:20:24 +01:00
parent eeaf1253da
commit 6438075233

View File

@ -135,13 +135,9 @@ def test_cases():
print("-----------------------------------------") print("-----------------------------------------")
print("Face recognition tests") print("Facial recognition tests")
passed_tests = 0; test_cases = 0
for model in models: for model in models:
#prebuilt_model = DeepFace.build_model(model)
#print(model," is built")
for metric in metrics: for metric in metrics:
for instance in dataset: for instance in dataset:
img1 = instance[0] img1 = instance[0]
@ -150,43 +146,32 @@ def test_cases():
resp_obj = DeepFace.verify(img1, img2 resp_obj = DeepFace.verify(img1, img2
, model_name = model , model_name = model
#, model = prebuilt_model
, distance_metric = metric) , distance_metric = metric)
prediction = resp_obj["verified"] prediction = resp_obj["verified"]
distance = round(resp_obj["distance"], 2) distance = round(resp_obj["distance"], 2)
threshold = resp_obj["threshold"] threshold = resp_obj["threshold"]
evaluate( prediction == result ) passed = prediction == result
test_result_label = "failed" evaluate(passed)
if prediction == result:
passed_tests = passed_tests + 1 if passed:
test_result_label = "passed" test_result_label = "passed"
else:
test_result_label = "failed"
if prediction == True: if prediction == True:
classified_label = "verified" classified_label = "verified"
else: else:
classified_label = "unverified" classified_label = "unverified"
test_cases = test_cases + 1
print(img1.split("/")[-1], "-", img2.split("/")[-1], classified_label, "as same person based on", model,"and",metric,". Distance:",distance,", Threshold:", threshold,"(",test_result_label,")") print(img1.split("/")[-1], "-", img2.split("/")[-1], classified_label, "as same person based on", model,"and",metric,". Distance:",distance,", Threshold:", threshold,"(",test_result_label,")")
print("--------------------------") print("--------------------------")
#----------------------------------------- #-----------------------------------------
print("Passed unit tests: ",passed_tests," / ",test_cases)
min_score = 70
accuracy = 100 * passed_tests / test_cases
accuracy = round(accuracy, 2)
print("--------------------------")
#-----------------------------------
print("--------------------------") print("--------------------------")
print("Passing numpy array to analyze function") print("Passing numpy array to analyze function")