mirror of
https://github.com/serengil/deepface.git
synced 2025-06-09 04:55:24 +00:00
Added type hints
This commit is contained in:
parent
64e6aceff0
commit
cfff58792a
@ -5,6 +5,7 @@ import warnings
|
|||||||
import time
|
import time
|
||||||
import pickle
|
import pickle
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any, Dict, List, Tuple
|
||||||
|
|
||||||
# 3rd party dependencies
|
# 3rd party dependencies
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -45,7 +46,7 @@ if tf_version == 2:
|
|||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
|
|
||||||
|
|
||||||
def build_model(model_name):
|
def build_model(model_name: str) -> Any:
|
||||||
"""
|
"""
|
||||||
This function builds a deepface model
|
This function builds a deepface model
|
||||||
Parameters:
|
Parameters:
|
||||||
@ -91,15 +92,15 @@ def build_model(model_name):
|
|||||||
|
|
||||||
|
|
||||||
def verify(
|
def verify(
|
||||||
img1_path,
|
img1_path: str,
|
||||||
img2_path,
|
img2_path: str,
|
||||||
model_name="VGG-Face",
|
model_name: str = "VGG-Face",
|
||||||
detector_backend="opencv",
|
detector_backend: str = "opencv",
|
||||||
distance_metric="cosine",
|
distance_metric: str = "cosine",
|
||||||
enforce_detection=True,
|
enforce_detection: bool = True,
|
||||||
align=True,
|
align: bool = True,
|
||||||
normalization="base",
|
normalization: str = "base",
|
||||||
):
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
This function verifies an image pair is same person or different persons. In the background,
|
This function verifies an image pair is same person or different persons. In the background,
|
||||||
verification function represents facial images as vectors and then calculates the similarity
|
verification function represents facial images as vectors and then calculates the similarity
|
||||||
@ -231,13 +232,13 @@ def verify(
|
|||||||
|
|
||||||
|
|
||||||
def analyze(
|
def analyze(
|
||||||
img_path,
|
img_path: str,
|
||||||
actions=("emotion", "age", "gender", "race"),
|
actions: Tuple[str, ...] = ("emotion", "age", "gender", "race"),
|
||||||
enforce_detection=True,
|
enforce_detection: bool = True,
|
||||||
detector_backend="opencv",
|
detector_backend: str = "opencv",
|
||||||
align=True,
|
align: bool = True,
|
||||||
silent=False,
|
silent: bool = False,
|
||||||
):
|
) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
This function analyzes facial attributes including age, gender, emotion and race.
|
This function analyzes facial attributes including age, gender, emotion and race.
|
||||||
In the background, analysis function builds convolutional neural network models to
|
In the background, analysis function builds convolutional neural network models to
|
||||||
@ -409,16 +410,16 @@ def analyze(
|
|||||||
|
|
||||||
|
|
||||||
def find(
|
def find(
|
||||||
img_path,
|
img_path: str,
|
||||||
db_path,
|
db_path : str,
|
||||||
model_name="VGG-Face",
|
model_name : str ="VGG-Face",
|
||||||
distance_metric="cosine",
|
distance_metric : str ="cosine",
|
||||||
enforce_detection=True,
|
enforce_detection : bool =True,
|
||||||
detector_backend="opencv",
|
detector_backend : str ="opencv",
|
||||||
align=True,
|
align : bool = True,
|
||||||
normalization="base",
|
normalization : str ="base",
|
||||||
silent=False,
|
silent : bool = False,
|
||||||
):
|
) -> List[pd.DataFrame]:
|
||||||
"""
|
"""
|
||||||
This function applies verification several times and find the identities in a database
|
This function applies verification several times and find the identities in a database
|
||||||
|
|
||||||
@ -650,13 +651,13 @@ def find(
|
|||||||
|
|
||||||
|
|
||||||
def represent(
|
def represent(
|
||||||
img_path,
|
img_path: str,
|
||||||
model_name="VGG-Face",
|
model_name: str = "VGG-Face",
|
||||||
enforce_detection=True,
|
enforce_detection: bool = True,
|
||||||
detector_backend="opencv",
|
detector_backend: str = "opencv",
|
||||||
align=True,
|
align: bool = True,
|
||||||
normalization="base",
|
normalization: str = "base",
|
||||||
):
|
) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
This function represents facial images as vectors. The function uses convolutional neural
|
This function represents facial images as vectors. The function uses convolutional neural
|
||||||
networks models to generate vector embeddings.
|
networks models to generate vector embeddings.
|
||||||
@ -760,15 +761,15 @@ def represent(
|
|||||||
|
|
||||||
|
|
||||||
def stream(
|
def stream(
|
||||||
db_path="",
|
db_path: str = "",
|
||||||
model_name="VGG-Face",
|
model_name: str = "VGG-Face",
|
||||||
detector_backend="opencv",
|
detector_backend: str = "opencv",
|
||||||
distance_metric="cosine",
|
distance_metric: str = "cosine",
|
||||||
enable_face_analysis=True,
|
enable_face_analysis: bool = True,
|
||||||
source=0,
|
source: Any = 0,
|
||||||
time_threshold=5,
|
time_threshold: int = 5,
|
||||||
frame_threshold=5,
|
frame_threshold: int = 5,
|
||||||
):
|
) -> None:
|
||||||
"""
|
"""
|
||||||
This function applies real time face recognition and facial attribute analysis
|
This function applies real time face recognition and facial attribute analysis
|
||||||
|
|
||||||
@ -816,13 +817,13 @@ def stream(
|
|||||||
|
|
||||||
|
|
||||||
def extract_faces(
|
def extract_faces(
|
||||||
img_path,
|
img_path: str,
|
||||||
target_size=(224, 224),
|
target_size: Tuple[int, int] = (224, 224),
|
||||||
detector_backend="opencv",
|
detector_backend: str = "opencv",
|
||||||
enforce_detection=True,
|
enforce_detection: bool = True,
|
||||||
align=True,
|
align: bool = True,
|
||||||
grayscale=False,
|
grayscale: bool = False,
|
||||||
):
|
) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
This function applies pre-processing stages of a face recognition pipeline
|
This function applies pre-processing stages of a face recognition pipeline
|
||||||
including detection and alignment
|
including detection and alignment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user