| 83 | |
| 84 | |
| 85 | def plot_precision_recall(files, naming_scheme='iter'): |
| 86 | if naming_scheme == 'exp_id': |
| 87 | # name becomes exp_id |
| 88 | names = [f.parts[-3] for f in files] |
| 89 | elif naming_scheme == 'iter': |
| 90 | names = [f.stem for f in files] |
| 91 | else: |
| 92 | raise ValueError(f'not supported {naming_scheme}') |
| 93 | fig, axs = plt.subplots(ncols=2, figsize=(16, 5)) |
| 94 | for f, color, name in zip(files, |
| 95 | sns.color_palette('Blues', n_colors=len(files)), |
| 96 | names): |
| 97 | data = torch.load(f) |
| 98 | precision = data['precision'] |
| 99 | recall = data['params'].recThrs |
| 100 | scores = data['scores'] |
| 101 | precision = precision[0, :, :, 0, -1].mean(1) |
| 102 | scores = scores[0, :, :, 0, -1].mean(1) |
| 103 | prec = precision.mean() |
| 104 | rec = data['recall'][0, :, 0, -1].mean() |
| 105 | print(f'{naming_scheme} {name}: mAP@50={prec * 100: 05.1f}, ' + |
| 106 | f'score={scores.mean():0.3f}, ' + |
| 107 | f'f1={2 * prec * rec / (prec + rec + 1e-8):0.3f}') |
| 108 | axs[0].plot(recall, precision, c=color) |
| 109 | axs[1].plot(recall, scores, c=color) |
| 110 | |
| 111 | axs[0].set_title('Precision / Recall') |
| 112 | axs[0].legend(names) |
| 113 | axs[1].set_title('Scores / Recall') |
| 114 | axs[1].legend(names) |
| 115 | return fig, axs |