class_docstr: The Maskformer loss implemeted with PaddlePaddle.
  
  Args:
      num_classes(int): The number of classes that you want this network to classify. Default:150.
      eos_coef(float): The weight coefficient of the last class. Default: 0.1.
      losses(Tuple): The category of losses that you want to compute. Default: ("labels", 'masks').
      ignore_index(int): The ignored label when we calculate the loss. Default:255.
class_docstr_tok: ["The","Maskformer","loss","implemeted","with","PaddlePaddle",".","Args",":","num_classes","(","int",")",":","The","number","of","classes","that","you","want","this","network","to","classify",".","Default:150.","eos_coef","(","float",")",":","The","weight","coefficient","of","the","last","class",".","Default",":","0.1.","losses","(","Tuple",")",":","The","category","of","losses","that","you","want","to","compute",".","Default",":","(","``","labels","''",",","'masks","'",")",".","ignore_index","(","int",")",":","The","ignored","label","when","we","calculate","the","loss",".","Default:255","."]
docstr: Compute the losses related to the masks: the focal loss and the dice loss.
  targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]
docstr_tok: ["Compute","the","losses","related","to","the","masks",":","the","focal","loss","and","the","dice","loss",".","targets","dicts","must","contain","the","key","``","masks","''","containing","a","tensor","of","dim","[","nb_target_boxes",",","h",",","w","]"]
code: def loss_masks(self, outputs, targets, indices, num_masks):
      """Compute the losses related to the masks: the focal loss and the dice loss.
      targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]
      """
      assert (
          "pred_masks" in outputs
      ), "The 'pred_masks' need to be in outputs, but only got keys: {}".format(
          outputs.keys()
      )
  
      targets_cpt, indices_cpt = [], []
      for t, indice in zip(targets, indices):
          if t["labels"].shape[0] != 0:
              targets_cpt.append(t)
              indices_cpt.append(indice)
      else:
          if indices_cpt == []:
              losses = {
                  "loss_mask": paddle.to_tensor([0.0]),
                  "loss_dice": paddle.to_tensor([0.0]),
              }
              return losses
      src_idx = self._get_src_permutation_idx(indices)
      tgt_idx = self._get_tgt_permutation_idx(indices_cpt)
      src_masks = outputs["pred_masks"]
      src_masks = src_masks[src_idx]
      if src_masks.ndim == 2:
          src_masks = src_masks.unsqueeze(0)
      masks = [t["masks"] for t in targets_cpt]
  
      target_masks, valid = nested_tensor_from_tensor_list(masks)
      target_masks = paddle.cast(target_masks, src_masks.dtype)
      target_masks = target_masks[tgt_idx]
  
      src_masks = F.interpolate(
          src_masks[:, None],
          size=target_masks.shape[-2:],
          mode="bilinear",
          align_corners=False,
      )
      src_masks = paddle.flatten(src_masks[:, 0], 1)
  
      target_masks = paddle.flatten(target_masks, 1)
      target_masks = target_masks.reshape(src_masks.shape)
      losses = {
          "loss_mask": sigmoid_focal_loss(
              src_masks, target_masks, num_masks
          ),
          "loss_dice": dice_loss(src_masks, target_masks, num_masks),
      }
      return losses
  
imports: import copy
  import numpy
  from scipy.optimize import linear_sum_assignment
  import paddle
  import paddle.nn
  import paddle.distributed
  import paddle.nn.functional
  from paddleseg.cvlibs import manager
label_desc: Use image node_id 3 for calling the MaskFormerLoss obj's underlying member method code with example usage: obj.loss_masks(outputs, targets, indices, num_masks) and returns: losses, losses