mirror of
https://github.com/serengil/deepface.git
synced 2025-06-07 12:05:22 +00:00
add a couple to test batch extract faces
This commit is contained in:
parent
60bee4e1a9
commit
f3d05ef2d5
@ -88,34 +88,40 @@ def test_batch_extract_faces(detector_backend):
|
|||||||
"dataset/img2.jpg",
|
"dataset/img2.jpg",
|
||||||
"dataset/img3.jpg",
|
"dataset/img3.jpg",
|
||||||
"dataset/img11.jpg",
|
"dataset/img11.jpg",
|
||||||
|
"dataset/couple.jpg"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Extract faces one by one
|
# Extract faces one by one
|
||||||
img_objs_individual = [
|
imgs_objs_individual = [
|
||||||
DeepFace.extract_faces(
|
DeepFace.extract_faces(
|
||||||
img_path=img_path,
|
img_path=img_path,
|
||||||
detector_backend=detector_backend,
|
detector_backend=detector_backend,
|
||||||
align=True,
|
align=True,
|
||||||
)[0] for img_path in img_paths
|
) for img_path in img_paths
|
||||||
]
|
]
|
||||||
|
|
||||||
# Extract faces in batch
|
# Extract faces in batch
|
||||||
img_objs_batch = DeepFace.extract_faces(
|
imgs_objs_batch = DeepFace.extract_faces(
|
||||||
img_path=img_paths,
|
img_path=img_paths,
|
||||||
detector_backend=detector_backend,
|
detector_backend=detector_backend,
|
||||||
align=True,
|
align=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
len(img_objs_batch) == 3 and
|
len(imgs_objs_batch) == 4 and
|
||||||
all(isinstance(obj, list) and len(obj) == 1 for obj in img_objs_batch)
|
all(isinstance(obj, list) for obj in imgs_objs_batch)
|
||||||
)
|
)
|
||||||
img_objs_batch = [obj for sublist in img_objs_batch for obj in sublist]
|
assert all(
|
||||||
|
len(imgs_objs_batch[i]) == 1
|
||||||
assert len(img_objs_batch) == len(img_objs_individual)
|
for i in range(len(imgs_objs_batch[:-1]))
|
||||||
|
)
|
||||||
|
assert len(imgs_objs_batch[-1]) == 2
|
||||||
|
|
||||||
|
for img_objs_individual, img_objs_batch in zip(imgs_objs_individual, imgs_objs_batch):
|
||||||
|
assert len(img_objs_batch) == len(img_objs_individual), (
|
||||||
|
"Batch and individual extraction results should have the same number of detected faces"
|
||||||
|
)
|
||||||
for img_obj_individual, img_obj_batch in zip(img_objs_individual, img_objs_batch):
|
for img_obj_individual, img_obj_batch in zip(img_objs_individual, img_objs_batch):
|
||||||
# assert np.array_equal(img_obj_individual["face"], img_obj_batch["face"])
|
|
||||||
for key in img_obj_individual["facial_area"]:
|
for key in img_obj_individual["facial_area"]:
|
||||||
if key == "left_eye" or key == "right_eye":
|
if key == "left_eye" or key == "right_eye":
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user