Пример #1
0
def test__given_diff_face_images__when_scanned__then_returns_diff_embeddings(
        scanner_cls):
    scanner: FaceScanner = scanner_cls()
    img1 = read_img(IMG_DIR / PERSON_B.img_names[0])
    img2 = read_img(IMG_DIR / PERSON_C.img_names[0])

    emb1 = first_and_only(scanner.scan(img1)).embedding
    emb2 = first_and_only(scanner.scan(img2)).embedding

    assert not embeddings_are_equal(emb1, emb2, scanner.difference_threshold)
Пример #2
0
def test__given_img__when_scanned__then_1_to_1_relationship_between_all_returned_boxes_and_faces(scanner_cls, row):
    scanner: FaceScanner = scanner_cls()
    img = read_img(IMG_DIR / row.img_name)

    scanned_faces = scanner.scan(img)

    assert calculate_errors(boxes=[face.box for face in scanned_faces], noses=row.noses) == 0
Пример #3
0
def test__given_threshold_set_to_1__when_scanned__then_returns_no_faces(scanner_cls):
    scanner: FaceScanner = scanner_cls()
    img = read_img(IMG_DIR / '000_5.jpg')

    result = scanner.scan(img, det_prob_threshold=1)

    assert len(result) == 0
Пример #4
0
def test__given_no_faces_img__when_scanned__then_returns_no_faces(scanner_cls):
    scanner: FaceScanner = scanner_cls()
    img = read_img(IMG_DIR / '017_0.jpg')

    result = scanner.scan(img)

    assert len(result) == 0
Пример #5
0
def test_landmarks(plugin: mixins.LandmarksDetectorMixin, row):
    img = read_img(IMG_DIR / row.img_name)

    faces = plugin_manager.detector(img=img, face_plugins=[plugin])
    sorted_faces = sorted(faces, key=lambda x: x._plugins_dto[0].nose)

    for face, excepted_nose in zip(sorted_faces, sorted(row.noses)):
        landmarks = face._plugins_dto[0]
        tolerance = face.box.height * 0.07
        assert euclidean(landmarks.nose, excepted_nose) < tolerance
Пример #6
0
def test__given_5face_img__when_scanned__then_returns_5_correct_bounding_boxes_sorted_by_probability(scanner_cls):
    correct_boxes = [BoundingBoxDTO(544, 222, 661, 361, 1),
                     BoundingBoxDTO(421, 236, 530, 369, 1),
                     BoundingBoxDTO(161, 36, 266, 160, 1),
                     BoundingBoxDTO(342, 160, 437, 268, 1),
                     BoundingBoxDTO(243, 174, 352, 309, 1)]
    scanner: FaceScanner = scanner_cls()
    img = read_img(IMG_DIR / '000_5.jpg')

    faces = scanner.scan(img)

    for face in faces:
        assert face.box.similar_to_any(correct_boxes, tolerance=20)
    assert is_sorted([face.box.probability for face in faces])
Пример #7
0
def test_getting_age_and_gender(img_name: str):

    img = read_img(IMG_DIR / img_name)
    person = annotations.name_2_person[img_name]
    face = plugin_manager.detector(img)[0]

    if age_detector:
        age_range = age_detector(face).age
        assert age_range[0] <= person.age <= age_range[1], \
            f'{img_name}: Age mismatched: {person.age} not in  {age_range}'

    if gender_detector:
        gender = gender_detector(face).gender
        assert gender is not None
        assert (gender == 'male') == person.is_male, \
            f'{img_name}: Wrong gender - {gender}'
Пример #8
0
def test__size_of_embeddings(scanner_cls):
    scanner: FaceScanner = scanner_cls()
    img = read_img(IMG_DIR / PERSON_B.img_names[0])
    emb = first_and_only(scanner.scan(img)).embedding
    assert len(emb) == 512