class_docstr: Side-Aware Boundary Localization (SABL) for RoI-Head.
  
  Side-Aware features are extracted by conv layers
  with an attention mechanism.
  Boundary Localization with Bucketing and Bucketing Guided Rescoring
  are implemented in BucketingBBoxCoder.
  
  Please refer to https://arxiv.org/abs/1912.04260 for more details.
  
  Args:
      cls_in_channels (int): Input channels of cls RoI feature.             Defaults to 256.
      reg_in_channels (int): Input channels of reg RoI feature.             Defaults to 256.
      roi_feat_size (int): Size of RoI features. Defaults to 7.
      reg_feat_up_ratio (int): Upsample ratio of reg features.             Defaults to 2.
      reg_pre_kernel (int): Kernel of 2D conv layers before             attention pooling. Defaults to 3.
      reg_post_kernel (int): Kernel of 1D conv layers after             attention pooling. Defaults to 3.
      reg_pre_num (int): Number of pre convs. Defaults to 2.
      reg_post_num (int): Number of post convs. Defaults to 1.
      num_classes (int): Number of classes in dataset. Defaults to 80.
      cls_out_channels (int): Hidden channels in cls fcs. Defaults to 1024.
      reg_offset_out_channels (int): Hidden and output channel             of reg offset branch. Defaults to 256.
      reg_cls_out_channels (int): Hidden and output channel             of reg cls branch. Defaults to 256.
      num_cls_fcs (int): Number of fcs for cls branch. Defaults to 1.
      num_reg_fcs (int): Number of fcs for reg branch.. Defaults to 0.
      reg_class_agnostic (bool): Class agnostic regresion or not.             Defaults to True.
      norm_cfg (dict): Config of norm layers. Defaults to None.
      bbox_coder (dict): Config of bbox coder. Defaults 'BucketingBBoxCoder'.
      loss_cls (dict): Config of classification loss.
      loss_bbox_cls (dict): Config of classification loss for bbox branch.
      loss_bbox_reg (dict): Config of regression loss for bbox branch.
docstr: Compute bucketing estimation targets and fine regression targets for
  a single image.
  
  Args:
      pos_proposals (Tensor): positive proposals of a single image,
           Shape (n_pos, 4)
      neg_proposals (Tensor): negative proposals of a single image,
           Shape (n_neg, 4).
      pos_gt_bboxes (Tensor): gt bboxes assigned to positive proposals
           of a single image, Shape (n_pos, 4).
      pos_gt_labels (Tensor): gt labels assigned to positive proposals
           of a single image, Shape (n_pos, ).
      cfg (dict): Config of calculating targets
  
  Returns:
      tuple:
  
          - labels (Tensor): Labels in a single image.                     Shape (n,).
          - label_weights (Tensor): Label weights in a single image.                    Shape (n,)
          - bucket_cls_targets (Tensor): Bucket cls targets in                     a single image. Shape (n, num_buckets*2).
          - bucket_cls_weights (Tensor): Bucket cls weights in                     a single image. Shape (n, num_buckets*2).
          - bucket_offset_targets (Tensor): Bucket offset targets                     in a single image. Shape (n, num_buckets*2).
          - bucket_offset_targets (Tensor): Bucket offset weights                     in a single image. Shape (n, num_buckets*2).
docstr_tok: ["Compute","bucketing","estimation","targets","and","fine","regression","targets","for","a","single","image",".","Args",":","pos_proposals","(","Tensor",")",":","positive","proposals","of","a","single","image",",","Shape","(","n_pos",",","4",")","neg_proposals","(","Tensor",")",":","negative","proposals","of","a","single","image",",","Shape","(","n_neg",",","4",")",".","pos_gt_bboxes","(","Tensor",")",":","gt","bboxes","assigned","to","positive","proposals","of","a","single","image",",","Shape","(","n_pos",",","4",")",".","pos_gt_labels","(","Tensor",")",":","gt","labels","assigned","to","positive","proposals","of","a","single","image",",","Shape","(","n_pos",",",")",".","cfg","(","dict",")",":","Config","of","calculating","targets","Returns",":","tuple",":","-","labels","(","Tensor",")",":","Labels","in","a","single","image",".","Shape","(","n",",",")",".","-","label_weights","(","Tensor",")",":","Label","weights","in","a","single","image",".","Shape","(","n",",",")","-","bucket_cls_targets","(","Tensor",")",":","Bucket","cls","targets","in","a","single","image",".","Shape","(","n",",","num_buckets","*","2",")",".","-","bucket_cls_weights","(","Tensor",")",":","Bucket","cls","weights","in","a","single","image",".","Shape","(","n",",","num_buckets","*","2",")",".","-","bucket_offset_targets","(","Tensor",")",":","Bucket","offset","targets","in","a","single","image",".","Shape","(","n",",","num_buckets","*","2",")",".","-","bucket_offset_targets","(","Tensor",")",":","Bucket","offset","weights","in","a","single","image",".","Shape","(","n",",","num_buckets","*","2",")","."]
code: def _bucket_target_single(
      self,
      pos_proposals,
      neg_proposals,
      pos_gt_bboxes,
      pos_gt_labels,
      cfg,
  ):
      """Compute bucketing estimation targets and fine regression targets for
          a single image.
  
          Args:
              pos_proposals (Tensor): positive proposals of a single image,
                   Shape (n_pos, 4)
              neg_proposals (Tensor): negative proposals of a single image,
                   Shape (n_neg, 4).
              pos_gt_bboxes (Tensor): gt bboxes assigned to positive proposals
                   of a single image, Shape (n_pos, 4).
              pos_gt_labels (Tensor): gt labels assigned to positive proposals
                   of a single image, Shape (n_pos, ).
              cfg (dict): Config of calculating targets
  
          Returns:
              tuple:
  
                  - labels (Tensor): Labels in a single image. \
                      Shape (n,).
                  - label_weights (Tensor): Label weights in a single image.\
                      Shape (n,)
                  - bucket_cls_targets (Tensor): Bucket cls targets in \
                      a single image. Shape (n, num_buckets*2).
                  - bucket_cls_weights (Tensor): Bucket cls weights in \
                      a single image. Shape (n, num_buckets*2).
                  - bucket_offset_targets (Tensor): Bucket offset targets \
                      in a single image. Shape (n, num_buckets*2).
                  - bucket_offset_targets (Tensor): Bucket offset weights \
                      in a single image. Shape (n, num_buckets*2).
          """
      num_pos = pos_proposals.size(0)
      num_neg = neg_proposals.size(0)
      num_samples = num_pos + num_neg
      labels = pos_gt_bboxes.new_full(
          (num_samples,), self.num_classes, dtype=torch.long
      )
      label_weights = pos_proposals.new_zeros(num_samples)
      bucket_cls_targets = pos_proposals.new_zeros(
          num_samples, 4 * self.side_num
      )
      bucket_cls_weights = pos_proposals.new_zeros(
          num_samples, 4 * self.side_num
      )
      bucket_offset_targets = pos_proposals.new_zeros(
          num_samples, 4 * self.side_num
      )
      bucket_offset_weights = pos_proposals.new_zeros(
          num_samples, 4 * self.side_num
      )
      if num_pos > 0:
          labels[:num_pos] = pos_gt_labels
          label_weights[:num_pos] = 1.0
          (
              pos_bucket_offset_targets,
              pos_bucket_offset_weights,
              pos_bucket_cls_targets,
              pos_bucket_cls_weights,
          ) = self.bbox_coder.encode(pos_proposals, pos_gt_bboxes)
          bucket_cls_targets[:num_pos, :] = pos_bucket_cls_targets
          bucket_cls_weights[:num_pos, :] = pos_bucket_cls_weights
          bucket_offset_targets[:num_pos, :] = pos_bucket_offset_targets
          bucket_offset_weights[:num_pos, :] = pos_bucket_offset_weights
      if num_neg > 0:
          label_weights[-num_neg:] = 1.0
      return (
          labels,
          label_weights,
          bucket_cls_targets,
          bucket_cls_weights,
          bucket_offset_targets,
          bucket_offset_weights,
      )
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, kaiming_init, normal_init, xavier_init
  from mmcv.runner import force_fp32
  from mmdet.core import build_bbox_coder, multi_apply, multiclass_nms
  from mmdet.models.builder import HEADS, build_loss
  from mmdet.models.losses import accuracy
label_desc: Use image node_id 14 for calling the SABLHead obj's underlying member method code with example usage: obj._bucket_target_single(pos_proposals, neg_proposals, pos_gt_bboxes, pos_gt_labels, cfg) and returns: labels,  label_weights,  bucket_cls_targets,  bucket_cls_weights,  bucket_offset_targets,  bucket_offset_weights