class_docstr: Dynamic Instance Interactive Head for `Sparse R-CNN: End-to-End Object
  Detection with Learnable Proposals <https://arxiv.org/abs/2011.12450>`_
  
  Args:
      num_classes (int): Number of class in dataset.
          Defaults to 80.
      num_ffn_fcs (int): The number of fully-connected
          layers in FFNs. Defaults to 2.
      num_heads (int): The hidden dimension of FFNs.
          Defaults to 8.
      num_cls_fcs (int): The number of fully-connected
          layers in classification subnet. Defaults to 1.
      num_reg_fcs (int): The number of fully-connected
          layers in regression subnet. Defaults to 3.
      feedforward_channels (int): The hidden dimension
          of FFNs. Defaults to 2048
      in_channels (int): Hidden_channels of MultiheadAttention.
          Defaults to 256.
      dropout (float): Probability of drop the channel.
          Defaults to 0.0
      ffn_act_cfg (:obj:`ConfigDict` or dict): The activation config
          for FFNs.
      dynamic_conv_cfg (:obj:`ConfigDict` or dict): The convolution
          config for DynamicConv.
      loss_iou (:obj:`ConfigDict` or dict): The config for iou or
          giou loss.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or \
          dict]): Initialization config dict. Defaults to None.
docstr: Forward function of Dynamic Instance Interactive Head.
  
  Args:
      roi_feat (Tensor): Roi-pooling features with shape
          (batch_size*num_proposals, feature_dimensions,
          pooling_h , pooling_w).
      proposal_feat (Tensor): Intermediate feature get from
          diihead in last stage, has shape
          (batch_size, num_proposals, feature_dimensions)
  
  Returns:
      tuple[Tensor]: Usually a tuple of classification scores
      and bbox prediction and a intermediate feature.
  
      - cls_scores (Tensor): Classification scores for
        all proposals, has shape
        (batch_size, num_proposals, num_classes).
      - bbox_preds (Tensor): Box energies / deltas for
        all proposals, has shape
        (batch_size, num_proposals, 4).
      - obj_feat (Tensor): Object feature before classification
        and regression subnet, has shape
        (batch_size, num_proposal, feature_dimensions).
      - attn_feats (Tensor): Intermediate feature.
docstr_tok: ["Forward","function","of","Dynamic","Instance","Interactive","Head",".","Args",":","roi_feat","(","Tensor",")",":","Roi-pooling","features","with","shape","(","batch_size","*","num_proposals",",","feature_dimensions",",","pooling_h",",","pooling_w",")",".","proposal_feat","(","Tensor",")",":","Intermediate","feature","get","from","diihead","in","last","stage",",","has","shape","(","batch_size",",","num_proposals",",","feature_dimensions",")","Returns",":","tuple","[","Tensor","]",":","Usually","a","tuple","of","classification","scores","and","bbox","prediction","and","a","intermediate","feature",".","-","cls_scores","(","Tensor",")",":","Classification","scores","for","all","proposals",",","has","shape","(","batch_size",",","num_proposals",",","num_classes",")",".","-","bbox_preds","(","Tensor",")",":","Box","energies","\/","deltas","for","all","proposals",",","has","shape","(","batch_size",",","num_proposals",",","4",")",".","-","obj_feat","(","Tensor",")",":","Object","feature","before","classification","and","regression","subnet",",","has","shape","(","batch_size",",","num_proposal",",","feature_dimensions",")",".","-","attn_feats","(","Tensor",")",":","Intermediate","feature","."]
code: def forward(self, roi_feat: Tensor, proposal_feat: Tensor) -> tuple:
      """Forward function of Dynamic Instance Interactive Head.
  
      Args:
          roi_feat (Tensor): Roi-pooling features with shape
              (batch_size*num_proposals, feature_dimensions,
              pooling_h , pooling_w).
          proposal_feat (Tensor): Intermediate feature get from
              diihead in last stage, has shape
              (batch_size, num_proposals, feature_dimensions)
  
      Returns:
          tuple[Tensor]: Usually a tuple of classification scores
          and bbox prediction and a intermediate feature.
  
          - cls_scores (Tensor): Classification scores for
            all proposals, has shape
            (batch_size, num_proposals, num_classes).
          - bbox_preds (Tensor): Box energies / deltas for
            all proposals, has shape
            (batch_size, num_proposals, 4).
          - obj_feat (Tensor): Object feature before classification
            and regression subnet, has shape
            (batch_size, num_proposal, feature_dimensions).
          - attn_feats (Tensor): Intermediate feature.
      """
      N, num_proposals = proposal_feat.shape[:2]
  
      # Self attention
      proposal_feat = proposal_feat.permute(1, 0, 2)
      proposal_feat = self.attention_norm(self.attention(proposal_feat))
      attn_feats = proposal_feat.permute(1, 0, 2)
  
      # instance interactive
      proposal_feat = attn_feats.reshape(-1, self.in_channels)
      proposal_feat_iic = self.instance_interactive_conv(
          proposal_feat, roi_feat
      )
      proposal_feat = (
          proposal_feat
          + self.instance_interactive_conv_dropout(proposal_feat_iic)
      )
      obj_feat = self.instance_interactive_conv_norm(proposal_feat)
  
      # FFN
      obj_feat = self.ffn_norm(self.ffn(obj_feat))
  
      cls_feat = obj_feat
      reg_feat = obj_feat
  
      for cls_layer in self.cls_fcs:
          cls_feat = cls_layer(cls_feat)
      for reg_layer in self.reg_fcs:
          reg_feat = reg_layer(reg_feat)
  
      cls_score = self.fc_cls(cls_feat).view(
          N,
          num_proposals,
          self.num_classes
          if self.loss_cls.use_sigmoid
          else self.num_classes + 1,
      )
      bbox_delta = self.fc_reg(reg_feat).view(N, num_proposals, 4)
  
      return (
          cls_score,
          bbox_delta,
          obj_feat.view(N, num_proposals, self.in_channels),
          attn_feats,
      )
  
imports: from typing import List
  import torch
  import torch.nn
  from mmcv.cnn import build_activation_layer, build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention
  from mmengine.config import ConfigDict
  from mmengine.model import bias_init_with_prob
  from torch import Tensor
  from mmdet.models.losses import accuracy
  from mmdet.models.task_modules import SamplingResult
  from mmdet.models.utils import multi_apply
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, OptConfigType, reduce_mean
  from .bbox_head import BBoxHead
label_desc: Use image node_id 3 for calling the DIIHead obj's underlying member method code with example usage: obj.forward(roi_feat, proposal_feat) and returns: cls_score,  bbox_delta,  obj_feat,  attn_feats