class_docstr: Localization distillation Head. (Short description)
  
  It utilizes the learned bbox distributions to transfer the localization
  dark knowledge from teacher to student. Original paper: `Localization
  Distillation for Object Detection. <https://arxiv.org/abs/2102.12252>`_
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      loss_ld (:obj:`ConfigDict` or dict): Config of Localization
          Distillation Loss (LD), T is the temperature for distillation.
class_docstr_tok: ["Localization","distillation","Head",".","(","Short","description",")","It","utilizes","the","learned","bbox","distributions","to","transfer","the","localization","dark","knowledge","from","teacher","to","student",".","Original","paper",":","`","Localization","Distillation","for","Object","Detection",".","<","https",":","\/\/arxiv.org\/abs\/2102.12252",">","`","_","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","loss_ld","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","Localization","Distillation","Loss","(","LD",")",",","T","is","the","temperature","for","distillation","."]
docstr: Compute losses of the head.
  
  Args:
      cls_scores (list[Tensor]): Cls and quality scores for each scale
          level has shape (N, num_classes, H, W).
      bbox_preds (list[Tensor]): Box distribution logits for each scale
          level with shape (N, 4*(n+1), H, W), n is max value of integral
          set.
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance.  It usually includes ``bboxes`` and ``labels``
          attributes.
      soft_targets (list[Tensor]): Soft BBox regression targets.
      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[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Compute","losses","of","the","head",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Cls","and","quality","scores","for","each","scale","level","has","shape","(","N",",","num_classes",",","H",",","W",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","distribution","logits","for","each","scale","level","with","shape","(","N",",","4","*","(","n+1",")",",","H",",","W",")",",","n","is","max","value","of","integral","set",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","soft_targets","(","list","[","Tensor","]",")",":","Soft","BBox","regression","targets",".","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","[","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],
      soft_targets: List[Tensor],
      batch_gt_instances_ignore: OptInstanceList = None,
  ) -> dict:
      """Compute losses of the head.
  
      Args:
          cls_scores (list[Tensor]): Cls and quality scores for each scale
              level has shape (N, num_classes, H, W).
          bbox_preds (list[Tensor]): Box distribution logits for each scale
              level with shape (N, 4*(n+1), H, W), n is max value of integral
              set.
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance.  It usually includes ``bboxes`` and ``labels``
              attributes.
          soft_targets (list[Tensor]): Soft BBox regression targets.
          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[str, Tensor]: A dictionary of loss components.
      """
  
      featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores]
      assert len(featmap_sizes) == self.prior_generator.num_levels
  
      device = cls_scores[0].device
      anchor_list, valid_flag_list = self.get_anchors(
          featmap_sizes, batch_img_metas, device=device
      )
  
      cls_reg_targets = self.get_targets(
          anchor_list,
          valid_flag_list,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore=batch_gt_instances_ignore,
      )
  
      (
          anchor_list,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          avg_factor,
      ) = cls_reg_targets
  
      avg_factor = reduce_mean(
          torch.tensor(avg_factor, dtype=torch.float, device=device)
      ).item()
  
      (
          losses_cls,
          losses_bbox,
          losses_dfl,
          losses_ld,
          avg_factor,
      ) = multi_apply(
          self.loss_by_feat_single,
          anchor_list,
          cls_scores,
          bbox_preds,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          self.prior_generator.strides,
          soft_targets,
          avg_factor=avg_factor,
      )
  
      avg_factor = sum(avg_factor) + 1e-6
      avg_factor = reduce_mean(avg_factor).item()
      losses_bbox = [x / avg_factor for x in losses_bbox]
      losses_dfl = [x / avg_factor for x in losses_dfl]
      return dict(
          loss_cls=losses_cls,
          loss_bbox=losses_bbox,
          loss_dfl=losses_dfl,
          loss_ld=losses_ld,
      )
  
file_path: mmdetection/mmdet/models/dense_heads/ld_head.py
imports: from typing import List, Tuple
  import torch
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_overlaps
  from mmdet.utils import ConfigType, InstanceList, OptInstanceList, reduce_mean
  from ..utils import multi_apply, unpack_gt_instances
  from .gfl_head import GFLHead
label_desc: Use image node_id 4 for calling the LDHead obj's underlying member method code with example usage: obj.loss_by_feat(cls_scores, bbox_preds, batch_gt_instances, batch_img_metas, soft_targets, batch_gt_instances_ignore) and returns: dict