Advertisement
Ilya_Bykonya

Face detection. Lab-5.

Nov 27th, 2023 (edited)
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | Source Code | 0 0
  1. # This Python file uses the following encoding: utf-8
  2. from deepface import DeepFace
  3. from pathlib import Path
  4. import pandas
  5.  
  6. if __name__ == "__main__":
  7.     database = '/home/the_gast/work/sharaga/ai/lab_5/images/'
  8.     targets = '/home/the_gast/work/sharaga/ai/lab_5/targets/'
  9.     for target in [str(filepath) for filepath in Path(targets).rglob("*.[jJ][pP][gG]")]:
  10.         print('=================================================================')
  11.         print(f'Detect next target: {target.removeprefix(targets)}')
  12.         result = DeepFace.find(img_path=target, db_path=database, enforce_detection=False)
  13.         for detection in result:
  14.             dataframe: pandas.DataFrame = pandas.DataFrame(detection)[['identity', 'VGG-Face_cosine']]
  15.             dataframe['identity'] = dataframe['identity'].apply(lambda filepath: filepath.split('/')[-2])
  16.             dataframe: pandas.DataFrame = dataframe.groupby(['identity'], as_index = False).mean()
  17.             dataframe = dataframe.sort_values(['VGG-Face_cosine'], ascending=True)
  18.             for row_index in range(min(dataframe.shape[0], 10)):
  19.                 print('\t', dataframe['identity'].iloc[row_index], dataframe['VGG-Face_cosine'].iloc[row_index])
  20.         input('Press enter to continue...')
  21.         print('=================================================================')
  22.     print('Finish')
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement