|
|
|
@ -343,7 +343,7 @@ def compute_ap(recall, precision):
|
|
|
|
|
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.
|
|
|
|
|
Source: https://github.com/rafaelpadilla/Object-Detection-Metrics.
|
|
|
|
|
# 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 = dict(enumerate(names)) # to dict
|
|
|
|
|
if plot:
|
|
|
|
|
plot_pr_curve(px, py, ap, Path(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, p, Path(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_pr_curve(px, py, ap, save_dir / f'{prefix}PR_curve.png', names)
|
|
|
|
|
plot_mc_curve(px, f1, save_dir / f'{prefix}F1_curve.png', names, ylabel='F1')
|
|
|
|
|
plot_mc_curve(px, p, save_dir / f'{prefix}P_curve.png', names, ylabel='Precision')
|
|
|
|
|
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
|
|
|
|
|
p, r, f1 = p[:, i], r[:, i], f1[:, i]
|
|
|
|
|