未验证 提交 25f116b3 编写于 作者: F Feng Wang 提交者: GitHub

fix(evaluator): fix attr bug in COCOEvaluator (#1067)

上级 147a8a35
......@@ -143,7 +143,7 @@ def main(exp, args, num_gpu):
logger.info("Model Structure:\n{}".format(str(model)))
evaluator = exp.get_evaluator(args.batch_size, is_distributed, args.test, args.legacy)
evaluator.per_class_mAP = True
evaluator.per_class_AP = True
evaluator.per_class_AR = True
torch.cuda.set_device(rank)
......
......@@ -50,8 +50,8 @@ def per_class_AR_table(coco_eval, class_names=COCO_CLASSES, headers=["class", "A
return table
def per_class_mAP_table(coco_eval, class_names=COCO_CLASSES, headers=["class", "AP"], colums=6):
per_class_mAP = {}
def per_class_AP_table(coco_eval, class_names=COCO_CLASSES, headers=["class", "AP"], colums=6):
per_class_AP = {}
precisions = coco_eval.eval["precision"]
# dimension of precisions: [TxRxKxAxM]
# precision has dims (iou, recall, cls, area range, max dets)
......@@ -63,10 +63,10 @@ def per_class_mAP_table(coco_eval, class_names=COCO_CLASSES, headers=["class", "
precision = precisions[:, :, idx, 0, -1]
precision = precision[precision > -1]
ap = np.mean(precision) if precision.size else float("nan")
per_class_mAP[name] = float(ap * 100)
per_class_AP[name] = float(ap * 100)
num_cols = min(colums, len(per_class_mAP) * len(headers))
result_pair = [x for pair in per_class_mAP.items() for x in pair]
num_cols = min(colums, len(per_class_AP) * len(headers))
result_pair = [x for pair in per_class_AP.items() for x in pair]
row_pair = itertools.zip_longest(*[result_pair[i::num_cols] for i in range(num_cols)])
table_headers = headers * (num_cols // len(headers))
table = tabulate(
......@@ -89,7 +89,7 @@ class COCOEvaluator:
nmsthre: float,
num_classes: int,
testdev: bool = False,
per_class_mAP: bool = False,
per_class_AP: bool = False,
per_class_AR: bool = False,
):
"""
......@@ -100,7 +100,8 @@ class COCOEvaluator:
confthre: confidence threshold ranging from 0 to 1, which
is defined in the config file.
nmsthre: IoU threshold of non-max supression ranging from 0 to 1.
per_class_mAP: Show per class mAP during evalution or not. Default to False.
per_class_AP: Show per class AP during evalution or not. Default to False.
per_class_AR: Show per class AR during evalution or not. Default to False.
"""
self.dataloader = dataloader
self.img_size = img_size
......@@ -108,7 +109,8 @@ class COCOEvaluator:
self.nmsthre = nmsthre
self.num_classes = num_classes
self.testdev = testdev
self.per_class_mAP = per_class_mAP
self.per_class_AP = per_class_AP
self.per_class_AR = per_class_AR
def evaluate(
self,
......@@ -278,8 +280,8 @@ class COCOEvaluator:
with contextlib.redirect_stdout(redirect_string):
cocoEval.summarize()
info += redirect_string.getvalue()
if self.per_class_mAP:
info += "per class mAP:\n" + per_class_mAP_table(cocoEval) + "\n"
if self.per_class_AP:
info += "per class AP:\n" + per_class_AP_table(cocoEval) + "\n"
if self.per_class_AR:
info += "per class AR:\n" + per_class_AR_table(cocoEval) + "\n"
return cocoEval.stats[0], cocoEval.stats[1], info
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册