class_docstr: Side-Aware Boundary Localization (SABL) for RetinaNet.
  
  The anchor generation, assigning and sampling in SABLRetinaHead
  are the same as GuidedAnchorHead for guided anchoring.
  
  Please refer to https://arxiv.org/abs/1912.04260 for more details.
  
  Args:
      num_classes (int): Number of classes.
      in_channels (int): Number of channels in the input feature map.
      stacked_convs (int): Number of Convs for classification and
          regression branches. Defaults to 4.
      feat_channels (int): Number of hidden channels. Defaults to 256.
      approx_anchor_generator (:obj:`ConfigType` or dict): Config dict for
          approx generator.
      square_anchor_generator (:obj:`ConfigDict` or dict): Config dict for
          square generator.
      conv_cfg (:obj:`ConfigDict` or dict, optional): Config dict for
          ConvModule. Defaults to None.
      norm_cfg (:obj:`ConfigDict` or dict, optional): Config dict for
          Norm Layer. Defaults to None.
      bbox_coder (:obj:`ConfigDict` or dict): Config dict for bbox coder.
      reg_decoded_bbox (bool): If true, the regression loss would be
          applied directly on decoded bounding boxes, converting both
          the predicted boxes and regression targets to absolute
          coordinates format. Default False. It should be ``True`` when
          using ``IoULoss``, ``GIoULoss``, or ``DIoULoss`` in the bbox head.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config of
          SABLRetinaHead.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config of
          SABLRetinaHead.
      loss_cls (:obj:`ConfigDict` or dict): Config of classification loss.
      loss_bbox_cls (:obj:`ConfigDict` or dict): Config of classification
          loss for bbox branch.
      loss_bbox_reg (:obj:`ConfigDict` or dict): Config of regression loss
          for bbox branch.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             dict], optional): Initialization config dict.
class_docstr_tok: ["Side-Aware","Boundary","Localization","(","SABL",")","for","RetinaNet",".","The","anchor","generation",",","assigning","and","sampling","in","SABLRetinaHead","are","the","same","as","GuidedAnchorHead","for","guided","anchoring",".","Please","refer","to","https",":","\/\/arxiv.org\/abs\/1912.04260","for","more","details",".","Args",":","num_classes","(","int",")",":","Number","of","classes",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","stacked_convs","(","int",")",":","Number","of","Convs","for","classification","and","regression","branches",".","Defaults","to","4.","feat_channels","(","int",")",":","Number","of","hidden","channels",".","Defaults","to","256.","approx_anchor_generator","(",":","obj",":","`","ConfigType","`","or","dict",")",":","Config","dict","for","approx","generator",".","square_anchor_generator","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","square","generator",".","conv_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","dict","for","ConvModule",".","Defaults","to","None",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","dict","for","Norm","Layer",".","Defaults","to","None",".","bbox_coder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","bbox","coder",".","reg_decoded_bbox","(","bool",")",":","If","true",",","the","regression","loss","would","be","applied","directly","on","decoded","bounding","boxes",",","converting","both","the","predicted","boxes","and","regression","targets","to","absolute","coordinates","format",".","Default","False",".","It","should","be","``","True","``","when","using","``","IoULoss","``",",","``","GIoULoss","``",",","or","``","DIoULoss","``","in","the","bbox","head",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Training","config","of","SABLRetinaHead",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Testing","config","of","SABLRetinaHead",".","loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","classification","loss",".","loss_bbox_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","classification","loss","for","bbox","branch",".","loss_bbox_reg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","regression","loss","for","bbox","branch",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[",":","obj",":","`","ConfigDict","`","or","dict","]",",","optional",")",":","Initialization","config","dict","."]
docstr: Compute bucketing targets.
  
  Args:
      approx_list (list[list[Tensor]]): Multi level approxs of each
          image.
      inside_flag_list (list[list[Tensor]]): Multi level inside flags of
          each image.
      square_list (list[list[Tensor]]): Multi level squares of each
          image.
      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. Defaults to True.
  
  Returns:
      tuple: Returns a tuple containing learning targets.
  
      - labels_list (list[Tensor]): Labels of each level.
      - label_weights_list (list[Tensor]): Label weights of each level.
      - bbox_cls_targets_list (list[Tensor]): BBox cls targets of             each level.
      - bbox_cls_weights_list (list[Tensor]): BBox cls weights of             each level.
      - bbox_reg_targets_list (list[Tensor]): BBox reg targets of             each level.
      - bbox_reg_weights_list (list[Tensor]): BBox reg weights of             each level.
      - num_total_pos (int): Number of positive samples in all images.
      - num_total_neg (int): Number of negative samples in all images.
docstr_tok: ["Compute","bucketing","targets",".","Args",":","approx_list","(","list","[","list","[","Tensor","]","]",")",":","Multi","level","approxs","of","each","image",".","inside_flag_list","(","list","[","list","[","Tensor","]","]",")",":","Multi","level","inside","flags","of","each","image",".","square_list","(","list","[","list","[","Tensor","]","]",")",":","Multi","level","squares","of","each","image",".","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",".","Defaults","to","True",".","Returns",":","tuple",":","Returns","a","tuple","containing","learning","targets",".","-","labels_list","(","list","[","Tensor","]",")",":","Labels","of","each","level",".","-","label_weights_list","(","list","[","Tensor","]",")",":","Label","weights","of","each","level",".","-","bbox_cls_targets_list","(","list","[","Tensor","]",")",":","BBox","cls","targets","of","each","level",".","-","bbox_cls_weights_list","(","list","[","Tensor","]",")",":","BBox","cls","weights","of","each","level",".","-","bbox_reg_targets_list","(","list","[","Tensor","]",")",":","BBox","reg","targets","of","each","level",".","-","bbox_reg_weights_list","(","list","[","Tensor","]",")",":","BBox","reg","weights","of","each","level",".","-","num_total_pos","(","int",")",":","Number","of","positive","samples","in","all","images",".","-","num_total_neg","(","int",")",":","Number","of","negative","samples","in","all","images","."]
code: def get_targets(
      self,
      approx_list: List[List[Tensor]],
      inside_flag_list: List[List[Tensor]],
      square_list: List[List[Tensor]],
      batch_gt_instances: InstanceList,
      batch_img_metas,
      batch_gt_instances_ignore: OptInstanceList = None,
      unmap_outputs=True,
  ) -> tuple:
      """Compute bucketing targets.
  
          Args:
              approx_list (list[list[Tensor]]): Multi level approxs of each
                  image.
              inside_flag_list (list[list[Tensor]]): Multi level inside flags of
                  each image.
              square_list (list[list[Tensor]]): Multi level squares of each
                  image.
              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. Defaults to True.
  
          Returns:
              tuple: Returns a tuple containing learning targets.
  
              - labels_list (list[Tensor]): Labels of each level.
              - label_weights_list (list[Tensor]): Label weights of each level.
              - bbox_cls_targets_list (list[Tensor]): BBox cls targets of \
              each level.
              - bbox_cls_weights_list (list[Tensor]): BBox cls weights of \
              each level.
              - bbox_reg_targets_list (list[Tensor]): BBox reg targets of \
              each level.
              - bbox_reg_weights_list (list[Tensor]): BBox reg weights of \
              each level.
              - num_total_pos (int): Number of positive samples in all images.
              - num_total_neg (int): Number of negative samples in all images.
          """
      num_imgs = len(batch_img_metas)
      assert (
          len(approx_list)
          == len(inside_flag_list)
          == len(square_list)
          == num_imgs
      )
      # anchor number of multi levels
      num_level_squares = [
          squares.size(0) for squares in square_list[0]
      ]
      # concat all level anchors and flags to a single tensor
      inside_flag_flat_list = []
      approx_flat_list = []
      square_flat_list = []
      for i in range(num_imgs):
          assert len(square_list[i]) == len(inside_flag_list[i])
          inside_flag_flat_list.append(torch.cat(inside_flag_list[i]))
          approx_flat_list.append(torch.cat(approx_list[i]))
          square_flat_list.append(torch.cat(square_list[i]))
  
      # compute targets for each image
      if batch_gt_instances_ignore is None:
          batch_gt_instances_ignore = [None for _ in range(num_imgs)]
      (
          all_labels,
          all_label_weights,
          all_bbox_cls_targets,
          all_bbox_cls_weights,
          all_bbox_reg_targets,
          all_bbox_reg_weights,
          pos_inds_list,
          neg_inds_list,
          sampling_results_list,
      ) = multi_apply(
          self._get_targets_single,
          approx_flat_list,
          inside_flag_flat_list,
          square_flat_list,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore,
          unmap_outputs=unmap_outputs,
      )
  
      # sampled anchors of all images
      avg_factor = sum(
          [results.avg_factor for results in sampling_results_list]
      )
      # split targets to a list w.r.t. multiple levels
      labels_list = images_to_levels(all_labels, num_level_squares)
      label_weights_list = images_to_levels(
          all_label_weights, num_level_squares
      )
      bbox_cls_targets_list = images_to_levels(
          all_bbox_cls_targets, num_level_squares
      )
      bbox_cls_weights_list = images_to_levels(
          all_bbox_cls_weights, num_level_squares
      )
      bbox_reg_targets_list = images_to_levels(
          all_bbox_reg_targets, num_level_squares
      )
      bbox_reg_weights_list = images_to_levels(
          all_bbox_reg_weights, num_level_squares
      )
      return (
          labels_list,
          label_weights_list,
          bbox_cls_targets_list,
          bbox_cls_weights_list,
          bbox_reg_targets_list,
          bbox_reg_weights_list,
          avg_factor,
      )
  
imports: from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptInstanceList
  from ..task_modules.samplers import PseudoSampler
  from ..utils import filter_scores_and_topk, images_to_levels, multi_apply, unmap
  from .base_dense_head import BaseDenseHead
  from .guided_anchor_head import GuidedAnchorHead
label_desc: Use image node_id 6 for calling the SABLRetinaHead obj's underlying member method code with example usage: obj.get_targets(approx_list, inside_flag_list, square_list, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore, unmap_outputs) and returns: labels_list,  label_weights_list,  bbox_cls_targets_list,  bbox_cls_weights_list,  bbox_reg_targets_list,  bbox_reg_weights_list,  avg_factor