class_docstr: Implementation of Region Proposal Network.
  
  Args:
      backbone (:obj:`ConfigDict` or dict): The backbone config.
      neck (:obj:`ConfigDict` or dict): The neck config.
      bbox_head (:obj:`ConfigDict` or dict): The bbox head config.
      train_cfg (:obj:`ConfigDict` or dict, optional): The training config.
      test_cfg (:obj:`ConfigDict` or dict, optional): The testing config.
      data_preprocessor (:obj:`ConfigDict` or dict, optional): Config of
          :class:`DetDataPreprocessor` to process the input data.
          Defaults to None.
      init_cfg (:obj:`ConfigDict` or list[:obj:`ConfigDict`] or dict or
          list[dict], optional): Initialization config dict.
          Defaults to None.
class_docstr_tok: ["Implementation","of","Region","Proposal","Network",".","Args",":","backbone","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","backbone","config",".","neck","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","neck","config",".","bbox_head","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","The","bbox","head","config",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","The","training","config",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","The","testing","config",".","data_preprocessor","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","of",":","class",":","`","DetDataPreprocessor","`","to","process","the","input","data",".","Defaults","to","None",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","list","[",":","obj",":","`","ConfigDict","`","]","or","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","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[str, Tensor]: 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","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss(
      self, batch_inputs: Tensor, batch_data_samples: SampleList
  ) -> dict:
      """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[str, Tensor]: A dictionary of loss components.
      """
      x = self.extract_feat(batch_inputs)
  
      # set cat_id of gt_labels to 0 in RPN
      rpn_data_samples = copy.deepcopy(batch_data_samples)
      for data_sample in rpn_data_samples:
          data_sample.gt_instances.labels = torch.zeros_like(
              data_sample.gt_instances.labels
          )
  
      losses = self.bbox_head.loss(x, rpn_data_samples)
      return losses
  
file_path: mmdetection/mmdet/models/detectors/rpn.py
imports: import copy
  import warnings
  import torch
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.utils import ConfigType, OptConfigType, OptMultiConfig
  from .single_stage import SingleStageDetector
label_desc: Use image node_id 2 for calling the RPN obj's underlying member method code with example usage: obj.loss(batch_inputs, batch_data_samples) and returns: losses