mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
adding some docstrings
This commit is contained in:
parent
92f0fb6c3b
commit
626aa2e385
@ -175,6 +175,14 @@ def verify(
|
||||
def find_cosine_distance(
|
||||
source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list]
|
||||
) -> np.float64:
|
||||
"""
|
||||
Find cosine distance between two given vectors
|
||||
Args:
|
||||
source_representation (np.ndarray or list): 1st vector
|
||||
test_representation (np.ndarray or list): 2nd vector
|
||||
Returns
|
||||
distance (np.float64): calculated cosine distance
|
||||
"""
|
||||
if isinstance(source_representation, list):
|
||||
source_representation = np.array(source_representation)
|
||||
|
||||
@ -190,6 +198,14 @@ def find_cosine_distance(
|
||||
def find_euclidean_distance(
|
||||
source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list]
|
||||
) -> np.float64:
|
||||
"""
|
||||
Find euclidean distance between two given vectors
|
||||
Args:
|
||||
source_representation (np.ndarray or list): 1st vector
|
||||
test_representation (np.ndarray or list): 2nd vector
|
||||
Returns
|
||||
distance (np.float64): calculated euclidean distance
|
||||
"""
|
||||
if isinstance(source_representation, list):
|
||||
source_representation = np.array(source_representation)
|
||||
|
||||
@ -203,12 +219,29 @@ def find_euclidean_distance(
|
||||
|
||||
|
||||
def l2_normalize(x: Union[np.ndarray, list]) -> np.ndarray:
|
||||
"""
|
||||
Normalize input vector with l2
|
||||
Args:
|
||||
x (np.ndarray or list): given vector
|
||||
Returns:
|
||||
y (np.ndarray): l2 normalized vector
|
||||
"""
|
||||
if isinstance(x, list):
|
||||
x = np.array(x)
|
||||
return x / np.sqrt(np.sum(np.multiply(x, x)))
|
||||
|
||||
|
||||
def find_threshold(model_name: str, distance_metric: str) -> float:
|
||||
"""
|
||||
Retrieve pre-tuned threshold values for a model and distance metric pair
|
||||
Args:
|
||||
model_name (str): facial recognition model name
|
||||
distance_metric (str): distance metric name. Options are cosine, euclidean
|
||||
and euclidean_l2.
|
||||
Returns:
|
||||
threshold (float): threshold value for that model name and distance metric
|
||||
pair. Distances less than this threshold will be classified same person.
|
||||
"""
|
||||
|
||||
base_threshold = {"cosine": 0.40, "euclidean": 0.55, "euclidean_l2": 0.75}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user