Skip to content

Commit

Permalink
Sample-wise normalization added as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
gbazad93 authored Aug 18, 2021
1 parent 69428b0 commit b3909cb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ivadomed/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class DiceLoss(nn.Module):
Attributes:
smooth (float): Value to avoid division by zero when images and predictions are empty.
"""
def __init__(self, smooth=1.0):
def __init__(self, smooth=1.0, sample_wise=False):
super(DiceLoss, self).__init__()
self.smooth = smooth
self.sample_wise = sample_wise

def forward(self, prediction, target):
if not self.sample_wise:
prediction, target = prediction.unsqueeze(dim=0), target.unsqueeze(dim=0)
iflat = prediction.reshape(prediction.shape[0], -1)
tflat = target.reshape(target.shape[0], -1)
intersection = (iflat * tflat).sum(dim = 1)
Expand Down

0 comments on commit b3909cb

Please sign in to comment.