-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from serengil/feat-task-0201-align-first
initial commit
- Loading branch information
Showing
6 changed files
with
139 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import numpy as np | ||
from retinaface import RetinaFace | ||
from retinaface.commons.logger import Logger | ||
|
||
logger = Logger("tests/test_actions.py") | ||
|
||
THRESHOLD = 1000 | ||
|
||
|
||
def test_detect_first(): | ||
""" | ||
Test the default behavior. Detect first and align second causes | ||
so many black pixels | ||
""" | ||
faces = RetinaFace.extract_faces(img_path="tests/dataset/img11.jpg") | ||
num_black_pixels = np.sum(np.all(faces[0] == 0, axis=2)) | ||
assert num_black_pixels > THRESHOLD | ||
logger.info("✅ Disabled align_first test for single face photo done") | ||
|
||
|
||
def test_align_first(): | ||
""" | ||
Test align first behavior. Align first and detect second do not cause | ||
so many black pixels in contrast to default behavior | ||
""" | ||
faces = RetinaFace.extract_faces(img_path="tests/dataset/img11.jpg", align_first=True) | ||
num_black_pixels = np.sum(np.all(faces[0] == 0, axis=2)) | ||
assert num_black_pixels < THRESHOLD | ||
logger.info("✅ Enabled align_first test for single face photo done") | ||
|
||
|
||
def test_align_first_for_group_photo(): | ||
""" | ||
Align first will not work if the given image has many faces and | ||
it will cause so many black pixels | ||
""" | ||
faces = RetinaFace.extract_faces(img_path="tests/dataset/couple.jpg", align_first=True) | ||
for face in faces: | ||
num_black_pixels = np.sum(np.all(face == 0, axis=2)) | ||
assert num_black_pixels > THRESHOLD | ||
|
||
logger.info("✅ Enabled align_first test for group photo done") | ||
|
||
|
||
def test_default_behavior_for_group_photo(): | ||
""" | ||
Align first will not work in the default behaviour and | ||
it will cause so many black pixels | ||
""" | ||
faces = RetinaFace.extract_faces(img_path="tests/dataset/couple.jpg") | ||
for face in faces: | ||
num_black_pixels = np.sum(np.all(face == 0, axis=2)) | ||
assert num_black_pixels > THRESHOLD | ||
|
||
logger.info("✅ Disabled align_first test for group photo done") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import cv2 | ||
from retinaface import RetinaFace | ||
from retinaface.commons import postprocess | ||
from retinaface.commons.logger import Logger | ||
|
||
logger = Logger("tests/test_expand_face_area.py") | ||
|
||
|
||
def test_expand_face_area(): | ||
img_path = "tests/dataset/img11.jpg" | ||
default_faces = RetinaFace.extract_faces(img_path=img_path, expand_face_area=10) | ||
|
||
img1 = default_faces[0] | ||
img1 = cv2.resize(img1, (500, 500)) | ||
|
||
obj1 = RetinaFace.detect_faces(img1, threshold=0.1) | ||
|
||
expanded_faces = RetinaFace.extract_faces(img_path=img_path, expand_face_area=50) | ||
|
||
img2 = expanded_faces[0] | ||
img2 = cv2.resize(img2, (500, 500)) | ||
|
||
obj2 = RetinaFace.detect_faces(img2, threshold=0.1) | ||
|
||
landmarks1 = obj1["face_1"]["landmarks"] | ||
landmarks2 = obj2["face_1"]["landmarks"] | ||
|
||
distance1 = postprocess.findEuclideanDistance(landmarks1["right_eye"], landmarks1["left_eye"]) | ||
distance2 = postprocess.findEuclideanDistance(landmarks2["right_eye"], landmarks2["left_eye"]) | ||
|
||
# 2nd one's expand ratio is higher. so, it should be smaller. | ||
assert distance2 < distance1 | ||
|
||
logger.info("✅ Test expand face area is done") |