Custom Softmax
(inp, multihotmask)
| 135 | |
| 136 | |
| 137 | def customsoftmax(inp, multihotmask): |
| 138 | """ |
| 139 | Custom Softmax |
| 140 | """ |
| 141 | soft = F.softmax(inp) |
| 142 | # This takes the mask * softmax ( sums it up hence summing up the classes |
| 143 | # in border then takes of summed up version vs no summed version |
| 144 | return torch.log( |
| 145 | torch.max(soft, |
| 146 | (multihotmask * (soft * multihotmask).sum(1, keepdim=True))) |
| 147 | ) |
| 148 | |
| 149 | |
| 150 | class ImgWtLossSoftNLL(nn.Module): |