(self, input, target)
| 243 | """Dice coeff for individual examples""" |
| 244 | |
| 245 | def forward(self, input, target): |
| 246 | self.save_for_backward(input, target) |
| 247 | eps = 0.0001 |
| 248 | self.inter = torch.dot(input.view(-1), target.view(-1)) |
| 249 | self.union = torch.sum(input) + torch.sum(target) + eps |
| 250 | |
| 251 | t = (2 * self.inter.float() + eps) / self.union.float() |
| 252 | return t |
| 253 | |
| 254 | # This function has only a single output, so it gets only one gradient |
| 255 | def backward(self, grad_output): |