mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 03:55:21 +00:00
Merge pull request #1427 from dakotah-jones/patch-1
Update representation.py
This commit is contained in:
commit
8ed6b7c7c7
@ -398,6 +398,7 @@ def __find_bulk_embeddings(
|
|||||||
enforce_detection=enforce_detection,
|
enforce_detection=enforce_detection,
|
||||||
align=align,
|
align=align,
|
||||||
expand_percentage=expand_percentage,
|
expand_percentage=expand_percentage,
|
||||||
|
color_face='bgr' # `represent` expects images in bgr format.
|
||||||
)
|
)
|
||||||
|
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
|
@ -87,6 +87,7 @@ def represent(
|
|||||||
# we have run pre-process in verification. so, skip if it is coming from verify.
|
# we have run pre-process in verification. so, skip if it is coming from verify.
|
||||||
target_size = model.input_shape
|
target_size = model.input_shape
|
||||||
if detector_backend != "skip":
|
if detector_backend != "skip":
|
||||||
|
# Images are returned in RGB format.
|
||||||
img_objs = detection.extract_faces(
|
img_objs = detection.extract_faces(
|
||||||
img_path=single_img_path,
|
img_path=single_img_path,
|
||||||
detector_backend=detector_backend,
|
detector_backend=detector_backend,
|
||||||
@ -104,6 +105,9 @@ def represent(
|
|||||||
if len(img.shape) != 3:
|
if len(img.shape) != 3:
|
||||||
raise ValueError(f"Input img must be 3 dimensional but it is {img.shape}")
|
raise ValueError(f"Input img must be 3 dimensional but it is {img.shape}")
|
||||||
|
|
||||||
|
# Convert to RGB format to keep compatability with `extract_faces`.
|
||||||
|
img = img[:, :, ::-1]
|
||||||
|
|
||||||
# make dummy region and confidence to keep compatibility with `extract_faces`
|
# make dummy region and confidence to keep compatibility with `extract_faces`
|
||||||
img_objs = [
|
img_objs = [
|
||||||
{
|
{
|
||||||
@ -130,7 +134,7 @@ def represent(
|
|||||||
|
|
||||||
img = img_obj["face"]
|
img = img_obj["face"]
|
||||||
|
|
||||||
# bgr to rgb
|
# rgb to bgr
|
||||||
img = img[:, :, ::-1]
|
img = img[:, :, ::-1]
|
||||||
|
|
||||||
region = img_obj["facial_area"]
|
region = img_obj["facial_area"]
|
||||||
|
@ -111,6 +111,27 @@ def test_max_faces():
|
|||||||
assert len(results) == max_faces
|
assert len(results) == max_faces
|
||||||
|
|
||||||
|
|
||||||
|
def test_represent_detector_backend():
|
||||||
|
# Results using a detection backend.
|
||||||
|
results_1 = DeepFace.represent(img_path="dataset/img1.jpg")
|
||||||
|
assert len(results_1) == 1
|
||||||
|
|
||||||
|
# Results performing face extraction first.
|
||||||
|
faces = DeepFace.extract_faces(img_path="dataset/img1.jpg", color_face='bgr')
|
||||||
|
assert len(faces) == 1
|
||||||
|
|
||||||
|
# Images sent into represent need to be in BGR format.
|
||||||
|
img = faces[0]['face']
|
||||||
|
results_2 = DeepFace.represent(img_path=img, detector_backend="skip")
|
||||||
|
assert len(results_2) == 1
|
||||||
|
|
||||||
|
# The embeddings should be the exact same for both cases.
|
||||||
|
embedding_1 = results_1[0]['embedding']
|
||||||
|
embedding_2 = results_2[0]['embedding']
|
||||||
|
assert embedding_1 == embedding_2
|
||||||
|
logger.info("✅ test represent function for consistent output.")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"model_name",
|
"model_name",
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user