class_docstr: RoI head for `Dynamic R-CNN <https://arxiv.org/abs/2004.06002>`_.
code: def _bbox_forward_train(
      self, x, sampling_results, gt_bboxes, gt_labels, img_metas
  ):
      num_imgs = len(img_metas)
      rois = bbox2roi([res.bboxes for res in sampling_results])
      bbox_results = self._bbox_forward(x, rois)
  
      bbox_targets = self.bbox_head.get_targets(
          sampling_results, gt_bboxes, gt_labels, self.train_cfg
      )
      # record the `beta_topk`-th smallest target
      # `bbox_targets[2]` and `bbox_targets[3]` stand for bbox_targets
      # and bbox_weights, respectively
      pos_inds = bbox_targets[3][:, 0].nonzero().squeeze(1)
      num_pos = len(pos_inds)
      cur_target = bbox_targets[2][pos_inds, :2].abs().mean(dim=1)
      beta_topk = min(
          self.train_cfg.dynamic_rcnn.beta_topk * num_imgs, num_pos
      )
      cur_target = torch.kthvalue(cur_target, beta_topk)[0].item()
      self.beta_history.append(cur_target)
      loss_bbox = self.bbox_head.loss(
          bbox_results["cls_score"],
          bbox_results["bbox_pred"],
          rois,
          *bbox_targets,
      )
  
      bbox_results.update(loss_bbox=loss_bbox)
      return bbox_results
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/dynamic_roi_head.py
imports: import numpy
  import torch
  from mmdet.core import bbox2roi
  from mmdet.models.losses import SmoothL1Loss
  from ..builder import HEADS
  from .standard_roi_head import StandardRoIHead
label_desc: Use image node_id 3 for calling the DynamicRoIHead obj's underlying member method code with example usage: obj._bbox_forward_train(x, sampling_results, gt_bboxes, gt_labels, img_metas) and returns: bbox_results