File size: 1,577 Bytes
d3dae3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""import os 
os.environ["SM_FRAMEWORK"] = "tf.keras"
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ['NUMBAPRO_NVVM']='/share/pkg.7/cuda/11.2/install/nvvm/lib64/libnvvm.so'
os.environ['NUMBAPRO_LIBDEVICE']='/share/pkg.7/cuda/11.2/install/nvvm/libdevice/'
import segmentation_models as sm
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'"""
import tensorflow as tf
import keras
import keras_vggface
from keras_vggface.vggface import VGGFace
import mtcnn
import numpy as np
import matplotlib as mpl
from keras.utils.data_utils import get_file
import dlib
import keras_vggface.utils
import PIL
import os.path
os.environ['KMP_DUPLICATE_LIB_OK']='True'
from deepface import DeepFace
import pandas as pd
import sys
import gradio as gr
from PIL import Image

models = [
  "VGG-Face", 
  "Facenet", 
  "Facenet512", 
  "OpenFace", 
  "DeepFace", 
  "DeepID", 
  "ArcFace", 
  "Dlib", 
  "SFace",
]

def db_find(path, db="database", model=0, thresh=.25):
    m = model
    dfs = DeepFace.find(img_path=path, db_path=db, model_name=models[m], detector_backend="mtcnn", enforce_detection=False)
    df = dfs[0].copy()
    df = df.drop(columns=['source_x', 'source_y', 'source_w', 'source_h'])
    df['id'] = df['identity'].str.strip("atfalmafkoda_unzip/database/person").str.split("/")
    df['id'] = df['id'].apply(lambda x: x[0])
    img_len = df.loc[df["VGG-Face_cosine"] < .3].shape[0]
    imgs = df.head(img_len)['identity'].tolist()
    return df.loc[df["VGG-Face_cosine"] < .3], imgs

demo = gr.Interface(fn=db_find, inputs="image", outputs=["dataframe", "gallery"])
demo.launch()