accept optional parameter - 'threshold' in verify method

This commit is contained in:
gobinathal 2024-04-30 23:29:45 +05:30
parent 42b45cc37a
commit b864f6a38b
2 changed files with 15 additions and 2 deletions

View File

@ -72,6 +72,7 @@ def verify(
expand_percentage: int = 0, expand_percentage: int = 0,
normalization: str = "base", normalization: str = "base",
silent: bool = False, silent: bool = False,
threshold: Optional[float] = None,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
""" """
Verify if an image pair represents the same person or different persons. Verify if an image pair represents the same person or different persons.
@ -107,6 +108,11 @@ def verify(
silent (boolean): Suppress or allow some log messages for a quieter analysis process silent (boolean): Suppress or allow some log messages for a quieter analysis process
(default is False). (default is False).
threshold (float): Specify a threshold to determine whether a pair represents the same
person or different individuals. This threshold is used for comparing distances.
If left unset, default pre-tuned threshold values will be applied based on the specified
model name and distance metric (default is None).
Returns: Returns:
result (dict): A dictionary containing verification results with following keys. result (dict): A dictionary containing verification results with following keys.
@ -143,6 +149,7 @@ def verify(
expand_percentage=expand_percentage, expand_percentage=expand_percentage,
normalization=normalization, normalization=normalization,
silent=silent, silent=silent,
threshold=threshold,
) )

View File

@ -1,6 +1,6 @@
# built-in dependencies # built-in dependencies
import time import time
from typing import Any, Dict, Union, List, Tuple from typing import Any, Dict, Optional, Union, List, Tuple
# 3rd party dependencies # 3rd party dependencies
import numpy as np import numpy as np
@ -24,6 +24,7 @@ def verify(
expand_percentage: int = 0, expand_percentage: int = 0,
normalization: str = "base", normalization: str = "base",
silent: bool = False, silent: bool = False,
threshold: Optional[float] = None,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
""" """
Verify if an image pair represents the same person or different persons. Verify if an image pair represents the same person or different persons.
@ -64,6 +65,11 @@ def verify(
silent (boolean): Suppress or allow some log messages for a quieter analysis process silent (boolean): Suppress or allow some log messages for a quieter analysis process
(default is False). (default is False).
threshold (float): Specify a threshold to determine whether a pair represents the same
person or different individuals. This threshold is used for comparing distances.
If left unset, default pre-tuned threshold values will be applied based on the specified
model name and distance metric (default is None).
Returns: Returns:
result (dict): A dictionary containing verification results. result (dict): A dictionary containing verification results.
@ -186,7 +192,7 @@ def verify(
) )
# find the face pair with minimum distance # find the face pair with minimum distance
threshold = find_threshold(model_name, distance_metric) threshold = threshold or find_threshold(model_name, distance_metric)
distance = float(min(distances)) # best distance distance = float(min(distances)) # best distance
facial_areas = facial_areas[np.argmin(distances)] facial_areas = facial_areas[np.argmin(distances)]