class_docstr: YOLOV3Head Paper link: https://arxiv.org/abs/1804.02767.
  
  Args:
      num_classes (int): The number of object classes (w/o background)
      in_channels (Sequence[int]): Number of input channels per scale.
      out_channels (Sequence[int]): The number of output channels per scale
          before the final 1x1 layer. Default: (1024, 512, 256).
      anchor_generator (:obj:`ConfigDict` or dict): Config dict for anchor
          generator.
      bbox_coder (:obj:`ConfigDict` or dict): Config of bounding box coder.
      featmap_strides (Sequence[int]): The stride of each scale.
          Should be in descending order. Defaults to (32, 16, 8).
      one_hot_smoother (float): Set a non-zero value to enable label-smooth
          Defaults to 0.
      conv_cfg (:obj:`ConfigDict` or dict, optional): Config dict for
          convolution layer. Defaults to None.
      norm_cfg (:obj:`ConfigDict` or dict): Dictionary to construct and
          config norm layer. Defaults to dict(type='BN', requires_grad=True).
      act_cfg (:obj:`ConfigDict` or dict): Config dict for activation layer.
          Defaults to dict(type='LeakyReLU', negative_slope=0.1).
      loss_cls (:obj:`ConfigDict` or dict): Config of classification loss.
      loss_conf (:obj:`ConfigDict` or dict): Config of confidence loss.
      loss_xy (:obj:`ConfigDict` or dict): Config of xy coordinate loss.
      loss_wh (:obj:`ConfigDict` or dict): Config of wh coordinate loss.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config of
          YOLOV3 head. Defaults to None.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config of
          YOLOV3 head. Defaults to None.
docstr: Calculate the loss based on the features extracted by the detection
  head.
  
  Args:
      pred_maps (list[Tensor]): Prediction map for each scale level,
          shape (N, num_anchors * num_attrib, 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",":","pred_maps","(","list","[","Tensor","]",")",":","Prediction","map","for","each","scale","level",",","shape","(","N",",","num_anchors","*","num_attrib",",","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,
      pred_maps: Sequence[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:
          pred_maps (list[Tensor]): Prediction map for each scale level,
              shape (N, num_anchors * num_attrib, 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.
      """
      num_imgs = len(batch_img_metas)
      device = pred_maps[0][0].device
  
      featmap_sizes = [
          pred_maps[i].shape[-2:] for i in range(self.num_levels)
      ]
      mlvl_anchors = self.prior_generator.grid_priors(
          featmap_sizes, device=device
      )
      anchor_list = [mlvl_anchors for _ in range(num_imgs)]
  
      responsible_flag_list = []
      for img_id in range(num_imgs):
          responsible_flag_list.append(
              self.responsible_flags(
                  featmap_sizes,
                  batch_gt_instances[img_id].bboxes,
                  device,
              )
          )
  
      target_maps_list, neg_maps_list = self.get_targets(
          anchor_list, responsible_flag_list, batch_gt_instances
      )
  
      losses_cls, losses_conf, losses_xy, losses_wh = multi_apply(
          self.loss_by_feat_single,
          pred_maps,
          target_maps_list,
          neg_maps_list,
      )
  
      return dict(
          loss_cls=losses_cls,
          loss_conf=losses_conf,
          loss_xy=losses_xy,
          loss_wh=losses_wh,
      )
  
imports: import copy
  import warnings
  from typing import List, Optional, Sequence, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, is_norm
  from mmengine.model import bias_init_with_prob, constant_init, normal_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList
  from ..task_modules.samplers import PseudoSampler
  from ..utils import filter_scores_and_topk, images_to_levels, multi_apply
  from .base_dense_head import BaseDenseHead
label_desc: Use image node_id 8 for calling the YOLOV3Head obj's underlying member method code with example usage: obj.loss_by_feat(pred_maps, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore) and returns: dict