jl749 / YOLOv3

yolov3 implementation in pytorch (https://arxiv.org/pdf/1804.02767.pdf)
0 stars 0 forks source link

FIX mAP calculation bug #6

Closed jl749 closed 1 year ago

jl749 commented 1 year ago

https://github.com/jl749/YOLOv3/blob/496563b75f0f59a15a627a3eb9e44ad119c031dd/yolov3/utils/metric.py#L66-L128

line 91 labels should be filtered by class too

jl749 commented 1 year ago

torchmetric mAP

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)