mirror of
https://github.com/serengil/deepface.git
synced 2025-07-22 18:00:02 +00:00
making distance calculation functions camel case
This commit is contained in:
parent
4800aa3e8c
commit
cefb8013bb
@ -2,7 +2,7 @@ from typing import Union
|
||||
import numpy as np
|
||||
|
||||
|
||||
def findCosineDistance(
|
||||
def find_cosine_distance(
|
||||
source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list]
|
||||
) -> np.float64:
|
||||
if isinstance(source_representation, list):
|
||||
@ -17,7 +17,7 @@ def findCosineDistance(
|
||||
return 1 - (a / (np.sqrt(b) * np.sqrt(c)))
|
||||
|
||||
|
||||
def findEuclideanDistance(
|
||||
def find_euclidean_distance(
|
||||
source_representation: Union[np.ndarray, list], test_representation: Union[np.ndarray, list]
|
||||
) -> np.float64:
|
||||
if isinstance(source_representation, list):
|
||||
@ -38,7 +38,7 @@ def l2_normalize(x: Union[np.ndarray, list]) -> np.ndarray:
|
||||
return x / np.sqrt(np.sum(np.multiply(x, x)))
|
||||
|
||||
|
||||
def findThreshold(model_name: str, distance_metric: str) -> float:
|
||||
def find_threshold(model_name: str, distance_metric: str) -> float:
|
||||
|
||||
base_threshold = {"cosine": 0.40, "euclidean": 0.55, "euclidean_l2": 0.75}
|
||||
|
||||
|
@ -249,11 +249,11 @@ def find(
|
||||
)
|
||||
|
||||
if distance_metric == "cosine":
|
||||
distance = dst.findCosineDistance(source_representation, target_representation)
|
||||
distance = dst.find_cosine_distance(source_representation, target_representation)
|
||||
elif distance_metric == "euclidean":
|
||||
distance = dst.findEuclideanDistance(source_representation, target_representation)
|
||||
distance = dst.find_euclidean_distance(source_representation, target_representation)
|
||||
elif distance_metric == "euclidean_l2":
|
||||
distance = dst.findEuclideanDistance(
|
||||
distance = dst.find_euclidean_distance(
|
||||
dst.l2_normalize(source_representation),
|
||||
dst.l2_normalize(target_representation),
|
||||
)
|
||||
@ -263,7 +263,7 @@ def find(
|
||||
distances.append(distance)
|
||||
|
||||
# ---------------------------
|
||||
target_threshold = threshold or dst.findThreshold(model_name, distance_metric)
|
||||
target_threshold = threshold or dst.find_threshold(model_name, distance_metric)
|
||||
|
||||
result_df["threshold"] = target_threshold
|
||||
result_df["distance"] = distances
|
||||
|
@ -133,11 +133,11 @@ def verify(
|
||||
img2_representation = img2_embedding_obj[0]["embedding"]
|
||||
|
||||
if distance_metric == "cosine":
|
||||
distance = dst.findCosineDistance(img1_representation, img2_representation)
|
||||
distance = dst.find_cosine_distance(img1_representation, img2_representation)
|
||||
elif distance_metric == "euclidean":
|
||||
distance = dst.findEuclideanDistance(img1_representation, img2_representation)
|
||||
distance = dst.find_euclidean_distance(img1_representation, img2_representation)
|
||||
elif distance_metric == "euclidean_l2":
|
||||
distance = dst.findEuclideanDistance(
|
||||
distance = dst.find_euclidean_distance(
|
||||
dst.l2_normalize(img1_representation), dst.l2_normalize(img2_representation)
|
||||
)
|
||||
else:
|
||||
@ -147,7 +147,7 @@ def verify(
|
||||
regions.append((img1_region, img2_region))
|
||||
|
||||
# -------------------------------
|
||||
threshold = dst.findThreshold(model_name, distance_metric)
|
||||
threshold = dst.find_threshold(model_name, distance_metric)
|
||||
distance = min(distances) # best distance
|
||||
facial_areas = regions[np.argmin(distances)]
|
||||
|
||||
|
@ -38,7 +38,7 @@ distance_vector = np.square(img1_representation - img2_representation)
|
||||
current_distance = np.sqrt(distance_vector.sum())
|
||||
logger.info(f"Euclidean distance: {current_distance}")
|
||||
|
||||
threshold = distance.findThreshold(model_name=model_name, distance_metric="euclidean")
|
||||
threshold = distance.find_threshold(model_name=model_name, distance_metric="euclidean")
|
||||
logger.info(f"Threshold for {model_name}-euclidean pair is {threshold}")
|
||||
|
||||
if current_distance < threshold:
|
||||
|
@ -6,7 +6,7 @@ from deepface.commons.logger import Logger
|
||||
|
||||
logger = Logger("tests/test_find.py")
|
||||
|
||||
threshold = distance.findThreshold(model_name="VGG-Face", distance_metric="cosine")
|
||||
threshold = distance.find_threshold(model_name="VGG-Face", distance_metric="cosine")
|
||||
|
||||
|
||||
def test_find_with_exact_path():
|
||||
|
Loading…
x
Reference in New Issue
Block a user