compute the eucilidean distance matrix between embeddings1 and embeddings2 using cpu
(emb1, emb2)
| 149 | |
| 150 | |
| 151 | def pdist_np(emb1, emb2): |
| 152 | ''' |
| 153 | compute the eucilidean distance matrix between embeddings1 and embeddings2 |
| 154 | using cpu |
| 155 | ''' |
| 156 | m, n = emb1.shape[0], emb2.shape[0] |
| 157 | emb1_pow = np.square(emb1).sum(axis=1)[..., np.newaxis] |
| 158 | emb2_pow = np.square(emb2).sum(axis=1)[np.newaxis, ...] |
| 159 | dist_mtx = -2 * np.matmul(emb1, emb2.T) + emb1_pow + emb2_pow |
| 160 | # dist_mtx = np.sqrt(dist_mtx.clip(min = 1e-12)) |
| 161 | return dist_mtx |
| 162 | |
| 163 | |
| 164 | class RobustTripletLoss_final(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected