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: Convert inputs type to support Detectron2's model.
  
  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`.
      training (bool): Whether to enable training time processing.
  
  Returns:
      list[dict]: A list of dict, which will be fed into Detectron2's
      model. And the dict usually contains following keys.
  
      - image (Tensor): Image in (C, H, W) format.
      - instances (Instances): GT Instance.
      - height (int): the output height resolution of the model
      - width (int): the output width resolution of the model
docstr_tok: ["Convert","inputs","type","to","support","Detectron2","'s","model",".","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","`",".","training","(","bool",")",":","Whether","to","enable","training","time","processing",".","Returns",":","list","[","dict","]",":","A","list","of","dict",",","which","will","be","fed","into","Detectron2's","model",".","And","the","dict","usually","contains","following","keys",".","-","image","(","Tensor",")",":","Image","in","(","C",",","H",",","W",")","format",".","-","instances","(","Instances",")",":","GT","Instance",".","-","height","(","int",")",":","the","output","height","resolution","of","the","model","-","width","(","int",")",":","the","output","width","resolution","of","the","model"]
code: def _convert_to_d2_inputs(
      self,
      batch_inputs: Tensor,
      batch_data_samples: SampleList,
      training=True,
  ) -> list:
      """Convert inputs type to support Detectron2's model.
  
      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`.
          training (bool): Whether to enable training time processing.
  
      Returns:
          list[dict]: A list of dict, which will be fed into Detectron2's
          model. And the dict usually contains following keys.
  
          - image (Tensor): Image in (C, H, W) format.
          - instances (Instances): GT Instance.
          - height (int): the output height resolution of the model
          - width (int): the output width resolution of the model
      """
      from detectron2.data.detection_utils import filter_empty_instances
      from detectron2.structures import Boxes, Instances
  
      batched_d2_inputs = []
      for image, data_samples in zip(batch_inputs, batch_data_samples):
          d2_inputs = dict()
          # deal with metainfo
          meta_info = data_samples.metainfo
          d2_inputs["file_name"] = meta_info["img_path"]
          d2_inputs["height"], d2_inputs["width"] = meta_info[
              "ori_shape"
          ]
          d2_inputs["image_id"] = meta_info["img_id"]
          # deal with image
          if self._channel_conversion:
              image = image[[2, 1, 0], ...]
          d2_inputs["image"] = image
          # deal with gt_instances
          gt_instances = data_samples.gt_instances
          d2_instances = Instances(meta_info["img_shape"])
  
          gt_boxes = gt_instances.bboxes
          # TODO: use mmdet.structures.box.get_box_tensor after PR 8658
          #  has merged
          if isinstance(gt_boxes, BaseBoxes):
              gt_boxes = gt_boxes.tensor
          d2_instances.gt_boxes = Boxes(gt_boxes)
  
          d2_instances.gt_classes = gt_instances.labels
          if gt_instances.get("masks", None) is not None:
              gt_masks = gt_instances.masks
              if isinstance(gt_masks, PolygonMasks):
                  d2_instances.gt_masks = D2_PolygonMasks(
                      gt_masks.masks
                  )
              elif isinstance(gt_masks, BitmapMasks):
                  d2_instances.gt_masks = D2_BitMasks(gt_masks.masks)
              else:
                  raise TypeError(
                      "The type of `gt_mask` can be "
                      "`PolygonMasks` or `BitMasks`, but get "
                      f"{type(gt_masks)}."
                  )
          # convert to cpu and convert back to cuda to avoid
          # some potential error
          if training:
              device = gt_boxes.device
              d2_instances = filter_empty_instances(
                  d2_instances.to("cpu")
              ).to(device)
              d2_inputs["instances"] = d2_instances
          batched_d2_inputs.append(d2_inputs)
  
      return batched_d2_inputs
  
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 7 for calling the Detectron2Wrapper obj's underlying member method code with example usage: obj._convert_to_d2_inputs(batch_inputs, batch_data_samples, training) and returns: batched_d2_inputs