class_docstr: The dual task loss implement of GSCNN
  
  Args:
      ignore_index (int64): Specifies a target value that is ignored
          and does not contribute to the input gradient. Default ``255``.
      tau (float): the tau of gumbel softmax sample.
class_docstr_tok: ["The","dual","task","loss","implement","of","GSCNN","Args",":","ignore_index","(","int64",")",":","Specifies","a","target","value","that","is","ignored","and","does","not","contribute","to","the","input","gradient",".","Default","``","255","``",".","tau","(","float",")",":","the","tau","of","gumbel","softmax","sample","."]
code: def forward(self, logit, labels):
      # import pdb; pdb.set_trace()
      n, c, h, w = logit.shape
      th = 1e-8
      eps = 1e-10
      if len(labels.shape) == 3:
          labels = labels.unsqueeze(1)
      mask = labels != self.ignore_index
      mask.stop_gradient = True
      logit = logit * mask
  
      labels = labels * mask
      if len(labels.shape) == 4:
          labels = labels.squeeze(1)
      labels.stop_gradient = True
      labels = F.one_hot(labels, logit.shape[1]).transpose((0, 3, 1, 2))
      labels.stop_gradient = True
  
      g = self._gumbel_softmax_sample(logit, tau=self.tau)
      g = self.compute_grad_mag(g)
      g_hat = self.compute_grad_mag(labels)
      loss = F.l1_loss(g, g_hat, reduction="none")
      loss = loss * mask
  
      g_mask = (g > th).astype("float32")
      g_mask.stop_gradient = True
      g_mask_sum = paddle.sum(g_mask)
      loss_g = paddle.sum(loss * g_mask)
      if g_mask_sum > eps:
          loss_g = loss_g / g_mask_sum
  
      g_hat_mask = (g_hat > th).astype("float32")
      g_hat_mask.stop_gradient = True
      g_hat_mask_sum = paddle.sum(g_hat_mask)
      loss_g_hat = paddle.sum(loss * g_hat_mask)
      if g_hat_mask_sum > eps:
          loss_g_hat = loss_g_hat / g_hat_mask_sum
  
      total_loss = 0.5 * loss_g + 0.5 * loss_g_hat
  
      return total_loss
  
file_path: PaddleSeg/paddleseg/models/losses/gscnn_dual_task_loss.py
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager
label_desc: Use image node_id 5 for calling the DualTaskLoss obj's underlying member method code with example usage: obj.forward(logit, labels) and returns: total_loss