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: Classification loss (NLL)
  targets dicts must contain the key "labels" containing a tensor of dim
      [nb_target_boxes]
docstr_tok: ["Classification","loss","(","NLL",")","targets","dicts","must","contain","the","key","``","labels","''","containing","a","tensor","of","dim","[","nb_target_boxes","]"]
code: def loss_labels(self, outputs, targets, indices, num_boxes, log=True):
      """Classification loss (NLL)
      targets dicts must contain the key "labels" containing a tensor of dim
          [nb_target_boxes]
      """
      assert "pred_logits" in outputs
      src_logits = outputs["pred_logits"]
  
      idx = self._get_src_permutation_idx(indices)
      target_classes_o = torch.cat(
          [t["labels"][J] for t, (_, J) in zip(targets, indices)]
      )
      target_classes = torch.full(
          src_logits.shape[:2],
          self.num_classes,
          dtype=torch.int64,
          device=src_logits.device,
      )
      target_classes[idx] = target_classes_o
  
      loss_ce = F.cross_entropy(
          src_logits.transpose(1, 2), target_classes, self.empty_weight
      )
      losses = {"loss_ce": loss_ce}
  
      if self.attribute_head is not None and "attributes" in targets[0]:
          attribute_logits = self.attribute_head(
              outputs["hs_for_attr"], target_classes
          )
          target_attributes_o = torch.cat(
              [
                  t["attributes"][J]
                  for t, (_, J) in zip(targets, indices)
              ]
          )
          target_attributes = -torch.ones(
              *src_logits.shape[:2],
              16,
              dtype=torch.int64,
              device=src_logits.device,
          )
          target_attributes[idx] = target_attributes_o
          losses["loss_attr"] = self._attribute_loss(
              attribute_logits, target_attributes
          )
  
      return losses
  
imports: from typing import Optional
  import torch
  import torch.nn.functional
  from mmf.models.unit.backbone import build_unit_convnet_backbone
  from mmf.models.unit.matcher import HungarianMatcher
  from mmf.models.unit.misc import NestedTensor
  from mmf.models.unit.transformer import UniTTransformer
  from mmf.utils import box_ops
  from mmf.utils.distributed import get_world_size, is_dist_initialized
  from torch import nn, Tensor
label_desc: Use image node_id 2 for calling the SetCriterion obj's underlying member method code with example usage: obj.loss_labels(outputs, targets, indices, num_boxes, log) and returns: losses