MCPcopy Create free account
hub / github.com/LAMDA-CL/CVPR22-Fact / forward_metric

Method forward_metric

models/base/Network.py:31–40  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

29 self.fc = nn.Linear(self.num_features, self.args.num_classes, bias=False)
30
31 def forward_metric(self, x):
32 x = self.encode(x)
33 if 'cos' in self.mode:
34 x = F.linear(F.normalize(x, p=2, dim=-1), F.normalize(self.fc.weight, p=2, dim=-1))
35 x = self.args.temperature * x
36
37 elif 'dot' in self.mode:
38 x = self.fc(x)
39 x = self.args.temperature * x
40 return x
41
42 def encode(self, x):
43 x = self.encoder(x)

Callers 1

forwardMethod · 0.95

Calls 1

encodeMethod · 0.95

Tested by

no test coverage detected