Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This Python file uses the following encoding: utf-8
- from deepface import DeepFace
- from pathlib import Path
- import pandas
- if __name__ == "__main__":
- database = '/home/the_gast/work/sharaga/ai/lab_5/images/'
- targets = '/home/the_gast/work/sharaga/ai/lab_5/targets/'
- for target in [str(filepath) for filepath in Path(targets).rglob("*.[jJ][pP][gG]")]:
- print('=================================================================')
- print(f'Detect next target: {target.removeprefix(targets)}')
- result = DeepFace.find(img_path=target, db_path=database, enforce_detection=False)
- for detection in result:
- dataframe: pandas.DataFrame = pandas.DataFrame(detection)[['identity', 'VGG-Face_cosine']]
- dataframe['identity'] = dataframe['identity'].apply(lambda filepath: filepath.split('/')[-2])
- dataframe: pandas.DataFrame = dataframe.groupby(['identity'], as_index = False).mean()
- dataframe = dataframe.sort_values(['VGG-Face_cosine'], ascending=True)
- for row_index in range(min(dataframe.shape[0], 10)):
- print('\t', dataframe['identity'].iloc[row_index], dataframe['VGG-Face_cosine'].iloc[row_index])
- input('Press enter to continue...')
- print('=================================================================')
- print('Finish')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement