(self, input, target)
| 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 | |
| 33 | def track_bn_stats(model, track_stats=True): |
nothing calls this directly
no outgoing calls
no test coverage detected