class_docstr: Implementation of `SparseInst <https://arxiv.org/abs/1912.02424>`_
  
  Args:
      data_preprocessor (:obj:`ConfigDict` or dict, optional): Config of
          :class:`DetDataPreprocessor` to process the input data.
          Defaults to None.
      backbone (:obj:`ConfigDict` or dict): The backbone module.
      encoder (:obj:`ConfigDict` or dict): The encoder module.
      decoder (:obj:`ConfigDict` or dict): The decoder module.
      criterion (:obj:`ConfigDict` or dict, optional): The training matcher
          and losses. Defaults to None.
      test_cfg (:obj:`ConfigDict` or dict, optional): The testing config
          of SparseInst. Defaults to None.
      init_cfg (:obj:`ConfigDict` or dict, optional): the config to control
          the initialization. Defaults to None.
class_docstr_tok: ["Implementation","of","`","SparseInst","<","https",":","\/\/arxiv.org\/abs\/1912.02424",">","`","_","Args",":","data_preprocessor","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","of",":","class",":","`","DetDataPreprocessor","`","to","process","the","input","data",".","Defaults","to","None",".","backbone","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","backbone","module",".","encoder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","encoder","module",".","decoder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","decoder","module",".","criterion","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","The","training","matcher","and","losses",".","Defaults","to","None",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","The","testing","config","of","SparseInst",".","Defaults","to","None",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","the","config","to","control","the","initialization",".","Defaults","to","None","."]
docstr: Calculate losses from a batch of inputs and data samples.
  
  Args:
      batch_inputs (Tensor): Input images of shape (N, C, H, W).
          These should usually be mean centered and std scaled.
      batch_data_samples (list[:obj:`DetDataSample`]): The batch
          data samples. It usually includes information such
          as `gt_instance` or `gt_panoptic_seg` or `gt_sem_seg`.
  
  Returns:
      dict: A dictionary of loss components.
docstr_tok: ["Calculate","losses","from","a","batch","of","inputs","and","data","samples",".","Args",":","batch_inputs","(","Tensor",")",":","Input","images","of","shape","(","N",",","C",",","H",",","W",")",".","These","should","usually","be","mean","centered","and","std","scaled",".","batch_data_samples","(","list","[",":","obj",":","`","DetDataSample","`","]",")",":","The","batch","data","samples",".","It","usually","includes","information","such","as","`","gt_instance","`","or","`","gt_panoptic_seg","`","or","`","gt_sem_seg","`",".","Returns",":","dict",":","A","dictionary","of","loss","components","."]
code: def loss(
      self, batch_inputs: Tensor, batch_data_samples: SampleList
  ) -> Union[dict, list]:
      """Calculate losses from a batch of inputs and data samples.
  
      Args:
          batch_inputs (Tensor): Input images of shape (N, C, H, W).
              These should usually be mean centered and std scaled.
          batch_data_samples (list[:obj:`DetDataSample`]): The batch
              data samples. It usually includes information such
              as `gt_instance` or `gt_panoptic_seg` or `gt_sem_seg`.
  
      Returns:
          dict: A dictionary of loss components.
      """
      outs = self._forward(batch_inputs)
      (
          batch_gt_instances,
          batch_gt_instances_ignore,
          batch_img_metas,
      ) = unpack_gt_instances(batch_data_samples)
  
      losses = self.criterion(
          outs,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore,
      )
      return losses
  
file_path: mmdetection/projects/SparseInst/sparseinst/sparseinst.py
imports: from typing import List, Tuple, Union
  import torch
  import torch.nn.functional
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models import BaseDetector
  from mmdet.models.utils import unpack_gt_instances
  from mmdet.registry import MODELS
  from mmdet.structures import OptSampleList, SampleList
  from mmdet.utils import ConfigType, OptConfigType
label_desc: Use image node_id 4 for calling the SparseInst obj's underlying member method code with example usage: obj.loss(batch_inputs, batch_data_samples) and returns: losses