class_docstr: Detection Head of `DDOD <https://arxiv.org/abs/2107.02963>`_.
  
  DDOD head decomposes conjunctions lying in most current one-stage
  detectors via label assignment disentanglement, spatial feature
  disentanglement, and pyramid supervision disentanglement.
  
  Args:
      num_classes (int): Number of categories excluding the
          background category.
      in_channels (int): Number of channels in the input feature map.
      stacked_convs (int): The number of stacked Conv. Defaults to 4.
      conv_cfg (:obj:`ConfigDict` or dict, optional): Config dict for
          convolution layer. Defaults to None.
      use_dcn (bool): Use dcn, Same as ATSS when False. Defaults to True.
      norm_cfg (:obj:`ConfigDict` or dict): Normal config of ddod head.
          Defaults to dict(type='GN', num_groups=32, requires_grad=True).
      loss_iou (:obj:`ConfigDict` or dict): Config of IoU loss. Defaults to
          dict(type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0).
docstr: Get cls targets for DDOD head.
  
  This method is almost the same as `AnchorHead.get_targets()`.
  Besides returning the targets as the parent  method does,
  it also returns the anchors as the first element of the
  returned tuple.
  
  Args:
      anchor_list (list[Tensor]): anchors of each image.
      valid_flag_list (list[Tensor]): Valid flags of each image.
      num_level_anchors_list (list[Tensor]): Number of anchors of each
          scale level of all image.
      cls_score_list (list[Tensor]): Classification scores for all scale
          levels, each is a 4D-tensor, the channels number is
          num_base_priors * num_classes.
      bbox_pred_list (list[Tensor]): Box energies / deltas for all scale
          levels, each is a 4D-tensor, the channels number is
          num_base_priors * 4.
      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.
      unmap_outputs (bool): Whether to map outputs back to the original
          set of anchors.
  
  Return:
      tuple[Tensor]: A tuple of cls targets components.
docstr_tok: ["Get","cls","targets","for","DDOD","head",".","This","method","is","almost","the","same","as","`","AnchorHead.get_targets","(",")","`",".","Besides","returning","the","targets","as","the","parent","method","does",",","it","also","returns","the","anchors","as","the","first","element","of","the","returned","tuple",".","Args",":","anchor_list","(","list","[","Tensor","]",")",":","anchors","of","each","image",".","valid_flag_list","(","list","[","Tensor","]",")",":","Valid","flags","of","each","image",".","num_level_anchors_list","(","list","[","Tensor","]",")",":","Number","of","anchors","of","each","scale","level","of","all","image",".","cls_score_list","(","list","[","Tensor","]",")",":","Classification","scores","for","all","scale","levels",",","each","is","a","4D-tensor",",","the","channels","number","is","num_base_priors","*","num_classes",".","bbox_pred_list","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","all","scale","levels",",","each","is","a","4D-tensor",",","the","channels","number","is","num_base_priors","*","4.","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",".","unmap_outputs","(","bool",")",":","Whether","to","map","outputs","back","to","the","original","set","of","anchors",".","Return",":","tuple","[","Tensor","]",":","A","tuple","of","cls","targets","components","."]
code: def get_cls_targets(
      self,
      anchor_list: List[Tensor],
      valid_flag_list: List[Tensor],
      num_level_anchors_list: List[int],
      cls_score_list: List[Tensor],
      bbox_pred_list: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
      unmap_outputs: bool = True,
  ) -> tuple:
      """Get cls targets for DDOD head.
  
      This method is almost the same as `AnchorHead.get_targets()`.
      Besides returning the targets as the parent  method does,
      it also returns the anchors as the first element of the
      returned tuple.
  
      Args:
          anchor_list (list[Tensor]): anchors of each image.
          valid_flag_list (list[Tensor]): Valid flags of each image.
          num_level_anchors_list (list[Tensor]): Number of anchors of each
              scale level of all image.
          cls_score_list (list[Tensor]): Classification scores for all scale
              levels, each is a 4D-tensor, the channels number is
              num_base_priors * num_classes.
          bbox_pred_list (list[Tensor]): Box energies / deltas for all scale
              levels, each is a 4D-tensor, the channels number is
              num_base_priors * 4.
          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.
          unmap_outputs (bool): Whether to map outputs back to the original
              set of anchors.
  
      Return:
          tuple[Tensor]: A tuple of cls targets components.
      """
      (
          all_anchors,
          all_labels,
          all_label_weights,
          all_bbox_targets,
          all_bbox_weights,
          pos_inds_list,
          neg_inds_list,
          sampling_results_list,
      ) = multi_apply(
          self._get_targets_single,
          anchor_list,
          valid_flag_list,
          cls_score_list,
          bbox_pred_list,
          num_level_anchors_list,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore,
          unmap_outputs=unmap_outputs,
          is_cls_assigner=True,
      )
      # Get `avg_factor` of all images, which calculate in `SamplingResult`.
      # When using sampling method, avg_factor is usually the sum of
      # positive and negative priors. When using `PseudoSampler`,
      # `avg_factor` is usually equal to the number of positive priors.
      avg_factor = sum(
          [results.avg_factor for results in sampling_results_list]
      )
      # split targets to a list w.r.t. multiple levels
      anchors_list = images_to_levels(
          all_anchors, num_level_anchors_list[0]
      )
      labels_list = images_to_levels(
          all_labels, num_level_anchors_list[0]
      )
      label_weights_list = images_to_levels(
          all_label_weights, num_level_anchors_list[0]
      )
      bbox_targets_list = images_to_levels(
          all_bbox_targets, num_level_anchors_list[0]
      )
      bbox_weights_list = images_to_levels(
          all_bbox_weights, num_level_anchors_list[0]
      )
      return (
          anchors_list,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          avg_factor,
      )
  
imports: from typing import List, Optional, Sequence, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule, Scale
  from mmengine.model import bias_init_with_prob, normal_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import bbox_overlaps
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList, reduce_mean
  from ..task_modules.prior_generators import anchor_inside_flags
  from ..utils import images_to_levels, multi_apply, unmap
  from .anchor_head import AnchorHead
label_desc: Use image node_id 11 for calling the DDODHead obj's underlying member method code with example usage: obj.get_cls_targets(anchor_list, valid_flag_list, num_level_anchors_list, cls_score_list, bbox_pred_list, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore, unmap_outputs) and returns: anchors_list,  labels_list,  label_weights_list,  bbox_targets_list,  bbox_weights_list,  avg_factor