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: Compute common vars for regression and classification targets.
  
  Args:
      anchor_list (List[List[Tensor]]): anchors of each image.
      valid_flag_list (List[List[Tensor]]): Valid flags of each image.
      cls_scores (List[Tensor]): Classification scores for all scale
          levels, each is a 4D-tensor, the channels number is
          num_base_priors * num_classes.
      bbox_preds (list[Tensor]): Box energies / deltas for all scale
          levels, each is a 4D-tensor, the channels number is
          num_base_priors * 4.
      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.
  
  Return:
      tuple[Tensor]: A tuple of common loss vars.
docstr_tok: ["Compute","common","vars","for","regression","and","classification","targets",".","Args",":","anchor_list","(","List","[","List","[","Tensor","]","]",")",":","anchors","of","each","image",".","valid_flag_list","(","List","[","List","[","Tensor","]","]",")",":","Valid","flags","of","each","image",".","cls_scores","(","List","[","Tensor","]",")",":","Classification","scores","for","all","scale","levels",",","each","is","a","4D-tensor",",","the","channels","number","is","num_base_priors","*","num_classes",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","all","scale","levels",",","each","is","a","4D-tensor",",","the","channels","number","is","num_base_priors","*","4.","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",".","Return",":","tuple","[","Tensor","]",":","A","tuple","of","common","loss","vars","."]
code: def process_predictions_and_anchors(
      self,
      anchor_list: List[List[Tensor]],
      valid_flag_list: List[List[Tensor]],
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
  ) -> tuple:
      """Compute common vars for regression and classification targets.
  
      Args:
          anchor_list (List[List[Tensor]]): anchors of each image.
          valid_flag_list (List[List[Tensor]]): Valid flags of each image.
          cls_scores (List[Tensor]): Classification scores for all scale
              levels, each is a 4D-tensor, the channels number is
              num_base_priors * num_classes.
          bbox_preds (list[Tensor]): Box energies / deltas for all scale
              levels, each is a 4D-tensor, the channels number is
              num_base_priors * 4.
          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.
  
      Return:
          tuple[Tensor]: A tuple of common loss vars.
      """
      num_imgs = len(batch_img_metas)
      assert len(anchor_list) == len(valid_flag_list) == num_imgs
  
      # anchor number of multi levels
      num_level_anchors = [
          anchors.size(0) for anchors in anchor_list[0]
      ]
      num_level_anchors_list = [num_level_anchors] * num_imgs
  
      anchor_list_ = []
      valid_flag_list_ = []
      # concat all level anchors and flags to a single tensor
      for i in range(num_imgs):
          assert len(anchor_list[i]) == len(valid_flag_list[i])
          anchor_list_.append(torch.cat(anchor_list[i]))
          valid_flag_list_.append(torch.cat(valid_flag_list[i]))
  
      # compute targets for each image
      if batch_gt_instances_ignore is None:
          batch_gt_instances_ignore = [None for _ in range(num_imgs)]
  
      num_levels = len(cls_scores)
      cls_score_list = []
      bbox_pred_list = []
  
      mlvl_cls_score_list = [
          cls_score.permute(0, 2, 3, 1).reshape(
              num_imgs, -1, self.num_base_priors * self.cls_out_channels
          )
          for cls_score in cls_scores
      ]
      mlvl_bbox_pred_list = [
          bbox_pred.permute(0, 2, 3, 1).reshape(
              num_imgs, -1, self.num_base_priors * 4
          )
          for bbox_pred in bbox_preds
      ]
  
      for i in range(num_imgs):
          mlvl_cls_tensor_list = [
              mlvl_cls_score_list[j][i] for j in range(num_levels)
          ]
          mlvl_bbox_tensor_list = [
              mlvl_bbox_pred_list[j][i] for j in range(num_levels)
          ]
          cat_mlvl_cls_score = torch.cat(mlvl_cls_tensor_list, dim=0)
          cat_mlvl_bbox_pred = torch.cat(mlvl_bbox_tensor_list, dim=0)
          cls_score_list.append(cat_mlvl_cls_score)
          bbox_pred_list.append(cat_mlvl_bbox_pred)
      return (
          anchor_list_,
          valid_flag_list_,
          num_level_anchors_list,
          cls_score_list,
          bbox_pred_list,
          batch_gt_instances_ignore,
      )
  
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 10 for calling the DDODHead obj's underlying member method code with example usage: obj.process_predictions_and_anchors(anchor_list, valid_flag_list, cls_scores, bbox_preds, batch_img_metas, batch_gt_instances_ignore) and returns: anchor_list_,  valid_flag_list_,  num_level_anchors_list,  cls_score_list,  bbox_pred_list,  batch_gt_instances_ignore