(self, input, target)
| 229 | """Dice coeff for individual examples""" |
| 230 | |
| 231 | def forward(self, input, target): |
| 232 | self.save_for_backward(input, target) |
| 233 | eps = 0.0001 |
| 234 | self.inter = torch.dot(input.view(-1), target.view(-1)) |
| 235 | self.union = torch.sum(input) + torch.sum(target) + eps |
| 236 | |
| 237 | t = (2 * self.inter.float() + eps) / self.union.float() |
| 238 | return t |
| 239 | |
| 240 | # This function has only a single output, so it gets only one gradient |
| 241 | def backward(self, grad_output): |