class_docstr: From DETR source: https://github.com/facebookresearch/detr
  (detr/models/detr.py)
class_docstr_tok: ["From","DETR","source",":","https",":","\/\/github.com\/facebookresearch\/detr","(","detr\/models\/detr.py",")"]
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]
      """
      import torchvision
  
      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]
      target_masks, _ = nested_tensor_from_tensor_list(
          masks
      ).decompose()
      target_masks = target_masks.to_device(src_masks)
      target_masks = target_masks[tgt_idx]
  
      src_masks = torchvision.ops.misc.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": self.sigmoid_focal_loss(
              src_masks, target_masks, num_boxes
          ),
          "loss_dice": self.dice_loss(
              src_masks, target_masks, num_boxes
          ),
      }
      return losses
  
imports: from typing import List, Optional, Tuple, Union
  import torch
label_desc: Use image node_id 7 for calling the SetCriterion obj's underlying member method code with example usage: obj.loss_masks(outputs, targets, indices, num_boxes) and returns: losses