class_docstr: This part is partially derivated from:
  
  https://github.com/facebookresearch/detr/blob/main/models/detr.py.
class_docstr_tok: ["This","part","is","partially","derivated","from",":","https",":","\/\/github.com\/facebookresearch\/detr\/blob\/main\/models\/detr.py","."]
code: def loss_classification(
      self, outputs, batch_gt_instances, indices, num_instances
  ):
      assert "pred_logits" in outputs
      src_logits = outputs["pred_logits"]
      idx = self._get_src_permutation_idx(indices)
      target_classes_o = torch.cat(
          [
              gt.labels[J]
              for gt, (_, J) in zip(batch_gt_instances, 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
  
      src_logits = src_logits.flatten(0, 1)
      target_classes = target_classes.flatten(0, 1)
      # comp focal loss.
      class_loss = (
          self.loss_cls(
              src_logits,
              target_classes,
          )
          / num_instances
      )
      return class_loss
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from scipy.optimize import linear_sum_assignment
  from torch.cuda.amp import autocast
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.utils import reduce_mean
label_desc: Use image node_id 4 for calling the SparseInstCriterion obj's underlying member method code with example usage: obj.loss_classification(outputs, batch_gt_instances, indices, num_instances) and returns: class_loss