In current dice loss implementation if a class with highest number doesn't appear in target the dice loss won't run against this class because of target.max():
for class_nr in range(1, int(target.max()) + 1):
class_target = (target == class_nr)
class_target.data = class_target.data.float()
loss += dice(output[:, class_nr, :, :], class_target)
return loss
In current dice loss implementation if a class with highest number doesn't appear in target the dice loss won't run against this class because of
target.max()
: