INNER CODE UNIT · Python
log_iou
castorini/daam · daam/evaluate.py:52
def log_iou(self, preds: Union[torch.Tensor, List[torch.Tensor]], truth: torch.Tensor, gt_idx: int = 0, pred_idx: int = 0):
if not isinstance(preds, list):
preds = [preds]
iou = max(compute_iou(pred, truth) for pred in preds)
self.ious[gt_idx].append((pred_idx, iou))
@property
def mean_iou(self) -> float:
n = max(max(self.ious), max([y[0] for x in self.ious.values() for y in x])) + 1
iou_matrix = np.zeros((n, n))
count_matrix = np.zeros((n, n))
for gt_idx, ious in self.ious.items():
for pred_idx, iou in ious:
iou_matrix[gt_idx, pred_idx] += iou
count_matrix[gt_idx, pred_idx] += 1