给定一个预训练的 CNN 模型,我提取 3450 参考(冬季)和 3450 查询图像(春季)的特征向量,并将特征与欧几里德距离进行比较,以绘制除地面实况之外的距离矩阵。地面实况矩阵表示一对一一图对应如下:
img_i in Query --> img_i in Reference database
我想用 Precision-Recall 曲线验证我的结果,这是我使用的代码:
def draw_PR(cm_gt, cm_pred, query_season, ref_season):
pr_curve = []
for th in np.arange(0, .99, 5e-4): # apply threshold
tp = (cm_pred < th) & (cm_gt == 0)
tp_plus_fp = (cm_pred < th)
tp_plus_fn = (cm_gt == 0)
try:
p = float(np.sum(tp))/np.sum(tp_plus_fp)
r = float(np.sum(tp))/np.sum(tp_plus_fn)
pr_curve.append([th, p, r])
except:
pass
pr_curve = np.array(pr_curve)
if pr_curve.size > 0:
plt.figure()
plt.plot(pr_curve[:, 2], pr_curve[:, 1], 'b')
plt.ylabel('Precision')
plt.xlabel('Recall')
plt.axis([0, 1.01, 0, 1.01])
plt.title('PR')
plt.tight_layout()
plt.grid()
plt.savefig('R_'+ref_season+'_Q_'+query_season+'_PR' + '.pdf', bbox_inches='tight', dpi=1000)
有没有人好心帮我弄清楚如何在给定预测和基本事实的距离矩阵的情况下绘制精确召回?
干杯,