mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
adding max_faces argument to represent
This commit is contained in:
parent
7a5f24955a
commit
c66804717c
@ -359,6 +359,7 @@ def represent(
|
|||||||
expand_percentage: int = 0,
|
expand_percentage: int = 0,
|
||||||
normalization: str = "base",
|
normalization: str = "base",
|
||||||
anti_spoofing: bool = False,
|
anti_spoofing: bool = False,
|
||||||
|
max_faces: Optional[int] = None,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Represent facial images as multi-dimensional vector embeddings.
|
Represent facial images as multi-dimensional vector embeddings.
|
||||||
@ -390,6 +391,8 @@ def represent(
|
|||||||
|
|
||||||
anti_spoofing (boolean): Flag to enable anti spoofing (default is False).
|
anti_spoofing (boolean): Flag to enable anti spoofing (default is False).
|
||||||
|
|
||||||
|
max_faces (int): Set a limit on the number of faces to be processed (default is None).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
results (List[Dict[str, Any]]): A list of dictionaries, each containing the
|
results (List[Dict[str, Any]]): A list of dictionaries, each containing the
|
||||||
following fields:
|
following fields:
|
||||||
@ -415,6 +418,7 @@ def represent(
|
|||||||
expand_percentage=expand_percentage,
|
expand_percentage=expand_percentage,
|
||||||
normalization=normalization,
|
normalization=normalization,
|
||||||
anti_spoofing=anti_spoofing,
|
anti_spoofing=anti_spoofing,
|
||||||
|
max_faces=max_faces,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -483,7 +487,7 @@ def extract_faces(
|
|||||||
align: bool = True,
|
align: bool = True,
|
||||||
expand_percentage: int = 0,
|
expand_percentage: int = 0,
|
||||||
grayscale: bool = False,
|
grayscale: bool = False,
|
||||||
color_face: str = 'rgb',
|
color_face: str = "rgb",
|
||||||
normalize_face: bool = True,
|
normalize_face: bool = True,
|
||||||
anti_spoofing: bool = False,
|
anti_spoofing: bool = False,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
|
@ -31,6 +31,7 @@ def represent():
|
|||||||
enforce_detection=input_args.get("enforce_detection", True),
|
enforce_detection=input_args.get("enforce_detection", True),
|
||||||
align=input_args.get("align", True),
|
align=input_args.get("align", True),
|
||||||
anti_spoofing=input_args.get("anti_spoofing", False),
|
anti_spoofing=input_args.get("anti_spoofing", False),
|
||||||
|
max_faces=input_args.get("max_faces"),
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug(obj)
|
logger.debug(obj)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# built-in dependencies
|
# built-in dependencies
|
||||||
import traceback
|
import traceback
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
# project dependencies
|
# project dependencies
|
||||||
from deepface import DeepFace
|
from deepface import DeepFace
|
||||||
@ -14,6 +15,7 @@ def represent(
|
|||||||
enforce_detection: bool,
|
enforce_detection: bool,
|
||||||
align: bool,
|
align: bool,
|
||||||
anti_spoofing: bool,
|
anti_spoofing: bool,
|
||||||
|
max_faces: Optional[int] = None,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
result = {}
|
result = {}
|
||||||
@ -24,6 +26,7 @@ def represent(
|
|||||||
enforce_detection=enforce_detection,
|
enforce_detection=enforce_detection,
|
||||||
align=align,
|
align=align,
|
||||||
anti_spoofing=anti_spoofing,
|
anti_spoofing=anti_spoofing,
|
||||||
|
max_faces=max_faces,
|
||||||
)
|
)
|
||||||
result["results"] = embedding_objs
|
result["results"] = embedding_objs
|
||||||
return result
|
return result
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# built-in dependencies
|
# built-in dependencies
|
||||||
from typing import Any, Dict, List, Union
|
from typing import Any, Dict, List, Union, Optional
|
||||||
|
|
||||||
# 3rd party dependencies
|
# 3rd party dependencies
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -19,6 +19,7 @@ def represent(
|
|||||||
expand_percentage: int = 0,
|
expand_percentage: int = 0,
|
||||||
normalization: str = "base",
|
normalization: str = "base",
|
||||||
anti_spoofing: bool = False,
|
anti_spoofing: bool = False,
|
||||||
|
max_faces: Optional[int] = None,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Represent facial images as multi-dimensional vector embeddings.
|
Represent facial images as multi-dimensional vector embeddings.
|
||||||
@ -46,6 +47,8 @@ def represent(
|
|||||||
|
|
||||||
anti_spoofing (boolean): Flag to enable anti spoofing (default is False).
|
anti_spoofing (boolean): Flag to enable anti spoofing (default is False).
|
||||||
|
|
||||||
|
max_faces (int): Set a limit on the number of faces to be processed (default is None).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
results (List[Dict[str, Any]]): A list of dictionaries, each containing the
|
results (List[Dict[str, Any]]): A list of dictionaries, each containing the
|
||||||
following fields:
|
following fields:
|
||||||
@ -94,7 +97,7 @@ def represent(
|
|||||||
]
|
]
|
||||||
# ---------------------------------
|
# ---------------------------------
|
||||||
|
|
||||||
for img_obj in img_objs:
|
for idx, img_obj in enumerate(img_objs):
|
||||||
if anti_spoofing is True and img_obj.get("is_real", True) is False:
|
if anti_spoofing is True and img_obj.get("is_real", True) is False:
|
||||||
raise ValueError("Spoof detected in the given image.")
|
raise ValueError("Spoof detected in the given image.")
|
||||||
img = img_obj["face"]
|
img = img_obj["face"]
|
||||||
@ -117,10 +120,15 @@ def represent(
|
|||||||
|
|
||||||
embedding = model.forward(img)
|
embedding = model.forward(img)
|
||||||
|
|
||||||
resp_obj = {}
|
resp_objs.append(
|
||||||
resp_obj["embedding"] = embedding
|
{
|
||||||
resp_obj["facial_area"] = region
|
"embedding": embedding,
|
||||||
resp_obj["face_confidence"] = confidence
|
"facial_area": region,
|
||||||
resp_objs.append(resp_obj)
|
"face_confidence": confidence,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if max_faces is not None and max_faces > 0 and max_faces > idx + 1:
|
||||||
|
break
|
||||||
|
|
||||||
return resp_objs
|
return resp_objs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user