Skip to content

Commit

Permalink
Switch to sample_video_2.mp4 for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
prouast committed Jun 13, 2024
1 parent 2e45e1c commit db5840e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
Binary file modified examples/sample_video_2.mp4
Binary file not shown.
Binary file removed examples/test.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies = [
"importlib_resources",
"numpy",
"onnxruntime",
"prpy[ffmpeg,numpy_min]>=0.2.4",
"prpy[ffmpeg,numpy_min]>=0.2.7",
"pyyaml",
"requests",
]
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

from vitallens.ssd import FaceDetector

# TODO: Select a better test video
TEST_VIDEO_PATH = "examples/test.mp4"
TEST_VIDEO_PATH = "examples/sample_video_2.mp4"

@pytest.fixture(scope='session')
def test_video_path():
Expand Down
24 changes: 12 additions & 12 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def test_VitalLens(request, method, detect_faces, file):
vl = VitalLens(method=method, detect_faces=detect_faces)
if file:
test_video_path = request.getfixturevalue('test_video_path')
result = vl(test_video_path, faces = None if detect_faces else [425, 116, 671, 433])
result = vl(test_video_path, faces = None if detect_faces else [247, 57, 440, 334])
else:
test_video_ndarray = request.getfixturevalue('test_video_ndarray')
test_video_fps = request.getfixturevalue('test_video_fps')
result = vl(test_video_ndarray, fps=test_video_fps, faces = None if detect_faces else [425, 116, 671, 433])
result = vl(test_video_ndarray, fps=test_video_fps, faces = None if detect_faces else [247, 57, 440, 334])
assert len(result) == 1
assert result[0]['face'].shape == (139, 4)
assert result[0]['pulse']['val'].shape == (139,)
np.testing.assert_allclose(result[0]['hr']['val'], 71.5, atol=2)
assert result[0]['face'].shape == (360, 4)
assert result[0]['pulse']['val'].shape == (360,)
np.testing.assert_allclose(result[0]['hr']['val'], 60, atol=10)

def test_VitalLens_API(request):
api_key = request.getfixturevalue('test_dev_api_key')
Expand All @@ -50,10 +50,10 @@ def test_VitalLens_API(request):
test_video_fps = request.getfixturevalue('test_video_fps')
result = vl(test_video_ndarray, fps=test_video_fps, faces=None)
assert len(result) == 1
assert result[0]['face'].shape == (139, 4)
assert result[0]['pulse']['val'].shape == (139,)
assert result[0]['pulse']['conf'].shape == (139,)
assert result[0]['resp']['val'].shape == (139,)
assert result[0]['resp']['conf'].shape == (139,)
np.testing.assert_allclose(result[0]['hr']['val'], 73, atol=0.5)
np.testing.assert_allclose(result[0]['rr']['val'], 15, atol=0.5)
assert result[0]['face'].shape == (360, 4)
assert result[0]['pulse']['val'].shape == (360,)
assert result[0]['pulse']['conf'].shape == (360,)
assert result[0]['resp']['val'].shape == (360,)
assert result[0]['resp']['conf'].shape == (360,)
np.testing.assert_allclose(result[0]['hr']['val'], 60, atol=0.5)
np.testing.assert_allclose(result[0]['rr']['val'], 13.5, atol=0.5)
6 changes: 3 additions & 3 deletions tests/test_ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def test_FaceDetector(request, file):
test_video_ndarray = request.getfixturevalue('test_video_ndarray')
test_video_fps = request.getfixturevalue('test_video_fps')
boxes, info = det(test_video_ndarray, fps=test_video_fps)
assert boxes.shape == (139, 1, 4)
assert info.shape == (139, 1, 5)
assert boxes.shape == (360, 1, 4)
assert info.shape == (360, 1, 5)
np.testing.assert_allclose(boxes[0,0],
[0.39557341, 0.16045742, 0.62178493, 0.60086358],
[0.32223, 0.118318, 0.572684, 0.696835],
atol=0.01)

16 changes: 8 additions & 8 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_probe_video_inputs(request, file):
test_video_ndarray = request.getfixturevalue('test_video_ndarray')
test_video_fps = request.getfixturevalue('test_video_fps')
video_shape, fps = probe_video_inputs(test_video_ndarray, fps=test_video_fps)
assert video_shape == (139, 720, 1080, 3)
assert fps == 30.
assert video_shape == (360, 480, 768, 3)
assert fps == 30

def test_probe_video_inputs_no_file():
with pytest.raises(Exception):
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_probe_video_inputs_wrong_type():
_ = probe_video_inputs(12345, fps=30.)

@pytest.mark.parametrize("file", [True, False])
@pytest.mark.parametrize("roi", [None, (0, 100, 500, 600)])
@pytest.mark.parametrize("roi", [None, (200, 0, 500, 350)])
@pytest.mark.parametrize("target_size", [None, 200])
@pytest.mark.parametrize("target_fps", [None, 15])
def test_parse_video_inputs(request, file, roi, target_size, target_fps):
Expand All @@ -98,12 +98,12 @@ def test_parse_video_inputs(request, file, roi, target_size, target_fps):
parsed, fps_in, video_shape_in, ds_factor = parse_video_inputs(
test_video_ndarray, fps=test_video_fps, roi=roi, target_size=target_size,
target_fps=target_fps)
assert parsed.shape == (139 if target_fps is None else 139 // 2 + 1,
200 if target_size is not None else (500 if roi is not None else 720),
200 if target_size is not None else (500 if roi is not None else 1080),
assert parsed.shape == (360 if target_fps is None else 360 // 2,
200 if target_size is not None else (350 if roi is not None else 480),
200 if target_size is not None else (300 if roi is not None else 768),
3)
assert fps_in == 30.
assert video_shape_in == (139, 720, 1080, 3)
assert fps_in == 30
assert video_shape_in == (360, 480, 768, 3)
assert ds_factor == 1 if target_fps is None else 2

def test_parse_video_inputs_no_file():
Expand Down

0 comments on commit db5840e

Please sign in to comment.