class_docstr: ATSS head with visual-language fusion module.
  
  Args:
      early_fuse (bool): Whether to fuse visual and language features
          Defaults to False.
      use_checkpoint (bool): Whether to use checkpoint. Defaults to False.
      num_dyhead_blocks (int): Number of dynamic head blocks. Defaults to 6.
      lang_model_name (str): Name of the language model.
          Defaults to 'bert-base-uncased'.
class_docstr_tok: ["ATSS","head","with","visual-language","fusion","module",".","Args",":","early_fuse","(","bool",")",":","Whether","to","fuse","visual","and","language","features","Defaults","to","False",".","use_checkpoint","(","bool",")",":","Whether","to","use","checkpoint",".","Defaults","to","False",".","num_dyhead_blocks","(","int",")",":","Number","of","dynamic","head","blocks",".","Defaults","to","6.","lang_model_name","(","str",")",":","Name","of","the","language","model",".","Defaults","to","'bert-base-uncased","'","."]
docstr: Compute regression, classification targets for anchors in a single
  image.
  
  Args:
      flat_anchors (Tensor): Multi-level anchors of the image, which are
          concatenated into a single tensor of shape (num_anchors ,4)
      valid_flags (Tensor): Multi level valid flags of the image,
          which are concatenated into a single tensor of
              shape (num_anchors,).
      num_level_anchors (List[int]): Number of anchors of each scale
          level.
      gt_instances (:obj:`InstanceData`): Ground truth of instance
          annotations. It usually includes ``bboxes`` and ``labels``
          attributes.
      img_meta (dict): Meta information for current image.
      gt_instances_ignore (:obj:`InstanceData`, optional): Instances
          to be ignored during training. 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.
  
  Returns:
      tuple: N is the number of total anchors in the image.
          labels (Tensor): Labels of all anchors in the image with shape
              (N,).
          label_weights (Tensor): Label weights of all anchor in the
              image with shape (N,).
          bbox_targets (Tensor): BBox targets of all anchors in the
              image with shape (N, 4).
          bbox_weights (Tensor): BBox weights of all anchors in the
              image with shape (N, 4)
          pos_inds (Tensor): Indices of positive anchor with shape
              (num_pos,).
          neg_inds (Tensor): Indices of negative anchor with shape
              (num_neg,).
          sampling_result (:obj:`SamplingResult`): Sampling results.
docstr_tok: ["Compute","regression",",","classification","targets","for","anchors","in","a","single","image",".","Args",":","flat_anchors","(","Tensor",")",":","Multi-level","anchors","of","the","image",",","which","are","concatenated","into","a","single","tensor","of","shape","(","num_anchors",",4",")","valid_flags","(","Tensor",")",":","Multi","level","valid","flags","of","the","image",",","which","are","concatenated","into","a","single","tensor","of","shape","(","num_anchors",",",")",".","num_level_anchors","(","List","[","int","]",")",":","Number","of","anchors","of","each","scale","level",".","gt_instances","(",":","obj",":","`","InstanceData","`",")",":","Ground","truth","of","instance","annotations",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","img_meta","(","dict",")",":","Meta","information","for","current","image",".","gt_instances_ignore","(",":","obj",":","`","InstanceData","`",",","optional",")",":","Instances","to","be","ignored","during","training",".","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",".","Returns",":","tuple",":","N","is","the","number","of","total","anchors","in","the","image",".","labels","(","Tensor",")",":","Labels","of","all","anchors","in","the","image","with","shape","(","N",",",")",".","label_weights","(","Tensor",")",":","Label","weights","of","all","anchor","in","the","image","with","shape","(","N",",",")",".","bbox_targets","(","Tensor",")",":","BBox","targets","of","all","anchors","in","the","image","with","shape","(","N",",","4",")",".","bbox_weights","(","Tensor",")",":","BBox","weights","of","all","anchors","in","the","image","with","shape","(","N",",","4",")","pos_inds","(","Tensor",")",":","Indices","of","positive","anchor","with","shape","(","num_pos",",",")",".","neg_inds","(","Tensor",")",":","Indices","of","negative","anchor","with","shape","(","num_neg",",",")",".","sampling_result","(",":","obj",":","`","SamplingResult","`",")",":","Sampling","results","."]
code: def _get_targets_single(
      self,
      flat_anchors: Tensor,
      valid_flags: Tensor,
      num_level_anchors: List[int],
      gt_instances: InstanceData,
      img_meta: dict,
      gt_instances_ignore: Optional[InstanceData] = None,
      unmap_outputs: bool = True,
  ) -> tuple:
      """Compute regression, classification targets for anchors in a single
      image.
  
      Args:
          flat_anchors (Tensor): Multi-level anchors of the image, which are
              concatenated into a single tensor of shape (num_anchors ,4)
          valid_flags (Tensor): Multi level valid flags of the image,
              which are concatenated into a single tensor of
                  shape (num_anchors,).
          num_level_anchors (List[int]): Number of anchors of each scale
              level.
          gt_instances (:obj:`InstanceData`): Ground truth of instance
              annotations. It usually includes ``bboxes`` and ``labels``
              attributes.
          img_meta (dict): Meta information for current image.
          gt_instances_ignore (:obj:`InstanceData`, optional): Instances
              to be ignored during training. 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.
  
      Returns:
          tuple: N is the number of total anchors in the image.
              labels (Tensor): Labels of all anchors in the image with shape
                  (N,).
              label_weights (Tensor): Label weights of all anchor in the
                  image with shape (N,).
              bbox_targets (Tensor): BBox targets of all anchors in the
                  image with shape (N, 4).
              bbox_weights (Tensor): BBox weights of all anchors in the
                  image with shape (N, 4)
              pos_inds (Tensor): Indices of positive anchor with shape
                  (num_pos,).
              neg_inds (Tensor): Indices of negative anchor with shape
                  (num_neg,).
              sampling_result (:obj:`SamplingResult`): Sampling results.
      """
      anchors = flat_anchors
      # Align the official implementation
      anchors[:, 2:] -= 1
  
      num_level_anchors_inside = num_level_anchors
      pred_instances = InstanceData(priors=anchors)
      assign_result = self.assigner.assign(
          pred_instances,
          num_level_anchors_inside,
          gt_instances,
          gt_instances_ignore,
      )
  
      sampling_result = self.sampler.sample(
          assign_result, pred_instances, gt_instances
      )
  
      num_valid_anchors = anchors.shape[0]
      bbox_targets = torch.zeros_like(anchors)
      bbox_weights = torch.zeros_like(anchors)
  
      # ===== this change =====
      labels = anchors.new_full(
          (num_valid_anchors, self.feat_channels),
          0,
          dtype=torch.float32,
      )
      label_weights = anchors.new_zeros(
          num_valid_anchors, dtype=torch.float
      )
      pos_inds = sampling_result.pos_inds
      neg_inds = sampling_result.neg_inds
      if len(pos_inds) > 0:
          if self.reg_decoded_bbox:
              pos_bbox_targets = sampling_result.pos_gt_bboxes
          else:
              pos_bbox_targets = self.bbox_coder.encode(
                  sampling_result.pos_priors,
                  sampling_result.pos_gt_bboxes,
              )
  
          bbox_targets[pos_inds, :] = pos_bbox_targets
          bbox_weights[pos_inds, :] = 1.0
  
          # ===== this change =====
          labels[pos_inds] = gt_instances.positive_maps[
              sampling_result.pos_assigned_gt_inds
          ]
          if self.train_cfg["pos_weight"] <= 0:
              label_weights[pos_inds] = 1.0
          else:
              label_weights[pos_inds] = self.train_cfg["pos_weight"]
      if len(neg_inds) > 0:
          label_weights[neg_inds] = 1.0
  
      return (
          anchors,
          labels,
          label_weights,
          bbox_targets,
          bbox_weights,
          pos_inds,
          neg_inds,
          sampling_result,
      )
  
imports: import copy
  import math
  from typing import Callable, List, Optional, Sequence, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Scale
  from mmcv.ops.modulated_deform_conv import ModulatedDeformConv2d
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModel
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import cat_boxes
  from mmdet.utils import InstanceList, OptInstanceList, reduce_mean
  from ..utils import BertEncoderLayer, VLFuse, filter_scores_and_topk, permute_and_flatten, select_single_mlvl, unpack_gt_instances
  from ..utils.vlfuse_helper import MAX_CLAMP_VALUE
  from .atss_head import ATSSHead
label_desc: Use image node_id 7 for calling the ATSSVLFusionHead obj's underlying member method code with example usage: obj._get_targets_single(flat_anchors, valid_flags, num_level_anchors, gt_instances, img_meta, gt_instances_ignore, unmap_outputs) and returns: anchors,  labels,  label_weights,  bbox_targets,  bbox_weights,  pos_inds,  neg_inds,  sampling_result