Definition of the metrics that can be used to evaluate models
First we create some predictions and targets. Note that our dataloader contains a background class with index 0 and all metrics remove by default the background class, so the first class has index 1 and the number of classes is 2.
num_classes = 2
boxes = torch.tensor([
[439, 157, 556, 241],
[437, 246, 518, 351],
[515, 306, 595, 375],
[407, 386, 531, 476],
[544, 419, 621, 476],
[609, 297, 636, 392]])
labels = torch.ones(6, dtype=torch.long)
targs = [dict({"boxes":boxes, "labels":labels})]
targs
boxes = torch.tensor([
[429, 219, 528, 247],
[433, 260, 506, 336],
[518, 314, 603, 369],
[592, 310, 634, 388],
[403, 384, 517, 461],
[405, 429, 519, 470],
[433, 272, 499, 341],
[413, 390, 515, 459]])
labels = torch.ones(8, dtype=torch.long)
scores = torch.tensor([0.460851, 0.269833, 0.462608, 0.298196, 0.382881, 0.369369, 0.272826, 0.619459])
preds = [dict({"boxes":boxes, "labels":labels, "scores":scores})]
preds
voc_pascal = create_mAP_metric(0.5, np.arange(0., 1.1, 0.1), "greedy", "VOC PASCAL mAP",
remove_background_class=True)
voc_pascal.func(preds, targs, num_classes=num_classes)
voc_pascal_all_pnts = create_mAP_metric(0.5, None, "greedy", "VOC PASCAL mAP all points",
remove_background_class=True)
voc_pascal_all_pnts.func(preds, targs, num_classes=num_classes)
coco_map_50 = create_mAP_metric(0.5, np.arange(0., 1.01, 0.01), "soft", "COCO mAP@0.5",
remove_background_class=True)
coco_map_50.func(preds, targs, num_classes=num_classes)
coco_map_50_95 = create_mAP_metric(np.arange(0.5, 1, .05), np.arange(0., 1.01, 0.01), "soft", "COCO mAP@[0.5:0.95]",
remove_background_class=True)
coco_map_50_95.func(preds, targs, num_classes=num_classes)
test_close(voc_pascal.func(preds, targs, num_classes=2), 0.5, eps=1e-03)
test_close(voc_pascal_all_pnts.func(preds, targs, num_classes=2), 0.5, eps=1e-03)
test_close(coco_map_50.func(preds, targs, num_classes=2), 0.5, eps=1e-03)
test_close(coco_map_50_95.func(preds, targs, num_classes=2), 0.157, eps=1e-03)
There are some prebuilt metrics, which you can use instantly:
COCO mAP:
mAP_at_IoU40
mAP_at_IoU50
mAP_at_IoU60
mAP_at_IoU70
mAP_at_IoU80
mAP_at_IoU90
mAP_at_IoU50_95
(mAP@[0.50:0.95:0.05])