class_docstr: Loss function from https://arxiv.org/abs/1707.03237,
  where iou computation is introduced heatmap manner to measure the
  diversity bwtween tow heatmaps.
class_docstr_tok: ["Loss","function","from","https",":","\/\/arxiv.org\/abs\/1707.03237",",","where","iou","computation","is","introduced","heatmap","manner","to","measure","the","diversity","bwtween","tow","heatmaps","."]
code: def _compute(self, pred, gt, mask, weights):
      if pred.dim() == 4:
          pred = pred[:, 0, :, :]
          gt = gt[:, 0, :, :]
      assert pred.shape == gt.shape
      assert pred.shape == mask.shape
      if weights is not None:
          assert weights.shape == mask.shape
          mask = weights * mask
  
      intersection = (pred * gt * mask).sum()
      union = (pred * mask).sum() + (gt * mask).sum() + self.eps
      loss = 1 - 2.0 * intersection / union
      assert loss <= 1
      return loss
  
imports: import torch
  import torch.nn
  import numpy
  import cv2
  from scipy import ndimage
label_desc: Use image node_id 3 for calling the DiceLoss obj's underlying member method code with example usage: obj._compute(pred, gt, mask, weights) and returns: loss