计算全局特征之间距离
计算全局distmat:
公式如下:就是简单的线性计算
换句话说,就是需要传入5个参数,mat里的每个元素乘以beta,mat1和mat2进行矩阵乘法(左行乘右列)后再乘以alpha,最后将这2个结果加在一起。
# 全局距离
print('Calculate distance matrixs...')
# query
qf = global_feats[:self.num_query]
q_pids = np.asarray(self.pids[:self.num_query])
q_camids = np.asarray(self.camids[:self.num_query])
# gallery
gf = global_feats[self.num_query:]
g_pids = np.asarray(self.pids[self.num_query:])
g_camids = np.asarray(self.camids[self.num_query:])
qf = qf
m, n = qf.shape[0], gf.shape[0]
if self.rerank:
distmat = re_ranking(qf, gf, k1=20, k2=6, lambda_value=0.3)
else:
# qf: M, F
# gf: N, F
if split == 0:
distmat = torch.pow(qf, 2).sum(dim=1, keepdim=True).expand(m, n) + \
torch.pow(gf, 2)