(self, inputs, target, weight=None, softmax=False)
| 123 | return loss |
| 124 | |
| 125 | def forward(self, inputs, target, weight=None, softmax=False): |
| 126 | if softmax: |
| 127 | inputs = torch.softmax(inputs, dim=1) |
| 128 | target = self._one_hot_encoder(target) |
| 129 | if weight is None: |
| 130 | weight = [1] * self.n_classes |
| 131 | assert inputs.size() == target.size(), 'predict {} & target {} shape do not match'.format(inputs.size(), target.size()) |
| 132 | class_wise_dice = [] |
| 133 | loss = 0.0 |
| 134 | for i in range(0, self.n_classes): |
| 135 | dice = self._dice_loss(inputs[:, i], target[:, i]) |
| 136 | class_wise_dice.append(1.0 - dice.item()) |
| 137 | loss += dice * weight[i] |
| 138 | return loss / self.n_classes |
| 139 | |
| 140 | def calculate_metric_percase(pred, gt): |
| 141 | pred[pred > 0] = 1 |
nothing calls this directly
no test coverage detected