class_docstr: Trident roi head.
  
  Args:
      num_branch (int): Number of branches in TridentNet.
      test_branch_idx (int): In inference, all 3 branches will be used
          if `test_branch_idx==-1`, otherwise only branch with index
          `test_branch_idx` will be used.
docstr: Perform forward propagation of the roi head and predict detection
  results on the features of the upstream network.
  
  - Compute prediction bbox and label per branch.
  - Merge predictions of each branch according to scores of
    bboxes, i.e., bboxes with higher score are kept to give
    top-k prediction.
  
  Args:
      x (tuple[Tensor]): Features from upstream network. Each
          has shape (N, C, H, W).
      rpn_results_list (list[:obj:`InstanceData`]): list of region
          proposals.
      batch_data_samples (List[:obj:`DetDataSample`]): The Data
          Samples. It usually includes information such as
          `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
      rescale (bool): Whether to rescale the results to
          the original image. Defaults to True.
  
  Returns:
      list[obj:`InstanceData`]: Detection results of each image.
      Each item usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
            (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
            the last dimension 4 arrange as (x1, y1, x2, y2).
docstr_tok: ["Perform","forward","propagation","of","the","roi","head","and","predict","detection","results","on","the","features","of","the","upstream","network",".","-","Compute","prediction","bbox","and","label","per","branch",".","-","Merge","predictions","of","each","branch","according","to","scores","of","bboxes",",","i.e.",",","bboxes","with","higher","score","are","kept","to","give","top-k","prediction",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Features","from","upstream","network",".","Each","has","shape","(","N",",","C",",","H",",","W",")",".","rpn_results_list","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","list","of","region","proposals",".","batch_data_samples","(","List","[",":","obj",":","`","DetDataSample","`","]",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",",","`","gt_panoptic_seg","`","and","`","gt_sem_seg","`",".","rescale","(","bool",")",":","Whether","to","rescale","the","results","to","the","original","image",".","Defaults","to","True",".","Returns",":","list","[","obj",":","`","InstanceData","`","]",":","Detection","results","of","each","image",".","Each","item","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")","."]
code: def predict(
      self,
      x: Tuple[Tensor],
      rpn_results_list: InstanceList,
      batch_data_samples: SampleList,
      rescale: bool = False,
  ) -> InstanceList:
      """Perform forward propagation of the roi head and predict detection
      results on the features of the upstream network.
  
      - Compute prediction bbox and label per branch.
      - Merge predictions of each branch according to scores of
        bboxes, i.e., bboxes with higher score are kept to give
        top-k prediction.
  
      Args:
          x (tuple[Tensor]): Features from upstream network. Each
              has shape (N, C, H, W).
          rpn_results_list (list[:obj:`InstanceData`]): list of region
              proposals.
          batch_data_samples (List[:obj:`DetDataSample`]): The Data
              Samples. It usually includes information such as
              `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
          rescale (bool): Whether to rescale the results to
              the original image. Defaults to True.
  
      Returns:
          list[obj:`InstanceData`]: Detection results of each image.
          Each item usually contains following keys.
  
              - scores (Tensor): Classification scores, has a shape
                (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                the last dimension 4 arrange as (x1, y1, x2, y2).
      """
      results_list = super().predict(
          x=x,
          rpn_results_list=rpn_results_list,
          batch_data_samples=batch_data_samples,
          rescale=rescale,
      )
  
      num_branch = (
          self.num_branch
          if self.training or self.test_branch_idx == -1
          else 1
      )
  
      merged_results_list = []
      for i in range(len(batch_data_samples) // num_branch):
          merged_results_list.append(
              self.merge_trident_bboxes(
                  results_list[i * num_branch : (i + 1) * num_branch]
              )
          )
      return merged_results_list
  
file_path: mmdetection/mmdet/models/roi_heads/trident_roi_head.py
imports: from typing import Tuple
  import torch
  from mmcv.ops import batched_nms
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.utils import InstanceList
  from .standard_roi_head import StandardRoIHead
label_desc: Use image node_id 3 for calling the TridentRoIHead obj's underlying member method code with example usage: obj.predict(x, rpn_results_list, batch_data_samples, rescale) and returns: merged_results_list