class_docstr: Guided-Anchor-based RPN head.
class_docstr_tok: ["Guided-Anchor-based","RPN","head","."]
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).
      shape_preds (list[Tensor]): shape predictions for each scale
          level with shape (N, 1, H, W).
      loc_preds (list[Tensor]): location predictions for each scale
          level with shape (N, num_anchors * 2, 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.
          Defaults to None.
  
  Returns:
      dict: 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",")",".","shape_preds","(","list","[","Tensor","]",")",":","shape","predictions","for","each","scale","level","with","shape","(","N",",","1",",","H",",","W",")",".","loc_preds","(","list","[","Tensor","]",")",":","location","predictions","for","each","scale","level","with","shape","(","N",",","num_anchors","*","2",",","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",".","Defaults","to","None",".","Returns",":","dict",":","A","dictionary","of","loss","components","."]
code: def loss_by_feat(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      shape_preds: List[Tensor],
      loc_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).
          shape_preds (list[Tensor]): shape predictions for each scale
              level with shape (N, 1, H, W).
          loc_preds (list[Tensor]): location predictions for each scale
              level with shape (N, num_anchors * 2, 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.
              Defaults to None.
  
      Returns:
          dict: A dictionary of loss components.
      """
      losses = super().loss_by_feat(
          cls_scores,
          bbox_preds,
          shape_preds,
          loc_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"],
          loss_anchor_shape=losses["loss_shape"],
          loss_anchor_loc=losses["loss_loc"],
      )
  
file_path: mmdetection/mmdet/models/dense_heads/ga_rpn_head.py
imports: import copy
  from typing import List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.ops import nms
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptInstanceList
  from .guided_anchor_head import GuidedAnchorHead
label_desc: Use image node_id 4 for calling the GARPNHead obj's underlying member method code with example usage: obj.loss_by_feat(cls_scores, bbox_preds, shape_preds, loc_preds, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: dict