Skip to content

Commit

Permalink
Merge pull request #1223 from GobinathAL/threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
serengil authored Apr 30, 2024
2 parents 42b45cc + b864f6a commit 04baf3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions deepface/DeepFace.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def verify(
expand_percentage: int = 0,
normalization: str = "base",
silent: bool = False,
threshold: Optional[float] = None,
) -> Dict[str, Any]:
"""
Verify if an image pair represents the same person or different persons.
Expand Down Expand Up @@ -107,6 +108,11 @@ def verify(
silent (boolean): Suppress or allow some log messages for a quieter analysis process
(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:
result (dict): A dictionary containing verification results with following keys.
Expand Down Expand Up @@ -143,6 +149,7 @@ def verify(
expand_percentage=expand_percentage,
normalization=normalization,
silent=silent,
threshold=threshold,
)


Expand Down
10 changes: 8 additions & 2 deletions deepface/modules/verification.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# built-in dependencies
import time
from typing import Any, Dict, Union, List, Tuple
from typing import Any, Dict, Optional, Union, List, Tuple

# 3rd party dependencies
import numpy as np
Expand All @@ -24,6 +24,7 @@ def verify(
expand_percentage: int = 0,
normalization: str = "base",
silent: bool = False,
threshold: Optional[float] = None,
) -> Dict[str, Any]:
"""
Verify if an image pair represents the same person or different persons.
Expand Down Expand Up @@ -63,6 +64,11 @@ def verify(
silent (boolean): Suppress or allow some log messages for a quieter analysis process
(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:
result (dict): A dictionary containing verification results.
Expand Down Expand Up @@ -186,7 +192,7 @@ def verify(
)

# 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
facial_areas = facial_areas[np.argmin(distances)]

Expand Down

0 comments on commit 04baf3e

Please sign in to comment.