Cross Entroply NLL Loss
| 119 | |
| 120 | |
| 121 | class CrossEntropyLoss2d(nn.Module): |
| 122 | """ |
| 123 | Cross Entroply NLL Loss |
| 124 | """ |
| 125 | |
| 126 | def __init__(self, weight=None, ignore_index=cfg.DATASET.IGNORE_LABEL, |
| 127 | reduction='mean'): |
| 128 | super(CrossEntropyLoss2d, self).__init__() |
| 129 | logx.msg("Using Cross Entropy Loss") |
| 130 | self.nll_loss = nn.NLLLoss(weight, reduction=reduction, |
| 131 | ignore_index=ignore_index) |
| 132 | |
| 133 | def forward(self, inputs, targets, do_rmi=None): |
| 134 | return self.nll_loss(F.log_softmax(inputs, dim=1), targets) |
| 135 | |
| 136 | |
| 137 | def customsoftmax(inp, multihotmask): |