Skip to content

Commit 2173bd8

Browse files
committed
test: add simple unit test for metrics (#137)
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent 42f66b2 commit 2173bd8

5 files changed

Lines changed: 102 additions & 2 deletions

File tree

t4_devkit/evaluation/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from .result import * # noqa
44
from .matching import * # noqa
55
from .result import * # noqa
6+
from .metric import * # noqa

t4_devkit/evaluation/metric/ap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def _update_buffer(self, frames: list[FrameBoxMatch]) -> ApBuffer:
9393

9494

9595
class ApH(Ap):
96-
def __init__(self, threshold: float) -> None:
97-
super().__init__(threshold=threshold)
96+
def __init__(self, scorer: MatchingScorerLike, threshold: float) -> None:
97+
super().__init__(scorer=scorer, threshold=threshold)
9898

9999
def _compute_tp(self, box_match: BoxMatch) -> float:
100100
if not box_match.is_matched():

t4_devkit/evaluation/metric/clear.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def _update_buffer(self, frames: list[FrameBoxMatch]) -> ClearBuffer:
8888
buffer.num_id_switch += 1
8989
else:
9090
buffer.num_fp += 1
91+
return buffer
9192

9293
def _is_id_switched(self, current_match: BoxMatch, previous_match: BoxMatch) -> bool:
9394
if (not current_match.is_matched()) and (not previous_match.is_matched()):

tests/evaluation/metric/test_ap.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from __future__ import annotations
2+
3+
import math
4+
5+
import pytest
6+
7+
from t4_devkit.dataclass import HomogeneousMatrix
8+
from t4_devkit.evaluation import (
9+
Ap,
10+
ApH,
11+
CenterDistance,
12+
FrameBoxMatch,
13+
MatchingParams,
14+
build_matcher,
15+
)
16+
17+
18+
@pytest.fixture(scope="module")
19+
def dummy_frame3d(dummy_evaluation_box3ds) -> FrameBoxMatch:
20+
estimations, ground_truths = dummy_evaluation_box3ds
21+
22+
matcher = build_matcher(params=MatchingParams())
23+
24+
matches = matcher(estimations, ground_truths)
25+
26+
ego2map = HomogeneousMatrix(
27+
position=(1, 0, 0),
28+
rotation=(1, 0, 0, 0),
29+
src="base_link",
30+
dst="map",
31+
)
32+
33+
return FrameBoxMatch(unix_time=100, frame_index=0, matches=matches, ego2map=ego2map)
34+
35+
36+
def test_ap(dummy_frame3d) -> None:
37+
ap = Ap(scorer=CenterDistance(), threshold=1.0)
38+
39+
score = ap(frames=[dummy_frame3d])
40+
41+
assert math.isclose(score, 0.394, rel_tol=1e-3)
42+
43+
44+
def test_aph(dummy_frame3d) -> None:
45+
aph = ApH(scorer=CenterDistance(), threshold=1.0)
46+
47+
score = aph(frames=[dummy_frame3d])
48+
49+
assert math.isclose(score, 0.394, rel_tol=1e-3)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from __future__ import annotations
2+
3+
import math
4+
5+
import pytest
6+
7+
from t4_devkit.dataclass import HomogeneousMatrix
8+
from t4_devkit.evaluation import (
9+
CenterDistance,
10+
FrameBoxMatch,
11+
MatchingParams,
12+
Mota,
13+
Motp,
14+
build_matcher,
15+
)
16+
17+
18+
@pytest.fixture(scope="module")
19+
def dummy_frame3d(dummy_evaluation_box3ds) -> FrameBoxMatch:
20+
estimations, ground_truths = dummy_evaluation_box3ds
21+
22+
matcher = build_matcher(params=MatchingParams())
23+
24+
matches = matcher(estimations, ground_truths)
25+
26+
ego2map = HomogeneousMatrix(
27+
position=(1, 0, 0),
28+
rotation=(1, 0, 0, 0),
29+
src="base_link",
30+
dst="map",
31+
)
32+
33+
return FrameBoxMatch(unix_time=100, frame_index=0, matches=matches, ego2map=ego2map)
34+
35+
36+
def test_ap(dummy_frame3d) -> None:
37+
mota = Mota(scorer=CenterDistance(), threshold=1.0)
38+
39+
score = mota(frames=[dummy_frame3d])
40+
41+
assert math.isclose(score, 0.0)
42+
43+
44+
def test_aph(dummy_frame3d) -> None:
45+
motp = Motp(scorer=CenterDistance(), threshold=1.0)
46+
47+
score = motp(frames=[dummy_frame3d])
48+
49+
assert math.isclose(score, 0.0)

0 commit comments

Comments
 (0)