class_docstr: Wrapper of a Detectron2 model. Input/output formats of this class follow
  MMDetection's convention, so a Detectron2 model can be trained and
  evaluated in MMDetection.
  
  Args:
      detector (:obj:`ConfigDict` or dict): The module config of
          Detectron2.
      bgr_to_rgb (bool): whether to convert image from BGR to RGB.
          Defaults to False.
      rgb_to_bgr (bool): whether to convert image from RGB to BGR.
          Defaults to False.
class_docstr_tok: ["Wrapper","of","a","Detectron2","model",".","Input\/output","formats","of","this","class","follow","MMDetection","'s","convention",",","so","a","Detectron2","model","can","be","trained","and","evaluated","in","MMDetection",".","Args",":","detector","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","module","config","of","Detectron2",".","bgr_to_rgb","(","bool",")",":","whether","to","convert","image","from","BGR","to","RGB",".","Defaults","to","False",".","rgb_to_bgr","(","bool",")",":","whether","to","convert","image","from","RGB","to","BGR",".","Defaults","to","False","."]
docstr: Calculate losses from a batch of inputs and data samples.
  
  The inputs will first convert to the Detectron2 type and feed into
  D2 models.
  
  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",".","The","inputs","will","first","convert","to","the","Detectron2","type","and","feed","into","D2","models",".","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, tuple]:
      """Calculate losses from a batch of inputs and data samples.
  
      The inputs will first convert to the Detectron2 type and feed into
      D2 models.
  
      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.
      """
      d2_batched_inputs = self._convert_to_d2_inputs(
          batch_inputs=batch_inputs,
          batch_data_samples=batch_data_samples,
          training=True,
      )
  
      with self.storage as storage:  # noqa
          losses = self.d2_model(d2_batched_inputs)
      # storage contains some training information, such as cls_accuracy.
      # you can use storage.latest() to get the detail information
      return losses
  
imports: from typing import Union
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import BaseBoxes
  from mmdet.structures.mask import BitmapMasks, PolygonMasks
  from mmdet.utils import ConfigType
  from .base import BaseDetector
label_desc: Use image node_id 3 for calling the Detectron2Wrapper obj's underlying member method code with example usage: obj.loss(batch_inputs, batch_data_samples) and returns: losses