Dice coeff for batches
(input, target)
| 214 | return iou.mean() |
| 215 | |
| 216 | def dice_coeff(input, target): |
| 217 | """Dice coeff for batches""" |
| 218 | if input.is_cuda: |
| 219 | s = torch.FloatTensor(1).to(device = input.device).zero_() |
| 220 | else: |
| 221 | s = torch.FloatTensor(1).zero_() |
| 222 | |
| 223 | for i, c in enumerate(zip(input, target)): |
| 224 | s = s + DiceCoeff().forward(c[0], c[1]) |
| 225 | |
| 226 | return s / (i + 1) |
| 227 | |
| 228 | class DiceCoeff(Function): |
| 229 | """Dice coeff for individual examples""" |