class_docstr: Base class for two-stage detectors.
  
  Two-stage detectors typically consisting of a region proposal network and a
  task-specific regression head.
class_docstr_tok: ["Base","class","for","two-stage","detectors",".","Two-stage","detectors","typically","consisting","of","a","region","proposal","network","and","a","task-specific","regression","head","."]
docstr: Predict results from a batch of inputs and data samples with post-
  processing.
  
  Args:
      batch_inputs (Tensor): Inputs with shape (N, C, H, W).
      batch_data_samples (List[:obj:`DetDataSample`]): The Data
          Samples. It usually includes information such as
          `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
      rescale (bool): Whether to rescale the results.
          Defaults to True.
  
  Returns:
      list[:obj:`DetDataSample`]: Return the detection results of the
      input images. The returns value is DetDataSample,
      which usually contain 'pred_instances'. And the
      ``pred_instances`` usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
              (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
              (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
              the last dimension 4 arrange as (x1, y1, x2, y2).
          - masks (Tensor): Has a shape (num_instances, H, W).
docstr_tok: ["Predict","results","from","a","batch","of","inputs","and","data","samples","with","post-","processing",".","Args",":","batch_inputs","(","Tensor",")",":","Inputs","with","shape","(","N",",","C",",","H",",","W",")",".","batch_data_samples","(","List","[",":","obj",":","`","DetDataSample","`","]",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",",","`","gt_panoptic_seg","`","and","`","gt_sem_seg","`",".","rescale","(","bool",")",":","Whether","to","rescale","the","results",".","Defaults","to","True",".","Returns",":","list","[",":","obj",":","`","DetDataSample","`","]",":","Return","the","detection","results","of","the","input","images",".","The","returns","value","is","DetDataSample",",","which","usually","contain","'pred_instances","'",".","And","the","``","pred_instances","``","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")",".","-","masks","(","Tensor",")",":","Has","a","shape","(","num_instances",",","H",",","W",")","."]
code: def predict(
      self,
      batch_inputs: Tensor,
      batch_data_samples: SampleList,
      rescale: bool = True,
  ) -> SampleList:
      """Predict results from a batch of inputs and data samples with post-
      processing.
  
      Args:
          batch_inputs (Tensor): Inputs with shape (N, C, H, W).
          batch_data_samples (List[:obj:`DetDataSample`]): The Data
              Samples. It usually includes information such as
              `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
          rescale (bool): Whether to rescale the results.
              Defaults to True.
  
      Returns:
          list[:obj:`DetDataSample`]: Return the detection results of the
          input images. The returns value is DetDataSample,
          which usually contain 'pred_instances'. And the
          ``pred_instances`` usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                  (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                  (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                  the last dimension 4 arrange as (x1, y1, x2, y2).
              - masks (Tensor): Has a shape (num_instances, H, W).
      """
  
      assert self.with_bbox, "Bbox head must be implemented."
      x = self.extract_feat(batch_inputs)
  
      # If there are no pre-defined proposals, use RPN to get proposals
      if batch_data_samples[0].get("proposals", None) is None:
          rpn_results_list = self.rpn_head.predict(
              x, batch_data_samples, rescale=False
          )
      else:
          rpn_results_list = [
              data_sample.proposals
              for data_sample in batch_data_samples
          ]
  
      results_list = self.roi_head.predict(
          x, rpn_results_list, batch_data_samples, rescale=rescale
      )
  
      batch_data_samples = self.add_pred_to_datasample(
          batch_data_samples, results_list
      )
      return batch_data_samples
  
file_path: mmdetection/mmdet/models/detectors/two_stage.py
imports: import copy
  import warnings
  from typing import List, Tuple, Union
  import torch
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig
  from .base import BaseDetector
label_desc: Use image node_id 8 for calling the TwoStageDetector obj's underlying member method code with example usage: obj.predict(batch_inputs, batch_data_samples, rescale) and returns: batch_data_samples