Added type hints

This commit is contained in:
RazaProdigy 2023-12-17 13:59:32 +04:00
parent 64e6aceff0
commit cfff58792a

View File

@ -5,6 +5,7 @@ import warnings
import time
import pickle
import logging
from typing import Any, Dict, List, Tuple
# 3rd party dependencies
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
Parameters:
@ -91,15 +92,15 @@ def build_model(model_name):
def verify(
img1_path,
img2_path,
model_name="VGG-Face",
detector_backend="opencv",
distance_metric="cosine",
enforce_detection=True,
align=True,
normalization="base",
):
img1_path: str,
img2_path: str,
model_name: str = "VGG-Face",
detector_backend: str = "opencv",
distance_metric: str = "cosine",
enforce_detection: bool = True,
align: bool = True,
normalization: str = "base",
) -> Dict[str, Any]:
"""
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
@ -231,13 +232,13 @@ def verify(
def analyze(
img_path,
actions=("emotion", "age", "gender", "race"),
enforce_detection=True,
detector_backend="opencv",
align=True,
silent=False,
):
img_path: str,
actions: Tuple[str, ...] = ("emotion", "age", "gender", "race"),
enforce_detection: bool = True,
detector_backend: str = "opencv",
align: bool = True,
silent: bool = False,
) -> List[Dict[str, Any]]:
"""
This function analyzes facial attributes including age, gender, emotion and race.
In the background, analysis function builds convolutional neural network models to
@ -409,16 +410,16 @@ def analyze(
def find(
img_path,
db_path,
model_name="VGG-Face",
distance_metric="cosine",
enforce_detection=True,
detector_backend="opencv",
align=True,
normalization="base",
silent=False,
):
img_path: str,
db_path : str,
model_name : str ="VGG-Face",
distance_metric : str ="cosine",
enforce_detection : bool =True,
detector_backend : str ="opencv",
align : bool = True,
normalization : str ="base",
silent : bool = False,
) -> List[pd.DataFrame]:
"""
This function applies verification several times and find the identities in a database
@ -650,13 +651,13 @@ def find(
def represent(
img_path,
model_name="VGG-Face",
enforce_detection=True,
detector_backend="opencv",
align=True,
normalization="base",
):
img_path: str,
model_name: str = "VGG-Face",
enforce_detection: bool = True,
detector_backend: str = "opencv",
align: bool = True,
normalization: str = "base",
) -> List[Dict[str, Any]]:
"""
This function represents facial images as vectors. The function uses convolutional neural
networks models to generate vector embeddings.
@ -760,15 +761,15 @@ def represent(
def stream(
db_path="",
model_name="VGG-Face",
detector_backend="opencv",
distance_metric="cosine",
enable_face_analysis=True,
source=0,
time_threshold=5,
frame_threshold=5,
):
db_path: str = "",
model_name: str = "VGG-Face",
detector_backend: str = "opencv",
distance_metric: str = "cosine",
enable_face_analysis: bool = True,
source: Any = 0,
time_threshold: int = 5,
frame_threshold: int = 5,
) -> None:
"""
This function applies real time face recognition and facial attribute analysis
@ -816,13 +817,13 @@ def stream(
def extract_faces(
img_path,
target_size=(224, 224),
detector_backend="opencv",
enforce_detection=True,
align=True,
grayscale=False,
):
img_path: str,
target_size: Tuple[int, int] = (224, 224),
detector_backend: str = "opencv",
enforce_detection: bool = True,
align: bool = True,
grayscale: bool = False,
) -> List[Dict[str, Any]]:
"""
This function applies pre-processing stages of a face recognition pipeline
including detection and alignment