class_docstr: Implementation of RPN head.
  
  Args:
      in_channels (int): Number of channels in the input feature map.
      num_classes (int): Number of categories excluding the background
          category. Defaults to 1.
      init_cfg (:obj:`ConfigDict` or list[:obj:`ConfigDict`] or dict or             list[dict]): Initialization config dict.
      num_convs (int): Number of convolution layers in the head.
          Defaults to 1.
docstr: Calculate the loss based on the features extracted by the detection
  head.
  
  Args:
      cls_scores (list[Tensor]): Box scores for each scale level,
          has shape (N, num_anchors * num_classes, H, W).
      bbox_preds (list[Tensor]): Box energies / deltas for each scale
          level with shape (N, num_anchors * 4, H, W).
      batch_gt_instances (list[obj:InstanceData]): Batch of gt_instance.
          It usually includes ``bboxes`` and ``labels`` attributes.
      batch_img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      batch_gt_instances_ignore (list[obj:InstanceData], Optional):
          Batch of gt_instances_ignore. It includes ``bboxes`` attribute
          data that is ignored during training and testing.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Calculate","the","loss","based","on","the","features","extracted","by","the","detection","head",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","for","each","scale","level",",","has","shape","(","N",",","num_anchors","*","num_classes",",","H",",","W",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","each","scale","level","with","shape","(","N",",","num_anchors","*","4",",","H",",","W",")",".","batch_gt_instances","(","list","[","obj",":","InstanceData","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","batch_img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","batch_gt_instances_ignore","(","list","[","obj",":","InstanceData","]",",","Optional",")",":","Batch","of","gt_instances_ignore",".","It","includes","``","bboxes","``","attribute","data","that","is","ignored","during","training","and","testing",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss_by_feat(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
  ) -> dict:
      """Calculate the loss based on the features extracted by the detection
      head.
  
      Args:
          cls_scores (list[Tensor]): Box scores for each scale level,
              has shape (N, num_anchors * num_classes, H, W).
          bbox_preds (list[Tensor]): Box energies / deltas for each scale
              level with shape (N, num_anchors * 4, H, W).
          batch_gt_instances (list[obj:InstanceData]): Batch of gt_instance.
              It usually includes ``bboxes`` and ``labels`` attributes.
          batch_img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          batch_gt_instances_ignore (list[obj:InstanceData], Optional):
              Batch of gt_instances_ignore. It includes ``bboxes`` attribute
              data that is ignored during training and testing.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      losses = super().loss_by_feat(
          cls_scores,
          bbox_preds,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore=batch_gt_instances_ignore,
      )
      return dict(
          loss_rpn_cls=losses["loss_cls"],
          loss_rpn_bbox=losses["loss_bbox"],
      )
  
imports: import copy
  from typing import List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmcv.ops import batched_nms
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import cat_boxes, empty_box_as, get_box_tensor, get_box_wh, scale_boxes
  from mmdet.utils import InstanceList, MultiConfig, OptInstanceList
  from .anchor_head import AnchorHead
label_desc: Use image node_id 4 for calling the RPNHead obj's underlying member method code with example usage: obj.loss_by_feat(cls_scores, bbox_preds, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: dict