Skip to content

Commit cea0e40

Browse files
authored
refactor: update metrics logic (#260)
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent dee647b commit cea0e40

3 files changed

Lines changed: 69 additions & 58 deletions

File tree

t4_devkit/evaluation/dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def load_dataset(data_root: str, task: EvaluationTask) -> SceneGroundTruth:
4444
# TODO(ktro2828): add support of segmentation object
4545
raise NotImplementedError("Segmentation task is under construction.")
4646
else:
47+
# TODO(ktro2828): add support of prediction future
4748
annotations = (
4849
list(map(t4.get_box3d, sample.ann_3ds))
4950
if task.is_3d()

t4_devkit/evaluation/metric/ap.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,33 @@ def __call__(self, frames: list[FrameBoxMatch]) -> float:
6969
buffer = self._update_buffer(frames)
7070
return buffer.compute_ap()
7171

72-
def _compute_tp(self, _box_match: BoxMatch) -> float:
72+
def _compute_tp(self, box_match: BoxMatch) -> float:
7373
return 1.0
7474

7575
def _update_buffer(self, frames: list[FrameBoxMatch]) -> ApBuffer:
7676
buffer = self.ApBuffer()
7777
for frame in frames:
78-
buffer.num_gt += frame.num_gt
79-
for box_match in frame.matches:
80-
if box_match.estimation is None:
81-
continue
82-
83-
buffer.confidences.append(box_match.estimation.confidence)
84-
if box_match.is_tp(
85-
scorer=self.scorer,
86-
threshold=self.threshold,
87-
ego2map=frame.ego2map,
88-
):
89-
buffer.tp_list.append(self._compute_tp(box_match))
90-
buffer.fp_list.append(0.0)
91-
else:
92-
buffer.tp_list.append(0.0)
93-
buffer.fp_list.append(1.0)
78+
self._update_buffer_frame(frame, buffer)
9479
return buffer
9580

81+
def _update_buffer_frame(self, frame: FrameBoxMatch, buffer: ApBuffer) -> None:
82+
buffer.num_gt += frame.num_gt
83+
for box_match in frame.matches:
84+
if box_match.estimation is None:
85+
continue
86+
87+
buffer.confidences.append(box_match.estimation.confidence)
88+
if box_match.is_tp(
89+
scorer=self.scorer,
90+
threshold=self.threshold,
91+
ego2map=frame.ego2map,
92+
):
93+
buffer.tp_list.append(self._compute_tp(box_match))
94+
buffer.fp_list.append(0.0)
95+
else:
96+
buffer.tp_list.append(0.0)
97+
buffer.fp_list.append(1.0)
98+
9699

97100
class ApH(Ap):
98101
def __init__(self, scorer: MatchingScorerLike, threshold: float) -> None:

t4_devkit/evaluation/metric/clear.py

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,52 +45,59 @@ def _update_buffer(self, frames: list[FrameBoxMatch]) -> ClearBuffer:
4545
for i in range(1, num_frame):
4646
current_frame = frames[i]
4747
previous_frame = frames[i - 1]
48+
self._update_buffer_frame(current_frame, previous_frame, buffer)
49+
return buffer
4850

49-
buffer.num_gt += current_frame.num_gt
50-
for current_match in current_frame.matches:
51-
is_id_switch = False
52-
is_same_match = False
53-
for previous_match in previous_frame.matches:
54-
if not previous_match.is_tp(
55-
self.scorer,
56-
self.threshold,
57-
previous_frame.ego2map,
58-
):
59-
continue
60-
61-
is_id_switch = self._is_id_switched(current_match, previous_match)
62-
if is_id_switch:
63-
break
64-
65-
is_same_match = self._is_same_match()
66-
if is_same_match:
67-
buffer.num_tp += current_match.is_tp(
68-
scorer=self.scorer,
69-
threshold=self.threshold,
70-
ego2map=current_frame.ego2map,
71-
)
72-
buffer.score += self.scorer(
73-
previous_match.estimation,
74-
previous_match.ground_truth,
75-
ego2map=previous_frame.ego2map,
76-
)
77-
break
78-
79-
if is_same_match:
51+
def _update_buffer_frame(
52+
self,
53+
current_frame: FrameBoxMatch,
54+
previous_frame: FrameBoxMatch,
55+
buffer: ClearBuffer,
56+
) -> None:
57+
buffer.num_gt += current_frame.num_gt
58+
for current_match in current_frame.matches:
59+
is_id_switch = False
60+
is_same_match = False
61+
for previous_match in previous_frame.matches:
62+
if not previous_match.is_tp(
63+
self.scorer,
64+
self.threshold,
65+
previous_frame.ego2map,
66+
):
8067
continue
8168

82-
if current_match.is_tp(self.scorer, self.threshold, current_frame.ego2map):
83-
buffer.num_tp += 1
69+
is_id_switch = self._is_id_switched(current_match, previous_match)
70+
if is_id_switch:
71+
break
72+
73+
is_same_match = self._is_same_match(current_match, previous_match)
74+
if is_same_match:
75+
buffer.num_tp += current_match.is_tp(
76+
scorer=self.scorer,
77+
threshold=self.threshold,
78+
ego2map=current_frame.ego2map,
79+
)
8480
buffer.score += self.scorer(
85-
current_match.estimation,
86-
current_match.ground_truth,
87-
current_frame.ego2map,
81+
previous_match.estimation,
82+
previous_match.ground_truth,
83+
ego2map=previous_frame.ego2map,
8884
)
89-
if is_id_switch:
90-
buffer.num_id_switch += 1
91-
else:
92-
buffer.num_fp += 1
93-
return buffer
85+
break
86+
87+
if is_same_match:
88+
continue
89+
90+
if current_match.is_tp(self.scorer, self.threshold, current_frame.ego2map):
91+
buffer.num_tp += 1
92+
buffer.score += self.scorer(
93+
current_match.estimation,
94+
current_match.ground_truth,
95+
current_frame.ego2map,
96+
)
97+
if is_id_switch:
98+
buffer.num_id_switch += 1
99+
else:
100+
buffer.num_fp += 1
94101

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

0 commit comments

Comments
 (0)