(self, grad_output)
| 253 | |
| 254 | # This function has only a single output, so it gets only one gradient |
| 255 | def backward(self, grad_output): |
| 256 | |
| 257 | input, target = self.saved_variables |
| 258 | grad_input = grad_target = None |
| 259 | |
| 260 | if self.needs_input_grad[0]: |
| 261 | grad_input = grad_output * 2 * (target * self.union - self.inter) \ |
| 262 | / (self.union * self.union) |
| 263 | if self.needs_input_grad[1]: |
| 264 | grad_target = None |
| 265 | |
| 266 | return grad_input, grad_target |
| 267 | |
| 268 | |
| 269 | def dice_coeff(input, target): |