class_docstr: Dice loss for segmentation
docstr: One-hot encodes targ, then runs IoU calculation then takes 1-dice value
docstr_tok: ["One-hot","encodes","targ",",","then","runs","IoU","calculation","then","takes","1-dice","value"]
code: def __call__(self, pred: Tensor, targ: Tensor) -> Tensor:
      "One-hot encodes targ, then runs IoU calculation then takes 1-dice value"
      targ = self._one_hot(targ, pred.shape[self.axis])
      pred, targ = TensorBase(pred), TensorBase(targ)
      assert (
          pred.shape == targ.shape
      ), "input and target dimensions differ, DiceLoss expects non one-hot targs"
      pred = self.activation(pred)
      sum_dims = list(range(2, len(pred.shape)))
      inter = torch.sum(pred * targ, dim=sum_dims)
      union = (
          torch.sum(pred**2 + targ, dim=sum_dims)
          if self.square_in_union
          else torch.sum(pred + targ, dim=sum_dims)
      )
      dice_score = (2.0 * inter + self.smooth) / (union + self.smooth)
      loss = 1 - dice_score
      if self.reduction == "mean":
          loss = loss.mean()
      elif self.reduction == "sum":
          loss = loss.sum()
      return loss
  
imports: from __future__ import annotations
  from .imports import *
  from .torch_imports import *
  from .torch_core import *
  from .layers import *
label_desc: Use image node_id 2 for calling the DiceLoss obj's underlying member method code with example usage: obj.__call__(pred, targ) and returns: loss