MCPcopy Create free account
hub / github.com/chenhaoxing/DiffusionInst / plot_precision_recall

Function plot_precision_recall

diffusioninst/util/plot_utils.py:76–107  ·  view source on GitHub ↗
(files, naming_scheme='iter')

Source from the content-addressed store, hash-verified

74
75
76def plot_precision_recall(files, naming_scheme='iter'):
77 if naming_scheme == 'exp_id':
78 # name becomes exp_id
79 names = [f.parts[-3] for f in files]
80 elif naming_scheme == 'iter':
81 names = [f.stem for f in files]
82 else:
83 raise ValueError(f'not supported {naming_scheme}')
84 fig, axs = plt.subplots(ncols=2, figsize=(16, 5))
85 for f, color, name in zip(files, sns.color_palette("Blues", n_colors=len(files)), names):
86 data = torch.load(f)
87 # precision is n_iou, n_points, n_cat, n_area, max_det
88 precision = data['precision']
89 recall = data['params'].recThrs
90 scores = data['scores']
91 # take precision for all classes, all areas and 100 detections
92 precision = precision[0, :, :, 0, -1].mean(1)
93 scores = scores[0, :, :, 0, -1].mean(1)
94 prec = precision.mean()
95 rec = data['recall'][0, :, 0, -1].mean()
96 print(f'{naming_scheme} {name}: mAP@50={prec * 100: 05.1f}, ' +
97 f'score={scores.mean():0.3f}, ' +
98 f'f1={2 * prec * rec / (prec + rec + 1e-8):0.3f}'
99 )
100 axs[0].plot(recall, precision, c=color)
101 axs[1].plot(recall, scores, c=color)
102
103 axs[0].set_title('Precision / Recall')
104 axs[0].legend(names)
105 axs[1].set_title('Scores / Recall')
106 axs[1].legend(names)
107 return fig, axs

Callers

nothing calls this directly

Calls 1

printFunction · 0.85

Tested by

no test coverage detected