Closed jl749 closed 1 year ago
from torchmetrics.detection.mean_ap import MeanAveragePrecision
metric = MeanAveragePrecision()
for p, t in zip(pred_boxes, true_boxes):
p = [{
"labels": p[:, 0].ravel(),
"scores": p[:, 1].ravel(),
"boxes": p[:, 2:]
}]
t = t.cuda()
t = [{
"boxes": t[:, 0:4],
"labels": t[:, 4]
}]
metric.update(p, t)
# preds = []
# targets = []
# for p in pred_boxes:
# preds.append({
# "labels": p[:, 0].ravel(),
# "scores": p[:, 1].ravel(),
# "boxes": p[:, 2:]
# })
# for t in true_boxes:
# t = t.cuda()
# targets.append({
# "boxes": t[:, 0:4],
# "labels": t[:, 4]
# })
# metric.update(preds, targets)
TM_result = metric.compute()
print(TM_result)
https://github.com/jl749/YOLOv3/blob/496563b75f0f59a15a627a3eb9e44ad119c031dd/yolov3/utils/metric.py#L66-L128
line 91
labels
should be filtered by class too