MCPcopy Create free account
hub / github.com/imrahulr/hat / forward

Method forward

core/utils/utils.py:19–30  ·  view source on GitHub ↗
(self, input, target)

Source from the content-addressed store, hash-verified

17 self.reduction = reduction
18
19 def forward(self, input, target):
20 num_classes = input.shape[1]
21 if target.ndim == 1:
22 target = torch.nn.functional.one_hot(target, num_classes)
23 target = (1. - self.smoothing) * target + self.smoothing / num_classes
24 logprobs = torch.nn.functional.log_softmax(input, dim=1)
25 loss = - (target * logprobs).sum(dim=1)
26 if self.reduction == 'mean':
27 return loss.mean()
28 elif self.reduction == 'sum':
29 return loss.sum()
30 return loss
31
32
33def track_bn_stats(model, track_stats=True):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected