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","."]
code: def __init__(
      self,
      backbone: ConfigType,
      neck: OptConfigType = None,
      rpn_head: OptConfigType = None,
      roi_head: OptConfigType = None,
      train_cfg: OptConfigType = None,
      test_cfg: OptConfigType = None,
      data_preprocessor: OptConfigType = None,
      init_cfg: OptMultiConfig = None,
  ) -> None:
      super().__init__(
          data_preprocessor=data_preprocessor, init_cfg=init_cfg
      )
      self.backbone = MODELS.build(backbone)
  
      if neck is not None:
          self.neck = MODELS.build(neck)
  
      if rpn_head is not None:
          rpn_train_cfg = (
              train_cfg.rpn if train_cfg is not None else None
          )
          rpn_head_ = rpn_head.copy()
          rpn_head_.update(
              train_cfg=rpn_train_cfg, test_cfg=test_cfg.rpn
          )
          rpn_head_num_classes = rpn_head_.get("num_classes", None)
          if rpn_head_num_classes is None:
              rpn_head_.update(num_classes=1)
          else:
              if rpn_head_num_classes != 1:
                  warnings.warn(
                      "The `num_classes` should be 1 in RPN, but get "
                      f"{rpn_head_num_classes}, please set "
                      "rpn_head.num_classes = 1 in your config file."
                  )
                  rpn_head_.update(num_classes=1)
          self.rpn_head = MODELS.build(rpn_head_)
  
      if roi_head is not None:
          # update train and test cfg here for now
          # TODO: refactor assigner & sampler
          rcnn_train_cfg = (
              train_cfg.rcnn if train_cfg is not None else None
          )
          roi_head.update(train_cfg=rcnn_train_cfg)
          roi_head.update(test_cfg=test_cfg.rcnn)
          self.roi_head = MODELS.build(roi_head)
  
      self.train_cfg = train_cfg
      self.test_cfg = test_cfg
  
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 1 to create a new TwoStageDetector object from inherited base classes: BaseDetector with example: obj = TwoStageDetector(backbone, neck, rpn_head, roi_head, train_cfg, test_cfg, data_preprocessor, init_cfg)