class_docstr: This class computes the loss for DETR.
  The process happens in two steps:
      1) we compute hungarian assignment between ground truth boxes and the outputs of the model
      2) we supervise each pair of matched ground-truth / prediction (supervise class and box)
class_docstr_tok: ["This","class","computes","the","loss","for","DETR",".","The","process","happens","in","two","steps",":","1",")","we","compute","hungarian","assignment","between","ground","truth","boxes","and","the","outputs","of","the","model","2",")","we","supervise","each","pair","of","matched","ground-truth","\/","prediction","(","supervise","class","and","box",")"]
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_boxes):
      """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
  
      src_idx = self._get_src_permutation_idx(indices)
      tgt_idx = self._get_tgt_permutation_idx(indices)
  
      src_masks = outputs["pred_masks"]
  
      # TODO use valid to mask invalid areas due to padding in loss
      (
          target_masks,
          valid,
      ) = nested_tensor_from_tensor_list(  # noqa: F821
          [t["masks"] for t in targets]
      ).decompose()
      target_masks = target_masks.to(src_masks)
  
      src_masks = src_masks[src_idx]
      # upsample predictions to the target size
      src_masks = interpolate(  # noqa: F821
          src_masks[:, None],
          size=target_masks.shape[-2:],
          mode="bilinear",
          align_corners=False,
      )
      src_masks = src_masks[:, 0].flatten(1)
  
      target_masks = target_masks[tgt_idx].flatten(1)
  
      losses = {
          "loss_mask": sigmoid_focal_loss(  # noqa: F821
              src_masks, target_masks, num_boxes
          ),  # noqa: F821
          "loss_dice": dice_loss(
              src_masks, target_masks, num_boxes
          ),  # noqa: F821
      }
      return losses
  
imports: from collections import OrderedDict
  import torch
  from torch import nn
  from torch.jit.annotations import Dict
  from torch.nn import functional
label_desc: Use image node_id 5 for calling the SetCriterion obj's underlying member method code with example usage: obj.loss_masks(outputs, targets, indices, num_boxes) and returns: losses