|
|
@ -343,7 +343,7 @@ def compute_ap(recall, precision):
|
|
|
|
return ap, mpre, mrec
|
|
|
|
return ap, mpre, mrec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, save_dir='.', names=(), eps=1e-16, prefix=""):
|
|
|
|
def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, save_dir=Path(), names=(), eps=1e-16, prefix=""):
|
|
|
|
""" Compute the average precision, given the recall and precision curves.
|
|
|
|
""" Compute the average precision, given the recall and precision curves.
|
|
|
|
Source: https://github.com/rafaelpadilla/Object-Detection-Metrics.
|
|
|
|
Source: https://github.com/rafaelpadilla/Object-Detection-Metrics.
|
|
|
|
# Arguments
|
|
|
|
# Arguments
|
|
|
@ -398,10 +398,10 @@ def ap_per_class(tp, conf, pred_cls, target_cls, plot=False, save_dir='.', names
|
|
|
|
names = [v for k, v in names.items() if k in unique_classes] # list: only classes that have data
|
|
|
|
names = [v for k, v in names.items() if k in unique_classes] # list: only classes that have data
|
|
|
|
names = dict(enumerate(names)) # to dict
|
|
|
|
names = dict(enumerate(names)) # to dict
|
|
|
|
if plot:
|
|
|
|
if plot:
|
|
|
|
plot_pr_curve(px, py, ap, Path(save_dir) / f'{prefix}PR_curve.png', names)
|
|
|
|
plot_pr_curve(px, py, ap, save_dir / f'{prefix}PR_curve.png', names)
|
|
|
|
plot_mc_curve(px, f1, Path(save_dir) / f'{prefix}F1_curve.png', names, ylabel='F1')
|
|
|
|
plot_mc_curve(px, f1, save_dir / f'{prefix}F1_curve.png', names, ylabel='F1')
|
|
|
|
plot_mc_curve(px, p, Path(save_dir) / f'{prefix}P_curve.png', names, ylabel='Precision')
|
|
|
|
plot_mc_curve(px, p, save_dir / f'{prefix}P_curve.png', names, ylabel='Precision')
|
|
|
|
plot_mc_curve(px, r, Path(save_dir) / f'{prefix}R_curve.png', names, ylabel='Recall')
|
|
|
|
plot_mc_curve(px, r, save_dir / f'{prefix}R_curve.png', names, ylabel='Recall')
|
|
|
|
|
|
|
|
|
|
|
|
i = smooth(f1.mean(0), 0.1).argmax() # max F1 index
|
|
|
|
i = smooth(f1.mean(0), 0.1).argmax() # max F1 index
|
|
|
|
p, r, f1 = p[:, i], r[:, i], f1[:, i]
|
|
|
|
p, r, f1 = p[:, i], r[:, i], f1[:, i]
|
|
|
|