classDiceLoss(nn.Module):'''
Loss function from https://arxiv.org/abs/1707.03237,
where iou computation is introduced heatmap manner to measure the
diversity bwtween tow heatmaps.
'''def__init__(self, eps=1e-6):super(DiceLoss, self).__init__()
self.eps = eps
defforward(self, pred: torch.Tensor, gt, mask, weights=None):'''
pred: one or two heatmaps of shape (N, 1, H, W),
the losses of tow heatmaps are added together.
gt: (N, 1, H, W)
mask: (N, H, W)
'''assert pred.dim()==4, pred.dim()return self._compute(pred, gt, mask, weights)def_compute(self, pred, gt, mask, weights):if pred.dim()