MCPcopy Create free account
hub / github.com/SLDGroup/EMCAD / forward

Method forward

utils/utils.py:125–138  ·  view source on GitHub ↗
(self, inputs, target, weight=None, softmax=False)

Source from the content-addressed store, hash-verified

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
140def calculate_metric_percase(pred, gt):
141 pred[pred > 0] = 1

Callers

nothing calls this directly

Calls 2

_one_hot_encoderMethod · 0.95
_dice_lossMethod · 0.95

Tested by

no test coverage detected