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"]
      src_masks = src_masks[src_idx]
      masks = [t["masks"] for t in targets]
      # TODO use valid to mask invalid areas due to padding in loss
      target_masks, valid = nested_tensor_from_tensor_list(
          masks
      ).decompose()
      target_masks = target_masks.to(src_masks)
      target_masks = target_masks[tgt_idx]
  
      # upsample predictions to the target size
      src_masks = interpolate(
          src_masks[:, None],
          size=target_masks.shape[-2:],
          mode="bilinear",
          align_corners=False,
      )
      src_masks = src_masks[:, 0].flatten(1)
  
      target_masks = target_masks.flatten(1)
      target_masks = target_masks.view(src_masks.shape)
      losses = {
          "loss_mask": sigmoid_focal_loss(
              src_masks, target_masks, num_boxes
          ),
          "loss_dice": dice_loss(src_masks, target_masks, num_boxes),
      }
      return losses
  
imports: import torch
  import torch.nn.functional
  from torch import nn
  from util import box_ops
  from util.misc import NestedTensor, nested_tensor_from_tensor_list, accuracy, get_world_size, interpolate, is_dist_avail_and_initialized
  from .backbone import build_backbone
  from .matcher import build_matcher
  from .segmentation import DETRsegm, PostProcessPanoptic, PostProcessSegm, dice_loss, sigmoid_focal_loss
  from .transformer import build_transformer
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