class_docstr: RoI head for `Dynamic R-CNN <https://arxiv.org/abs/2004.06002>`_.
docstr: Forward function for training.
  
  Args:
      x (list[Tensor]): list of multi-level img features.
  
      img_metas (list[dict]): list of image info dict where each dict
          has: 'img_shape', 'scale_factor', 'flip', and may also contain
          'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
          For details on the values of these keys see
          `mmdet/datasets/pipelines/formatting.py:Collect`.
  
      proposals (list[Tensors]): list of region proposals.
  
      gt_bboxes (list[Tensor]): each item are the truth boxes for each
          image in [tl_x, tl_y, br_x, br_y] format.
  
      gt_labels (list[Tensor]): class indices corresponding to each box
  
      gt_bboxes_ignore (None | list[Tensor]): specify which bounding
          boxes can be ignored when computing the loss.
  
      gt_masks (None | Tensor) : true segmentation masks for each box
          used if the architecture supports a segmentation task.
  
  Returns:
      dict[str, Tensor]: a dictionary of loss components
code: def forward_train(
      self,
      x,
      img_metas,
      proposal_list,
      gt_bboxes,
      gt_labels,
      gt_bboxes_ignore=None,
      gt_masks=None,
  ):
      """Forward function for training.
  
      Args:
          x (list[Tensor]): list of multi-level img features.
  
          img_metas (list[dict]): list of image info dict where each dict
              has: 'img_shape', 'scale_factor', 'flip', and may also contain
              'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
              For details on the values of these keys see
              `mmdet/datasets/pipelines/formatting.py:Collect`.
  
          proposals (list[Tensors]): list of region proposals.
  
          gt_bboxes (list[Tensor]): each item are the truth boxes for each
              image in [tl_x, tl_y, br_x, br_y] format.
  
          gt_labels (list[Tensor]): class indices corresponding to each box
  
          gt_bboxes_ignore (None | list[Tensor]): specify which bounding
              boxes can be ignored when computing the loss.
  
          gt_masks (None | Tensor) : true segmentation masks for each box
              used if the architecture supports a segmentation task.
  
      Returns:
          dict[str, Tensor]: a dictionary of loss components
      """
      # assign gts and sample proposals
      if self.with_bbox or self.with_mask:
          num_imgs = len(img_metas)
          if gt_bboxes_ignore is None:
              gt_bboxes_ignore = [None for _ in range(num_imgs)]
          sampling_results = []
          cur_iou = []
          for i in range(num_imgs):
              assign_result = self.bbox_assigner.assign(
                  proposal_list[i],
                  gt_bboxes[i],
                  gt_bboxes_ignore[i],
                  gt_labels[i],
              )
              sampling_result = self.bbox_sampler.sample(
                  assign_result,
                  proposal_list[i],
                  gt_bboxes[i],
                  gt_labels[i],
                  feats=[lvl_feat[i][None] for lvl_feat in x],
              )
              # record the `iou_topk`-th largest IoU in an image
              iou_topk = min(
                  self.train_cfg.dynamic_rcnn.iou_topk,
                  len(assign_result.max_overlaps),
              )
              ious, _ = torch.topk(assign_result.max_overlaps, iou_topk)
              cur_iou.append(ious[-1].item())
              sampling_results.append(sampling_result)
          # average the current IoUs over images
          cur_iou = np.mean(cur_iou)
          self.iou_history.append(cur_iou)
  
      losses = dict()
      # bbox head forward and loss
      if self.with_bbox:
          bbox_results = self._bbox_forward_train(
              x, sampling_results, gt_bboxes, gt_labels, img_metas
          )
          losses.update(bbox_results["loss_bbox"])
  
      # mask head forward and loss
      if self.with_mask:
          mask_results = self._mask_forward_train(
              x,
              sampling_results,
              bbox_results["bbox_feats"],
              gt_masks,
              img_metas,
          )
          losses.update(mask_results["loss_mask"])
  
      # update IoU threshold and SmoothL1 beta
      update_iter_interval = (
          self.train_cfg.dynamic_rcnn.update_iter_interval
      )
      if len(self.iou_history) % update_iter_interval == 0:
          new_iou_thr, new_beta = self.update_hyperparameters()
  
      return losses
  
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 2 for calling the DynamicRoIHead obj's underlying member method code with example usage: obj.forward_train(x, img_metas, proposal_list, gt_bboxes, gt_labels, gt_bboxes_ignore, gt_masks) and returns: losses