mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 11:35:21 +00:00
Add test.
Add comments. Update color format for `__find_bulk_embeddings`.
This commit is contained in:
parent
41cabea7a6
commit
5d4146b248
@ -398,6 +398,7 @@ def __find_bulk_embeddings(
|
||||
enforce_detection=enforce_detection,
|
||||
align=align,
|
||||
expand_percentage=expand_percentage,
|
||||
color_face='bgr' # `represent` expects images in bgr format.
|
||||
)
|
||||
|
||||
except ValueError as err:
|
||||
|
@ -74,6 +74,7 @@ def represent(
|
||||
# we have run pre-process in verification. so, this can be skipped if it is coming from verify.
|
||||
target_size = model.input_shape
|
||||
if detector_backend != "skip":
|
||||
# Images are returned in RGB format.
|
||||
img_objs = detection.extract_faces(
|
||||
img_path=img_path,
|
||||
detector_backend=detector_backend,
|
||||
@ -87,13 +88,13 @@ def represent(
|
||||
else: # skip
|
||||
# Try load. If load error, will raise exception internal
|
||||
img, _ = image_utils.load_image(img_path)
|
||||
|
||||
# bgr to rgb
|
||||
img = img[:, :, ::-1]
|
||||
|
||||
|
||||
if len(img.shape) != 3:
|
||||
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`
|
||||
img_objs = [
|
||||
{
|
||||
|
@ -81,3 +81,23 @@ def test_max_faces():
|
||||
max_faces = 1
|
||||
results = DeepFace.represent(img_path="dataset/couple.jpg", max_faces=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
|
||||
|
Loading…
x
Reference in New Issue
Block a user