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 of a single scale level based on the features
  extracted by the detection head.
  
  Args:
      pred_map (Tensor): Raw predictions for a single level.
      target_map (Tensor): The Ground-Truth target for a single level.
      neg_map (Tensor): The negative masks for a single level.
  
  Returns:
      tuple:
          loss_cls (Tensor): Classification loss.
          loss_conf (Tensor): Confidence loss.
          loss_xy (Tensor): Regression loss of x, y coordinate.
          loss_wh (Tensor): Regression loss of w, h coordinate.
docstr_tok: ["Calculate","the","loss","of","a","single","scale","level","based","on","the","features","extracted","by","the","detection","head",".","Args",":","pred_map","(","Tensor",")",":","Raw","predictions","for","a","single","level",".","target_map","(","Tensor",")",":","The","Ground-Truth","target","for","a","single","level",".","neg_map","(","Tensor",")",":","The","negative","masks","for","a","single","level",".","Returns",":","tuple",":","loss_cls","(","Tensor",")",":","Classification","loss",".","loss_conf","(","Tensor",")",":","Confidence","loss",".","loss_xy","(","Tensor",")",":","Regression","loss","of","x",",","y","coordinate",".","loss_wh","(","Tensor",")",":","Regression","loss","of","w",",","h","coordinate","."]
code: def loss_by_feat_single(
      self, pred_map: Tensor, target_map: Tensor, neg_map: Tensor
  ) -> tuple:
      """Calculate the loss of a single scale level based on the features
      extracted by the detection head.
  
      Args:
          pred_map (Tensor): Raw predictions for a single level.
          target_map (Tensor): The Ground-Truth target for a single level.
          neg_map (Tensor): The negative masks for a single level.
  
      Returns:
          tuple:
              loss_cls (Tensor): Classification loss.
              loss_conf (Tensor): Confidence loss.
              loss_xy (Tensor): Regression loss of x, y coordinate.
              loss_wh (Tensor): Regression loss of w, h coordinate.
      """
  
      num_imgs = len(pred_map)
      pred_map = pred_map.permute(0, 2, 3, 1).reshape(
          num_imgs, -1, self.num_attrib
      )
      neg_mask = neg_map.float()
      pos_mask = target_map[..., 4]
      pos_and_neg_mask = neg_mask + pos_mask
      pos_mask = pos_mask.unsqueeze(dim=-1)
      if torch.max(pos_and_neg_mask) > 1.0:
          warnings.warn("There is overlap between pos and neg sample.")
          pos_and_neg_mask = pos_and_neg_mask.clamp(min=0.0, max=1.0)
  
      pred_xy = pred_map[..., :2]
      pred_wh = pred_map[..., 2:4]
      pred_conf = pred_map[..., 4]
      pred_label = pred_map[..., 5:]
  
      target_xy = target_map[..., :2]
      target_wh = target_map[..., 2:4]
      target_conf = target_map[..., 4]
      target_label = target_map[..., 5:]
  
      loss_cls = self.loss_cls(
          pred_label, target_label, weight=pos_mask
      )
      loss_conf = self.loss_conf(
          pred_conf, target_conf, weight=pos_and_neg_mask
      )
      loss_xy = self.loss_xy(pred_xy, target_xy, weight=pos_mask)
      loss_wh = self.loss_wh(pred_wh, target_wh, weight=pos_mask)
  
      return loss_cls, loss_conf, loss_xy, loss_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 9 for calling the YOLOV3Head obj's underlying member method code with example usage: obj.loss_by_feat_single(pred_map, target_map, neg_map) and returns: loss_cls,  loss_conf,  loss_xy,  loss_wh