Advertisement
STANAANDREY

deepface

May 31st, 2025 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from deepface import DeepFace
  2. import os
  3.  
  4. os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
  5.  
  6. def main():
  7.     # Assuming img1_path and img2_path are defined elsewhere
  8.     # and point to image files
  9.  
  10.     print('matching...')
  11.     # result = DeepFace.verify(
  12.     #     img1_path="bieber.jpeg",
  13.     #     img2_path="bieber.jpg",
  14.     #     model_name="ArcFace",
  15.     #     detector_backend="retinaface"
  16.     # )
  17.  
  18.     results = DeepFace.find(img_path="menight.jpeg", db_path="imgs/", model_name="ArcFace",
  19.                             detector_backend="mtcnn",
  20.                             distance_metric="euclidean",
  21.                             #enforce_detection=False,
  22.                             )
  23.  
  24.     df = results[0] if isinstance(results, list) else results
  25.  
  26.     print(len(df))
  27.     if len(df) == 0:
  28.         exit()
  29.  
  30.     # Get the row with the smallest distance
  31.     best_match = df.iloc[df['distance'].idxmin()]
  32.  
  33.     # Get the file path (identity)
  34.     identity_path = best_match['identity']
  35.     distance = best_match['distance']
  36.  
  37.     print(f"Best match: {identity_path} with distance {distance}")
  38.  
  39. if __name__ == '__main__':
  40.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement