class_docstr: Detection Head of `FoveaBox: Beyond Anchor-based Object Detector.
  
  <https://arxiv.org/abs/1904.03797>`_.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      base_edge_list (list[int]): List of edges.
      scale_ranges (list[tuple]): Range of scales.
      sigma (float): Super parameter of ``FoveaHead``.
      with_deform (bool):  Whether use deform conv.
      deform_groups (int): Deformable conv group size.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             dict], optional): Initialization config dict.
class_docstr_tok: ["Detection","Head","of","`","FoveaBox",":","Beyond","Anchor-based","Object","Detector",".","<","https",":","\/\/arxiv.org\/abs\/1904.03797",">","`","_",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","base_edge_list","(","list","[","int","]",")",":","List","of","edges",".","scale_ranges","(","list","[","tuple","]",")",":","Range","of","scales",".","sigma","(","float",")",":","Super","parameter","of","``","FoveaHead","``",".","with_deform","(","bool",")",":","Whether","use","deform","conv",".","deform_groups","(","int",")",":","Deformable","conv","group","size",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[",":","obj",":","`","ConfigDict","`","or","dict","]",",","optional",")",":","Initialization","config","dict","."]
docstr: Compute regression and classification targets for a single image.
  
  Args:
      gt_instances (:obj:`InstanceData`): Ground truth of instance
          annotations. It usually includes ``bboxes`` and ``labels``
          attributes.
      featmap_size_list (list[tuple]): Size tuple of feature maps.
      priors_list (list[Tensor]): Priors of each fpn level, each has
          shape (num_priors, 2).
  
  Returns:
      tuple:
  
      - label_list (list[Tensor]): Labels of all anchors in the image.
      - box_target_list (list[Tensor]): BBox targets of all anchors in
        the image.
docstr_tok: ["Compute","regression","and","classification","targets","for","a","single","image",".","Args",":","gt_instances","(",":","obj",":","`","InstanceData","`",")",":","Ground","truth","of","instance","annotations",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","featmap_size_list","(","list","[","tuple","]",")",":","Size","tuple","of","feature","maps",".","priors_list","(","list","[","Tensor","]",")",":","Priors","of","each","fpn","level",",","each","has","shape","(","num_priors",",","2",")",".","Returns",":","tuple",":","-","label_list","(","list","[","Tensor","]",")",":","Labels","of","all","anchors","in","the","image",".","-","box_target_list","(","list","[","Tensor","]",")",":","BBox","targets","of","all","anchors","in","the","image","."]
code: def _get_targets_single(
      self,
      gt_instances: InstanceData,
      featmap_size_list: List[tuple] = None,
      priors_list: List[Tensor] = None,
  ) -> tuple:
      """Compute regression and classification targets for a single image.
  
      Args:
          gt_instances (:obj:`InstanceData`): Ground truth of instance
              annotations. It usually includes ``bboxes`` and ``labels``
              attributes.
          featmap_size_list (list[tuple]): Size tuple of feature maps.
          priors_list (list[Tensor]): Priors of each fpn level, each has
              shape (num_priors, 2).
  
      Returns:
          tuple:
  
          - label_list (list[Tensor]): Labels of all anchors in the image.
          - box_target_list (list[Tensor]): BBox targets of all anchors in
            the image.
      """
      gt_bboxes_raw = gt_instances.bboxes
      gt_labels_raw = gt_instances.labels
      gt_areas = torch.sqrt(
          (gt_bboxes_raw[:, 2] - gt_bboxes_raw[:, 0])
          * (gt_bboxes_raw[:, 3] - gt_bboxes_raw[:, 1])
      )
      label_list = []
      bbox_target_list = []
      # for each pyramid, find the cls and box target
      for (
          base_len,
          (lower_bound, upper_bound),
          stride,
          featmap_size,
          priors,
      ) in zip(
          self.base_edge_list,
          self.scale_ranges,
          self.strides,
          featmap_size_list,
          priors_list,
      ):
          # FG cat_id: [0, num_classes -1], BG cat_id: num_classes
          priors = priors.view(*featmap_size, 2)
          x, y = priors[..., 0], priors[..., 1]
          labels = gt_labels_raw.new_full(
              featmap_size, self.num_classes
          )
          bbox_targets = gt_bboxes_raw.new_ones(
              featmap_size[0], featmap_size[1], 4
          )
          # scale assignment
          hit_indices = (
              ((gt_areas >= lower_bound) & (gt_areas <= upper_bound))
              .nonzero()
              .flatten()
          )
          if len(hit_indices) == 0:
              label_list.append(labels)
              bbox_target_list.append(torch.log(bbox_targets))
              continue
          _, hit_index_order = torch.sort(-gt_areas[hit_indices])
          hit_indices = hit_indices[hit_index_order]
          gt_bboxes = gt_bboxes_raw[hit_indices, :] / stride
          gt_labels = gt_labels_raw[hit_indices]
          half_w = 0.5 * (gt_bboxes[:, 2] - gt_bboxes[:, 0])
          half_h = 0.5 * (gt_bboxes[:, 3] - gt_bboxes[:, 1])
          # valid fovea area: left, right, top, down
          pos_left = (
              torch.ceil(
                  gt_bboxes[:, 0] + (1 - self.sigma) * half_w - 0.5
              )
              .long()
              .clamp(0, featmap_size[1] - 1)
          )
          pos_right = (
              torch.floor(
                  gt_bboxes[:, 0] + (1 + self.sigma) * half_w - 0.5
              )
              .long()
              .clamp(0, featmap_size[1] - 1)
          )
          pos_top = (
              torch.ceil(
                  gt_bboxes[:, 1] + (1 - self.sigma) * half_h - 0.5
              )
              .long()
              .clamp(0, featmap_size[0] - 1)
          )
          pos_down = (
              torch.floor(
                  gt_bboxes[:, 1] + (1 + self.sigma) * half_h - 0.5
              )
              .long()
              .clamp(0, featmap_size[0] - 1)
          )
          for (
              px1,
              py1,
              px2,
              py2,
              label,
              (gt_x1, gt_y1, gt_x2, gt_y2),
          ) in zip(
              pos_left,
              pos_top,
              pos_right,
              pos_down,
              gt_labels,
              gt_bboxes_raw[hit_indices, :],
          ):
              labels[py1 : py2 + 1, px1 : px2 + 1] = label
              bbox_targets[py1 : py2 + 1, px1 : px2 + 1, 0] = (
                  x[py1 : py2 + 1, px1 : px2 + 1] - gt_x1
              ) / base_len
              bbox_targets[py1 : py2 + 1, px1 : px2 + 1, 1] = (
                  y[py1 : py2 + 1, px1 : px2 + 1] - gt_y1
              ) / base_len
              bbox_targets[py1 : py2 + 1, px1 : px2 + 1, 2] = (
                  gt_x2 - x[py1 : py2 + 1, px1 : px2 + 1]
              ) / base_len
              bbox_targets[py1 : py2 + 1, px1 : px2 + 1, 3] = (
                  gt_y2 - y[py1 : py2 + 1, px1 : px2 + 1]
              ) / base_len
          bbox_targets = bbox_targets.clamp(min=1.0 / 16, max=16.0)
          label_list.append(labels)
          bbox_target_list.append(torch.log(bbox_targets))
      return label_list, bbox_target_list
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule
  from mmcv.ops import DeformConv2d
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.utils import InstanceList, OptInstanceList, OptMultiConfig
  from ..utils import filter_scores_and_topk, multi_apply
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 6 for calling the FoveaHead obj's underlying member method code with example usage: obj._get_targets_single(gt_instances, featmap_size_list, priors_list) and returns: label_list,  bbox_target_list