class_docstr: Multiscale Transformer blocks
class_docstr_tok: ["Multiscale","Transformer","blocks"]
docstr: Args:
      dim (int): Number of input channels.
      dim_out (int): Number of output channels.
      num_heads (int): Number of attention heads in the MViT block.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
      qkv_bias (bool): If True, add a learnable bias to query, key, value.
      drop_path (float): Stochastic depth rate.
      norm_layer (nn.Module): Normalization layer.
      act_layer (nn.Module): Activation layer.
      qkv_pool_kernel (tuple): kernel size for qkv pooling layers.
      stride_q (int): stride size for q pooling layer.
      stride_kv (int): stride size for kv pooling layer.
      residual_pooling (bool): If true, enable residual pooling.
      window_size (int): Window size for window attention blocks. If it equals 0, then not
          use window attention.
      use_rel_pos (bool): If True, add relative postional embeddings to the attention map.
      rel_pos_zero_init (bool): If True, zero initialize relative positional parameters.
      input_size (int or None): Input resolution.
docstr_tok: ["Args",":","dim","(","int",")",":","Number","of","input","channels",".","dim_out","(","int",")",":","Number","of","output","channels",".","num_heads","(","int",")",":","Number","of","attention","heads","in","the","MViT","block",".","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","qkv_bias","(","bool",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","drop_path","(","float",")",":","Stochastic","depth","rate",".","norm_layer","(","nn.Module",")",":","Normalization","layer",".","act_layer","(","nn.Module",")",":","Activation","layer",".","qkv_pool_kernel","(","tuple",")",":","kernel","size","for","qkv","pooling","layers",".","stride_q","(","int",")",":","stride","size","for","q","pooling","layer",".","stride_kv","(","int",")",":","stride","size","for","kv","pooling","layer",".","residual_pooling","(","bool",")",":","If","true",",","enable","residual","pooling",".","window_size","(","int",")",":","Window","size","for","window","attention","blocks",".","If","it","equals","0",",","then","not","use","window","attention",".","use_rel_pos","(","bool",")",":","If","True",",","add","relative","postional","embeddings","to","the","attention","map",".","rel_pos_zero_init","(","bool",")",":","If","True",",","zero","initialize","relative","positional","parameters",".","input_size","(","int","or","None",")",":","Input","resolution","."]
code: def __init__(
      self,
      dim,
      dim_out,
      num_heads,
      mlp_ratio=4.0,
      qkv_bias=True,
      drop_path=0.0,
      norm_layer=nn.LayerNorm,
      act_layer=nn.GELU,
      qkv_pool_kernel=(3, 3),
      stride_q=1,
      stride_kv=1,
      residual_pooling=True,
      window_size=0,
      use_rel_pos=False,
      rel_pos_zero_init=True,
      input_size=None,
  ):
      """
      Args:
          dim (int): Number of input channels.
          dim_out (int): Number of output channels.
          num_heads (int): Number of attention heads in the MViT block.
          mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
          qkv_bias (bool): If True, add a learnable bias to query, key, value.
          drop_path (float): Stochastic depth rate.
          norm_layer (nn.Module): Normalization layer.
          act_layer (nn.Module): Activation layer.
          qkv_pool_kernel (tuple): kernel size for qkv pooling layers.
          stride_q (int): stride size for q pooling layer.
          stride_kv (int): stride size for kv pooling layer.
          residual_pooling (bool): If true, enable residual pooling.
          window_size (int): Window size for window attention blocks. If it equals 0, then not
              use window attention.
          use_rel_pos (bool): If True, add relative postional embeddings to the attention map.
          rel_pos_zero_init (bool): If True, zero initialize relative positional parameters.
          input_size (int or None): Input resolution.
      """
      super().__init__()
      self.norm1 = norm_layer(dim)
      self.attn = MultiScaleAttention(
          dim,
          dim_out,
          num_heads=num_heads,
          qkv_bias=qkv_bias,
          norm_layer=norm_layer,
          pool_kernel=qkv_pool_kernel,
          stride_q=stride_q,
          stride_kv=stride_kv,
          residual_pooling=residual_pooling,
          window_size=window_size,
          use_rel_pos=use_rel_pos,
          rel_pos_zero_init=rel_pos_zero_init,
          input_size=input_size,
      )
  
      from timm.models.layers import DropPath, Mlp
  
      self.drop_path = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
      self.norm2 = norm_layer(dim_out)
      self.mlp = Mlp(
          in_features=dim_out,
          hidden_features=int(dim_out * mlp_ratio),
          out_features=dim_out,
          act_layer=act_layer,
      )
  
      if dim != dim_out:
          self.proj = nn.Linear(dim, dim_out)
  
      if stride_q > 1:
          kernel_skip = stride_q + 1
          padding_skip = int(kernel_skip // 2)
          self.pool_skip = nn.MaxPool2d(
              kernel_skip, stride_q, padding_skip, ceil_mode=False
          )
  
file_path: detectron2/detectron2/modeling/backbone/mvit.py
imports: import logging
  import numpy
  import torch
  import torch.nn
  from .backbone import Backbone
  from .utils import PatchEmbed, add_decomposed_rel_pos, get_abs_pos, window_partition, window_unpartition
label_desc: Use image node_id 1 to create a new MultiScaleBlock object from inherited base classes: nn with example: obj = MultiScaleBlock(dim, dim_out, num_heads, mlp_ratio, qkv_bias, drop_path, norm_layer, act_layer, qkv_pool_kernel, stride_q, stride_kv, residual_pooling, window_size, use_rel_pos, rel_pos_zero_init, input_size)