MCPcopy Create free account
hub / github.com/Chain123/Meta-HAR / pairwiseloss

Class pairwiseloss

utils.py:74–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73
74class pairwiseloss(torch.nn.Module):
75 def __init__(self):
76 super(pairwiseloss, self).__init__()
77
78 def forward(self, embed, target, chunck_size, Expand=10):
79 Expand = np.float64(Expand * 1.0)
80 embed_split = torch.split(embed, chunck_size, dim=0)
81 target_split = torch.split(target, chunck_size, dim=0)
82 Phi = cosine_similarity(embed_split[0], embed_split[1]) * Expand
83 soft_phi = softplus(Phi)
84 if device == "cuda":
85 mask = torch.sum(torch.mul(target_split[0], target_split[1]), dim=1).type(torch.cuda.FloatTensor)
86 else:
87 mask = torch.sum(torch.mul(target_split[0], target_split[1]), dim=1).type(torch.FloatTensor)
88 # print(mask.type())
89 # print(Phi.type())
90 mask_phi = torch.mul(mask, Phi)
91 pairwiseloss = torch.sub(soft_phi, mask_phi).mean()
92 return pairwiseloss
93
94
95class pairwiseloss_global(torch.nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…