class_docstr: Implementation of `Grid RoI Head <https://arxiv.org/abs/1811.12030>`_
  
  Args:
      grid_roi_extractor (:obj:`ConfigDict` or dict): Config of
          roi extractor.
      grid_head (:obj:`ConfigDict` or dict): Config of grid head
class_docstr_tok: ["Implementation","of","`","Grid","RoI","Head","<","https",":","\/\/arxiv.org\/abs\/1811.12030",">","`","_","Args",":","grid_roi_extractor","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","roi","extractor",".","grid_head","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","grid","head"]
docstr: Perform forward propagation and loss calculation of the detection
  roi on the features of the upstream network.
  
  Args:
      x (tuple[Tensor]): List of multi-level img features.
      rpn_results_list (list[:obj:`InstanceData`]): List of region
          proposals.
      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: ["Perform","forward","propagation","and","loss","calculation","of","the","detection","roi","on","the","features","of","the","upstream","network",".","Args",":","x","(","tuple","[","Tensor","]",")",":","List","of","multi-level","img","features",".","rpn_results_list","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","List","of","region","proposals",".","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,
      x: Tuple[Tensor],
      rpn_results_list: InstanceList,
      batch_data_samples: SampleList,
      **kwargs,
  ) -> dict:
      """Perform forward propagation and loss calculation of the detection
      roi on the features of the upstream network.
  
      Args:
          x (tuple[Tensor]): List of multi-level img features.
          rpn_results_list (list[:obj:`InstanceData`]): List of region
              proposals.
          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
      """
      assert len(rpn_results_list) == len(batch_data_samples)
      outputs = unpack_gt_instances(batch_data_samples)
      (
          batch_gt_instances,
          batch_gt_instances_ignore,
          batch_img_metas,
      ) = outputs
  
      # assign gts and sample proposals
      num_imgs = len(batch_data_samples)
      sampling_results = []
      for i in range(num_imgs):
          # rename rpn_results.bboxes to rpn_results.priors
          rpn_results = rpn_results_list[i]
          rpn_results.priors = rpn_results.pop("bboxes")
  
          assign_result = self.bbox_assigner.assign(
              rpn_results,
              batch_gt_instances[i],
              batch_gt_instances_ignore[i],
          )
          sampling_result = self.bbox_sampler.sample(
              assign_result,
              rpn_results,
              batch_gt_instances[i],
              feats=[lvl_feat[i][None] for lvl_feat in x],
          )
          sampling_results.append(sampling_result)
  
      losses = dict()
      # bbox head loss
      if self.with_bbox:
          bbox_results = self.bbox_loss(
              x, sampling_results, batch_img_metas
          )
          losses.update(bbox_results["loss_bbox"])
  
      # mask head forward and loss
      if self.with_mask:
          mask_results = self.mask_loss(
              x,
              sampling_results,
              bbox_results["bbox_feats"],
              batch_gt_instances,
          )
          losses.update(mask_results["loss_mask"])
  
      return losses
  
file_path: mmdetection/mmdet/models/roi_heads/grid_roi_head.py
imports: from typing import List, Optional, Tuple
  import torch
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox2roi
  from mmdet.utils import ConfigType, InstanceList
  from ..task_modules.samplers import SamplingResult
  from ..utils.misc import unpack_gt_instances
  from .standard_roi_head import StandardRoIHead
label_desc: Use image node_id 4 for calling the GridRoIHead obj's underlying member method code with example usage: obj.loss(x, rpn_results_list, batch_data_samples) and returns: losses