MCPcopy Create free account
hub / github.com/XLearning-SCU/2022-CVPR-DART / pdist_np

Function pdist_np

loss.py:151–161  ·  view source on GitHub ↗

compute the eucilidean distance matrix between embeddings1 and embeddings2 using cpu

(emb1, emb2)

Source from the content-addressed store, hash-verified

149
150
151def 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
164class RobustTripletLoss_final(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected