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: Refine bboxes during training.
  
  Args:
      rois (Tensor): Shape (n*bs, 5), where n is image number per GPU,
          and bs is the sampled RoIs per image.
      labels (Tensor): Shape (n*bs, ).
      bbox_preds (list[Tensor]): Shape [(n*bs, num_buckets*2),                 (n*bs, num_buckets*2)].
      pos_is_gts (list[Tensor]): Flags indicating if each positive bbox
          is a gt bbox.
      img_metas (list[dict]): Meta info of each image.
  
  Returns:
      list[Tensor]: Refined bboxes of each image in a mini-batch.
docstr_tok: ["Refine","bboxes","during","training",".","Args",":","rois","(","Tensor",")",":","Shape","(","n","*","bs",",","5",")",",","where","n","is","image","number","per","GPU",",","and","bs","is","the","sampled","RoIs","per","image",".","labels","(","Tensor",")",":","Shape","(","n","*","bs",",",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Shape","[","(","n","*","bs",",","num_buckets","*","2",")",",","(","n","*","bs",",","num_buckets","*","2",")","]",".","pos_is_gts","(","list","[","Tensor","]",")",":","Flags","indicating","if","each","positive","bbox","is","a","gt","bbox",".","img_metas","(","list","[","dict","]",")",":","Meta","info","of","each","image",".","Returns",":","list","[","Tensor","]",":","Refined","bboxes","of","each","image","in","a","mini-batch","."]
code: def refine_bboxes(
      self, rois, labels, bbox_preds, pos_is_gts, img_metas
  ):
      """Refine bboxes during training.
  
          Args:
              rois (Tensor): Shape (n*bs, 5), where n is image number per GPU,
                  and bs is the sampled RoIs per image.
              labels (Tensor): Shape (n*bs, ).
              bbox_preds (list[Tensor]): Shape [(n*bs, num_buckets*2), \
                  (n*bs, num_buckets*2)].
              pos_is_gts (list[Tensor]): Flags indicating if each positive bbox
                  is a gt bbox.
              img_metas (list[dict]): Meta info of each image.
  
          Returns:
              list[Tensor]: Refined bboxes of each image in a mini-batch.
          """
      img_ids = rois[:, 0].long().unique(sorted=True)
      assert img_ids.numel() == len(img_metas)
  
      bboxes_list = []
      for i in range(len(img_metas)):
          inds = torch.nonzero(rois[:, 0] == i, as_tuple=False).squeeze(
              dim=1
          )
          num_rois = inds.numel()
  
          bboxes_ = rois[inds, 1:]
          label_ = labels[inds]
          edge_cls_preds, edge_offset_preds = bbox_preds
          edge_cls_preds_ = edge_cls_preds[inds]
          edge_offset_preds_ = edge_offset_preds[inds]
          bbox_pred_ = [edge_cls_preds_, edge_offset_preds_]
          img_meta_ = img_metas[i]
          pos_is_gts_ = pos_is_gts[i]
  
          bboxes = self.regress_by_class(
              bboxes_, label_, bbox_pred_, img_meta_
          )
          # filter gt bboxes
          pos_keep = 1 - pos_is_gts_
          keep_inds = pos_is_gts_.new_ones(num_rois)
          keep_inds[: len(pos_is_gts_)] = pos_keep
  
          bboxes_list.append(bboxes[keep_inds.type(torch.bool)])
  
      return bboxes_list
  
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 17 for calling the SABLHead obj's underlying member method code with example usage: obj.refine_bboxes(rois, labels, bbox_preds, pos_is_gts, img_metas) and returns: bboxes_list