STANAANDREY

deepface2

Jun 1st, 2025
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 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="simi.png", db_path="imgs/",
  19.     model_name="Facenet512",        # Match verify's default
  20.     detector_backend="opencv",    # Match verify' s default
  21.     distance_metric="euclidean",     # Match verify' s default
  22.     enforce_detection=False,       # Match verify' s default (and find's typical behavior)
  23.     align=True,
  24.     )
  25.  
  26.     df = results[0] if isinstance(results, list) else results
  27.  
  28.     print(len(df))
  29.     if len(df) == 0:
  30.         exit()
  31.  
  32.     # Get the row with the smallest distance
  33.     best_match = df.iloc[df['distance'].idxmin()]
  34.  
  35.     # Get the file path (identity)
  36.     identity_path = best_match['identity']
  37.     distance = best_match['distance']
  38.  
  39.     print(f"Best match: {identity_path} with distance {distance}")
  40.  
  41. if __name__ == '__main__':
  42.     main()
  43.     #print(DeepFace.verify(img1_path='menight.jpeg', img2_path='imgs/me2.jpeg'))
Advertisement
Add Comment
Please, Sign In to add comment