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.
code: def __init__(
      self,
      num_classes: int = 80,
      num_ffn_fcs: int = 2,
      num_heads: int = 8,
      num_cls_fcs: int = 1,
      num_reg_fcs: int = 3,
      feedforward_channels: int = 2048,
      in_channels: int = 256,
      dropout: float = 0.0,
      ffn_act_cfg: ConfigType = dict(type="ReLU", inplace=True),
      dynamic_conv_cfg: ConfigType = dict(
          type="DynamicConv",
          in_channels=256,
          feat_channels=64,
          out_channels=256,
          input_feat_shape=7,
          act_cfg=dict(type="ReLU", inplace=True),
          norm_cfg=dict(type="LN"),
      ),
      loss_iou: ConfigType = dict(type="GIoULoss", loss_weight=2.0),
      init_cfg: OptConfigType = None,
      **kwargs,
  ) -> None:
      assert init_cfg is None, (
          "To prevent abnormal initialization "
          "behavior, init_cfg is not allowed to be set"
      )
      super().__init__(
          num_classes=num_classes,
          reg_decoded_bbox=True,
          reg_class_agnostic=True,
          init_cfg=init_cfg,
          **kwargs,
      )
      self.loss_iou = MODELS.build(loss_iou)
      self.in_channels = in_channels
      self.fp16_enabled = False
      self.attention = MultiheadAttention(
          in_channels, num_heads, dropout
      )
      self.attention_norm = build_norm_layer(
          dict(type="LN"), in_channels
      )[1]
  
      self.instance_interactive_conv = MODELS.build(dynamic_conv_cfg)
      self.instance_interactive_conv_dropout = nn.Dropout(dropout)
      self.instance_interactive_conv_norm = build_norm_layer(
          dict(type="LN"), in_channels
      )[1]
  
      self.ffn = FFN(
          in_channels,
          feedforward_channels,
          num_ffn_fcs,
          act_cfg=ffn_act_cfg,
          dropout=dropout,
      )
      self.ffn_norm = build_norm_layer(dict(type="LN"), in_channels)[1]
  
      self.cls_fcs = nn.ModuleList()
      for _ in range(num_cls_fcs):
          self.cls_fcs.append(
              nn.Linear(in_channels, in_channels, bias=False)
          )
          self.cls_fcs.append(
              build_norm_layer(dict(type="LN"), in_channels)[1]
          )
          self.cls_fcs.append(
              build_activation_layer(dict(type="ReLU", inplace=True))
          )
  
      # over load the self.fc_cls in BBoxHead
      if self.loss_cls.use_sigmoid:
          self.fc_cls = nn.Linear(in_channels, self.num_classes)
      else:
          self.fc_cls = nn.Linear(in_channels, self.num_classes + 1)
  
      self.reg_fcs = nn.ModuleList()
      for _ in range(num_reg_fcs):
          self.reg_fcs.append(
              nn.Linear(in_channels, in_channels, bias=False)
          )
          self.reg_fcs.append(
              build_norm_layer(dict(type="LN"), in_channels)[1]
          )
          self.reg_fcs.append(
              build_activation_layer(dict(type="ReLU", inplace=True))
          )
      # over load the self.fc_cls in BBoxHead
      self.fc_reg = nn.Linear(in_channels, 4)
  
      assert self.reg_class_agnostic, (
          "DIIHead only " "suppport `reg_class_agnostic=True` "
      )
      assert self.reg_decoded_bbox, (
          "DIIHead only " "suppport `reg_decoded_bbox=True`"
      )
  
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 1 to create a new DIIHead object from inherited base classes: BBoxHead with example: obj = DIIHead(num_classes, num_ffn_fcs, num_heads, num_cls_fcs, num_reg_fcs, feedforward_channels, in_channels, dropout, ffn_act_cfg, dynamic_conv_cfg, loss_iou, init_cfg)