class_docstr: Implementation of `Grid Head <https://arxiv.org/abs/1811.12030>`_
  
  Args:
      grid_points (int): The number of grid points. Defaults to 9.
      num_convs (int): The number of convolution layers. Defaults to 8.
      roi_feat_size (int): RoI feature size. Default to 14.
      in_channels (int): The channel number of inputs features.
          Defaults to 256.
      conv_kernel_size (int): The kernel size of convolution layers.
          Defaults to 3.
      point_feat_channels (int): The number of channels of each point
          features. Defaults to 64.
      class_agnostic (bool): Whether use class agnostic classification.
          If so, the output channels of logits will be 1. Defaults to False.
      loss_grid (:obj:`ConfigDict` or dict): Config of grid loss.
      conv_cfg (:obj:`ConfigDict` or dict, optional) dictionary to
          construct and config conv layer.
      norm_cfg (:obj:`ConfigDict` or dict): dictionary to construct and
          config norm layer.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             dict]): Initialization config dict.
docstr: Calculate the loss based on the features extracted by the grid head.
  
  Args:
      grid_pred (dict[str, Tensor]): Outputs of grid_head forward.
      sample_idx (Tensor): The sampling index of ``grid_pred``.
      sampling_results (List[obj:SamplingResult]): Assign results of
          all images in a batch after sampling.
      rcnn_train_cfg (obj:`ConfigDict`): `train_cfg` of RCNN.
  
  Returns:
      dict: A dictionary of loss and targets components.
docstr_tok: ["Calculate","the","loss","based","on","the","features","extracted","by","the","grid","head",".","Args",":","grid_pred","(","dict","[","str",",","Tensor","]",")",":","Outputs","of","grid_head","forward",".","sample_idx","(","Tensor",")",":","The","sampling","index","of","``","grid_pred","``",".","sampling_results","(","List","[","obj",":","SamplingResult","]",")",":","Assign","results","of","all","images","in","a","batch","after","sampling",".","rcnn_train_cfg","(","obj",":","`","ConfigDict","`",")",":","`","train_cfg","`","of","RCNN",".","Returns",":","dict",":","A","dictionary","of","loss","and","targets","components","."]
code: def loss(
      self,
      grid_pred: Tensor,
      sample_idx: Tensor,
      sampling_results: List[SamplingResult],
      rcnn_train_cfg: ConfigDict,
  ) -> dict:
      """Calculate the loss based on the features extracted by the grid head.
  
      Args:
          grid_pred (dict[str, Tensor]): Outputs of grid_head forward.
          sample_idx (Tensor): The sampling index of ``grid_pred``.
          sampling_results (List[obj:SamplingResult]): Assign results of
              all images in a batch after sampling.
          rcnn_train_cfg (obj:`ConfigDict`): `train_cfg` of RCNN.
  
      Returns:
          dict: A dictionary of loss and targets components.
      """
      grid_targets = self.get_targets(sampling_results, rcnn_train_cfg)
      grid_targets = grid_targets[sample_idx]
  
      loss_fused = self.loss_grid(grid_pred["fused"], grid_targets)
      loss_unfused = self.loss_grid(grid_pred["unfused"], grid_targets)
      loss_grid = loss_fused + loss_unfused
      return dict(loss_grid=loss_grid)
  
imports: from typing import Dict, List, Tuple
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.task_modules.samplers import SamplingResult
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType
label_desc: Use image node_id 5 for calling the GridHead obj's underlying member method code with example usage: obj.loss(grid_pred, sample_idx, sampling_results, rcnn_train_cfg) and returns: dict