(qf, gf)
| 5 | |
| 6 | |
| 7 | def euclidean_distance(qf, gf): |
| 8 | m = qf.shape[0] |
| 9 | n = gf.shape[0] |
| 10 | dist_mat = torch.pow(qf, 2).sum(dim=1, keepdim=True).expand(m, n) + \ |
| 11 | torch.pow(gf, 2).sum(dim=1, keepdim=True).expand(n, m).t() |
| 12 | dist_mat.addmm_(1, -2, qf, gf.t()) |
| 13 | return dist_mat.cpu().numpy() |
| 14 | |
| 15 | def cosine_similarity(qf, gf): |
| 16 | epsilon = 0.00001 |