File size: 1,742 Bytes
3888132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 3rd party dependencies
import pytest
import numpy as np

# project dependencies
from deepface import DeepFace
from deepface.commons import logger as log

logger = log.get_singletonish_logger()


def test_enabled_enforce_detection_for_non_facial_input():
    black_img = np.zeros([224, 224, 3])

    with pytest.raises(ValueError):
        DeepFace.represent(img_path=black_img)

    with pytest.raises(ValueError):
        DeepFace.verify(img1_path=black_img, img2_path=black_img)

    logger.info("✅ enabled enforce detection with non facial input tests done")


def test_disabled_enforce_detection_for_non_facial_input_on_represent():
    black_img = np.zeros([224, 224, 3])
    objs = DeepFace.represent(img_path=black_img, enforce_detection=False)

    assert isinstance(objs, list)
    assert len(objs) > 0
    assert isinstance(objs[0], dict)
    assert "embedding" in objs[0].keys()
    assert "facial_area" in objs[0].keys()
    assert isinstance(objs[0]["facial_area"], dict)
    assert "x" in objs[0]["facial_area"].keys()
    assert "y" in objs[0]["facial_area"].keys()
    assert "w" in objs[0]["facial_area"].keys()
    assert "h" in objs[0]["facial_area"].keys()
    assert isinstance(objs[0]["embedding"], list)
    assert len(objs[0]["embedding"]) == 4096  # embedding of VGG-Face

    logger.info("✅ disabled enforce detection with non facial input test for represent tests done")


def test_disabled_enforce_detection_for_non_facial_input_on_verify():
    black_img = np.zeros([224, 224, 3])
    obj = DeepFace.verify(img1_path=black_img, img2_path=black_img, enforce_detection=False)
    assert isinstance(obj, dict)

    logger.info("✅ disabled enforce detection with non facial input test for verify tests done")