CaesarAI / CaesarFaceRecognition /caesardeepface.py
CaesarCloudSync
CaesarAI Deployed
9d3162f
raw
history blame
1.87 kB
from deepface import DeepFace
class CaesarDeepFace:
"""
https://github.com/serengil/deepface
"""
def __init__(self) -> None:
self.metrics = ["cosine", "euclidean", "euclidean_l2"]
self.models = ["VGG-Face", "Facenet", "Facenet512", "OpenFace", "DeepFace", "DeepID", "ArcFace", "Dlib", "SFace"]
self.backends = [
'opencv',
'ssd',
'dlib',
'mtcnn',
'retinaface',
'mediapipe'
]
def face_authentication(self,filename1="img1.jpg",filename2="img2.jpg"):
#face verification
# Value Error
try:
result = DeepFace.verify(img1_path =filename1 ,
img2_path = filename2,
distance_metric = self.metrics[0],
model_name = self.models[0],
detector_backend = self.backends[0]
)
return result
except ValueError as vex:
return {"message":"Face wasn't detected","error":f"{type(vex)},{vex}"}
def face_recognition(self,filename,db_path="C:/workspace/my_db"):
dfs = DeepFace.find(img_path =filename,
db_path = db_path,
distance_metric = self.metrics[2])
return dfs
def face_analyze(self,filename="img1.jpg"):
objs = DeepFace.analyze(img_path = filename,
actions = ['age', 'gender', 'race', 'emotion'])
return objs
def face_embeddigns(self,filename):
embedding_objs = DeepFace.represent(img_path = filename)
return embedding_objs
def face_streaming(self,db_path="C:/User/Sefik/Desktop/database"):
DeepFace.stream(db_path = db_path)
if __name__ == "__main__":
caesardeepface = CaesarDeepFace()
result = caesardeepface.face_authentication(filename2="img3.jpg")
print(result)