def runSMCNTF(dbFeat, qFeat, gt, SMCN_params, err, flag=None): st = time.time() n1 = np.linalg.norm(dbFeat, axis=1).reshape((-1, 1)) n2 = np.linalg.norm(qFeat, axis=1).reshape((1, -1)) n12 = np.matmul(n1, n2) S_pairwise = np.matmul(dbFeat, qFeat.T) / n12 S_in = np.matmul(dbFeat, dbFeat.T) / np.matmul(n1, n1.T) can = getCandidate(S_in, S_pairwise, *SMCN_params) S_smcntf, pathid = refreshLoss(S_in, S_pairwise, can, err) time_cost = time.time() - st if flag == 's': return S_smcntf elif flag == 'r': return pathid else: P, R = utils.drawPR(S_smcntf, gt, True) ap = utils.calAvgPred(P, R) return ap, time_cost
def runSMCN(dbFeat, qFeat, gt, SMCN_params, flag=None): st = time.time() n1 = np.linalg.norm(dbFeat, axis=1).reshape((-1, 1)) n2 = np.linalg.norm(qFeat, axis=1).reshape((1, -1)) n12 = np.matmul(n1, n2) S_pairwise = np.matmul(dbFeat, qFeat.T) / n12 S_in = np.matmul(dbFeat, dbFeat.T) / np.matmul(n1, n1.T) can = getCandidate(S_in, S_pairwise, *SMCN_params) S_smcncan = np.zeros_like(S_pairwise) for i in range(can.shape[1]): tmp = np.where(can[:, i] >= 0)[0] if len(tmp): S_smcncan[can[tmp, i], i] = S_pairwise[can[tmp, i], i] if flag == 's': return S_smcncan else: time_cost = time.time() - st P, R = utils.drawPR(S_smcncan, gt) ap = utils.calAvgPred(P, R) return ap, time_cost
subdir = arg_dataset['subdir'] db_save_path = join(desc_dir, subdir[arg_eval['compare_subdir'][0]] + '_desc.npy') q_save_path = join(desc_dir, subdir[arg_eval['compare_subdir'][1]] + '_desc.npy') dbFeat = np.load(db_save_path) qFeat = np.load(q_save_path) if arg_dataset['name'] == 'scut': dbFeat = dbFeat[::4, :] qFeat = qFeat[::4, :] dbn = dbFeat.shape[0] qn = qFeat.shape[0] # get ground truth if arg_dataset['name'] == 'ox_robotcar': err = arg_dataset['err'] db_gps = np.load(join(imgdir, 'gps_' + subdir[arg_eval['compare_subdir'][0]] + '.npy')) q_gps = np.load(join(imgdir, 'gps_' + subdir[arg_eval['compare_subdir'][1]] + '.npy')) _, gtm = utils.getGpsGT(db_gps, q_gps, err) else: err = arg_dataset['err'] gtm = utils.getGroundTruthMatrix(dbn, err) print("Computing Descriptors...") seqLen = 16 descData = performDelta([dbFeat, qFeat], seqLen) S = utils.MCN_pairwise(descData[0], descData[1]) P, R = utils.drawPR(S, gtm) auc = utils.calAvgPred(P, R) print("delta auc : %.4f" % auc)
sig_D1_slsbh = utils.getLSBH(sig_D1, P, 0.25) sig_D2_slsbh = utils.getLSBH(sig_D2, P, 0.25) del P # pairwise n1 = np.linalg.norm(sig_D1, axis=1).reshape((-1, 1)) n2 = np.linalg.norm(sig_D2, axis=1).reshape((1, -1)) n12 = np.matmul(n1, n2) S_pairwise = np.matmul(sig_D1, sig_D2.T) / n12 # sLBSH nOnes = 2 * s * new_dims S_slbsh = np.matmul(sig_D1_slsbh, sig_D2_slsbh.T, dtype=np.float) / nOnes P, R = utils.drawPR(S_pairwise, GT) ap_pairwise = utils.calAvgPred(P, R) P, R = utils.drawPR(S_slbsh, GT) ap_slsbh = utils.calAvgPred(P, R) # calulate the result and save them, firstly uncomment following code and # run them, and comment it and visualize the result # old_dims = omni_D1.shape[1] # newr = np.array([0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5]) #(*) # new_dims = (8192 * newr).astype(np.int) # s = 0.25 # # omni_ap = [] # for each_dim in new_dims: # P = np.random.rand(old_dims, each_dim) # P /= np.linalg.norm(P, axis=1, keepdims=True)
err = 9 #(*) error tolerance for nordland dataset, 9 is set in paper S_file = '../cp3_5/vis3/nd_sumwin.npz' #(*) NL similarity matrix S = np.load(S_file) S_pw = S['S_pw'] S_pwk = S['S_pwk'] S_mcn = S['S_mcn'] S_seq = loadmat('../cp3_4/seqslam/nd_sumwin.mat')['S'] #(*) tmp = np.isnan(S_seq) S_seq[tmp] = np.max(S_seq[~tmp]) S_smcn = S['S_smcn'] S_smcntf = S['S_smcntf'] S_dd = S_nd_dd del S GT = utils.getGroundTruthMatrix(S_pw.shape[0], err) P, R = utils.drawPR(S_pw, GT) ap = utils.calAvgPred(P, R) plt.plot(R, P, color=vis.color[0], label='PW: %.4f' % ap, linewidth=2) P, R = utils.drawPR(S_pwk, GT) ap = utils.calAvgPred(P, R) plt.plot(R, P, color=vis.color[1], label='PWk: %.4f' % ap, linewidth=2) P, R = utils.drawPR(S_mcn, GT) ap = utils.calAvgPred(P, R) plt.plot(R, P, color=vis.color[2], label='MCN: %.4f' % ap, linewidth=2) P, R = utils.drawPR(S_seq, GT, True) ap = utils.calAvgPred(P, R) plt.plot(R, P, color=vis.color[3], label='SeqSLAM: %.4f' % ap, linewidth=2)
gt = utils.getGroundTruth(dbn, err) gtm = utils.getGroundTruthMatrix(dbn, err) # oxford robotcar # err = arg_dataset['err'] # db_gps = np.load(join(imgdir, 'gps_' + subdir[arg_eval['compare_subdir'][0]] + '.npy')) # q_gps = np.load(join(imgdir, 'gps_' + subdir[arg_eval['compare_subdir'][1]] + '.npy')) # _, gtm = utils.getGpsGT(db_gps, q_gps, err) S = utils.MCN_pairwise(dbFeat, qFeat) # experiment 3_2 # if SCUT, uncomment following # canr = [1, 3, 5, 7] # otherwise canr = [0.01, 0.02, 0.05, 0.1] #(*) spid = np.argsort(S, axis=0) for each in canr: # if not SCUT #(*) cannum = int(each * dbn) # otherwise # cannum = each S_can = np.zeros_like(S) for i in range(qn): S_can[spid[-cannum:, i], i] = S[spid[-cannum:, i], i] P, R = utils.drawPR(S_can, gtm) auc = utils.calAvgPred(P, R) print('cannum: %d auc: %.4f' % (cannum, auc))
S_omni_mcn = MCN.runMCN_SDR(params, omni_D1_slsbh, omni_D2_slsbh, GT) # SMCN can = SMCN.getCandidate(S_omni_in, S_omni, *(2, 1, 3)) S_omni_smcncan = np.zeros_like(S_omni) for i in range(can.shape[1]): tmp = np.where(can[:, i] >= 0)[0] if len(tmp): S_omni_smcncan[can[tmp, i], i] = S_omni[can[tmp, i], i] # SMCNTF S_omni_smcntf = SMCN.refreshLoss(S_omni_in, S_omni, can, 1) # visulize plt.figure() P, R = utils.drawPR(S_pairwise, GT) ap = utils.calAvgPred(P, R) plt.plot(R, P, color=utils.color[0], label='pairwise: %.4f' % ap, linewidth=2) P, R = utils.drawPR(S_slbsh, GT) ap = utils.calAvgPred(P, R) plt.plot(R, P, color=utils.color[1], label='sLBSH: %.4f' % ap, linewidth=2) P, R = utils.drawPR(S_omni, GT) ap = utils.calAvgPred(P, R) plt.plot(R, P, color=utils.color[2], label='omni-sLBSH%d : %.4f' % (new_dims * 2, ap), linewidth=2)