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","."]
code: def forward(self, logits, targets):
      targets_cpt = []
      batch_size = targets["gt_masks"].shape[0]
      # split targets in a batch
      for target_per_image_idx in range(batch_size):
          gt_masks = targets["gt_masks"][target_per_image_idx, ...]
          padded_masks = paddle.zeros(
              (
                  gt_masks.shape[0],
                  gt_masks.shape[-2],
                  gt_masks.shape[-1],
              ),
              dtype=gt_masks.dtype,
          )
          padded_masks[
              :, : gt_masks.shape[1], : gt_masks.shape[2]
          ] = gt_masks
  
          targets_cpt.append(
              {
                  "labels": targets["gt_classes"][
                      target_per_image_idx, ...
                  ],
                  "masks": padded_masks,
              }
          )
  
      targets = []
      for item in targets_cpt:
          item["masks"] = paddle.cast(item["masks"], "bool")
          invalid_indices = paddle.nonzero(
              paddle.cast(item["labels"] == self.ignore_index, "int64")
          )
          if len(invalid_indices) > 0:
              start_idx = int(invalid_indices[0].numpy())
          else:
              start_idx = len(item["labels"])
          index = paddle.cast(
              paddle.to_tensor([i for i in range(start_idx)]), "int64"
          )
          item["labels"] = paddle.gather(
              item["labels"], index, axis=0
          )  # [n] n<150
          item["masks"] = paddle.gather(
              item["masks"], index, axis=0
          )  # [n,512,512]
          targets.append(item)
  
      logits_without_aux = {
          k: v for k, v in logits.items() if k != "aux_outputs"
      }
  
      # Retrieve the matching between the outputs of the last layer and the targets
      indices = self.matcher(logits_without_aux, targets)
  
      num_masks = sum(len(t["labels"]) for t in targets)
      num_masks = paddle.to_tensor([num_masks], dtype="float32")
  
      if dist.get_world_size() > 1:
          dist.all_reduce(num_masks)
      num_masks = (
          paddle.clip(num_masks / dist.get_world_size(), min=1)
          .detach()
          .numpy()[0]
      )
  
      losses = {}
      for loss in self.losses:
          losses.update(
              self.get_loss(
                  loss, logits_without_aux, targets, indices, num_masks
              )
          )
  
      if "aux_outputs" in logits:
          for i in range(len(logits["aux_outputs"])):
              indices = self.matcher(logits["aux_outputs"][i], targets)
              for loss in self.losses:
                  l_dict = self.get_loss(
                      loss,
                      logits["aux_outputs"][i],
                      targets,
                      indices,
                      num_masks,
                  )
                  l_dict = {k + f"_{i}": v for k, v in l_dict.items()}
                  losses.update(l_dict)
  
      for k in list(losses.keys()):
          if k in self.weight_dict:
              losses[k] *= self.weight_dict[k]
          else:
              losses.pop(k)
  
      return sum(losses.values())
  
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 7 for calling the MaskFormerLoss obj's underlying member method code with example usage: obj.forward(logits, targets) and returns: sum