class_docstr: SOLOv2 mask head used in `SOLOv2: Dynamic and Fast Instance
  Segmentation. <https://arxiv.org/pdf/2003.10152>`_
  
  Args:
      mask_feature_head (dict): Config of SOLOv2MaskFeatHead.
      dynamic_conv_size (int): Dynamic Conv kernel size. Defaults to 1.
      dcn_cfg (dict): Dcn conv configurations in kernel_convs and cls_conv.
          Defaults to None.
      dcn_apply_to_all_conv (bool): Whether to use dcn in every layer of
          kernel_convs and cls_convs, or only the last layer. It shall be set
          `True` for the normal version of SOLOv2 and `False` for the
          light-weight version. Defaults to True.
      init_cfg (dict or list[dict], optional): Initialization config dict.
class_docstr_tok: ["SOLOv2","mask","head","used","in","`","SOLOv2",":","Dynamic","and","Fast","Instance","Segmentation",".","<","https",":","\/\/arxiv.org\/pdf\/2003.10152",">","`","_","Args",":","mask_feature_head","(","dict",")",":","Config","of","SOLOv2MaskFeatHead",".","dynamic_conv_size","(","int",")",":","Dynamic","Conv","kernel","size",".","Defaults","to","1.","dcn_cfg","(","dict",")",":","Dcn","conv","configurations","in","kernel_convs","and","cls_conv",".","Defaults","to","None",".","dcn_apply_to_all_conv","(","bool",")",":","Whether","to","use","dcn","in","every","layer","of","kernel_convs","and","cls_convs",",","or","only","the","last","layer",".","It","shall","be","set","`","True","`","for","the","normal","version","of","SOLOv2","and","`","False","`","for","the","light-weight","version",".","Defaults","to","True",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict","."]
docstr: Forward features from the upstream network.
  
  Args:
      x (tuple[Tensor]): Features from the upstream network, each is
          a 4D-tensor.
  
  Returns:
      tuple: A tuple of classification scores, mask prediction,
      and mask features.
  
          - mlvl_kernel_preds (list[Tensor]): Multi-level dynamic kernel
            prediction. The kernel is used to generate instance
            segmentation masks by dynamic convolution. Each element in
            the list has shape
            (batch_size, kernel_out_channels, num_grids, num_grids).
          - mlvl_cls_preds (list[Tensor]): Multi-level scores. Each
            element in the list has shape
            (batch_size, num_classes, num_grids, num_grids).
          - mask_feats (Tensor): Unified mask feature map used to
            generate instance segmentation masks by dynamic convolution.
            Has shape (batch_size, mask_out_channels, h, w).
docstr_tok: ["Forward","features","from","the","upstream","network",".","Args",":","x","(","tuple","[","Tensor","]",")",":","Features","from","the","upstream","network",",","each","is","a","4D-tensor",".","Returns",":","tuple",":","A","tuple","of","classification","scores",",","mask","prediction",",","and","mask","features",".","-","mlvl_kernel_preds","(","list","[","Tensor","]",")",":","Multi-level","dynamic","kernel","prediction",".","The","kernel","is","used","to","generate","instance","segmentation","masks","by","dynamic","convolution",".","Each","element","in","the","list","has","shape","(","batch_size",",","kernel_out_channels",",","num_grids",",","num_grids",")",".","-","mlvl_cls_preds","(","list","[","Tensor","]",")",":","Multi-level","scores",".","Each","element","in","the","list","has","shape","(","batch_size",",","num_classes",",","num_grids",",","num_grids",")",".","-","mask_feats","(","Tensor",")",":","Unified","mask","feature","map","used","to","generate","instance","segmentation","masks","by","dynamic","convolution",".","Has","shape","(","batch_size",",","mask_out_channels",",","h",",","w",")","."]
code: def forward(self, x):
      """Forward features from the upstream network.
  
      Args:
          x (tuple[Tensor]): Features from the upstream network, each is
              a 4D-tensor.
  
      Returns:
          tuple: A tuple of classification scores, mask prediction,
          and mask features.
  
              - mlvl_kernel_preds (list[Tensor]): Multi-level dynamic kernel
                prediction. The kernel is used to generate instance
                segmentation masks by dynamic convolution. Each element in
                the list has shape
                (batch_size, kernel_out_channels, num_grids, num_grids).
              - mlvl_cls_preds (list[Tensor]): Multi-level scores. Each
                element in the list has shape
                (batch_size, num_classes, num_grids, num_grids).
              - mask_feats (Tensor): Unified mask feature map used to
                generate instance segmentation masks by dynamic convolution.
                Has shape (batch_size, mask_out_channels, h, w).
      """
      assert len(x) == self.num_levels
      mask_feats = self.mask_feature_head(x)
      ins_kernel_feats = self.resize_feats(x)
      mlvl_kernel_preds = []
      mlvl_cls_preds = []
      for i in range(self.num_levels):
          ins_kernel_feat = ins_kernel_feats[i]
          # ins branch
          # concat coord
          coord_feat = generate_coordinate(
              ins_kernel_feat.size(), ins_kernel_feat.device
          )
          ins_kernel_feat = torch.cat([ins_kernel_feat, coord_feat], 1)
  
          # kernel branch
          kernel_feat = ins_kernel_feat
          kernel_feat = F.interpolate(
              kernel_feat,
              size=self.num_grids[i],
              mode="bilinear",
              align_corners=False,
          )
  
          cate_feat = kernel_feat[:, :-2, :, :]
  
          kernel_feat = kernel_feat.contiguous()
          for i, kernel_conv in enumerate(self.kernel_convs):
              kernel_feat = kernel_conv(kernel_feat)
          kernel_pred = self.conv_kernel(kernel_feat)
  
          # cate branch
          cate_feat = cate_feat.contiguous()
          for i, cls_conv in enumerate(self.cls_convs):
              cate_feat = cls_conv(cate_feat)
          cate_pred = self.conv_cls(cate_feat)
  
          mlvl_kernel_preds.append(kernel_pred)
          mlvl_cls_preds.append(cate_pred)
  
      return mlvl_kernel_preds, mlvl_cls_preds, mask_feats
  
imports: import warnings
  from typing import List, Optional, Tuple
  import mmcv
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.utils.misc import floordiv
  from mmdet.registry import MODELS
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType
  from ..layers import mask_matrix_nms
  from ..utils import center_of_mass, generate_coordinate, multi_apply
  from .solo_head import SOLOHead
label_desc: Use image node_id 3 for calling the SOLOV2Head obj's underlying member method code with example usage: obj.forward(x) and returns: mlvl_kernel_preds,  mlvl_cls_preds,  mask_feats