class_docstr: TimeSformer block.
  
  Args:
      dim (`int`):
          feature dimension
      num_heads (`int`):
          number of attention heads
      mlp_ratio (`float`):
          mlp ratio
      qkv_bias (`bool=False`):
          if use qkv_bias
      qk_scale (`float=None`):
          number to scale qk
      drop (`float=0.`):
          drop rate of projection in attention & MLP layers
      attn_drop (`float=0.`):
          attention drop rate
      drop_path (`float=0.1`):
          drop probability in DropPath
      act_layer (`nn.module=nn.GELU`):
          module used in activation layer
      norm_layer (`nn.module=nn.LayerNorm`):
          module used in normalization layer
      attention_type (`str='divided_space_time`):
          type of TimeSformer attention from ['divided_space_time', 'space_only', 'joint_space_time']
  
  Example:
      >>> import torch
      >>> from towhee.models.timesformer.timesformer_block import Block
      >>>
      >>> test_shape = (1, 196*8+1, 768)
      >>> fake_x = torch.rand(test_shape)
      >>> model = Block(dim=768, num_heads=12)
      >>> out = model(fake_x, b=1, t=8, w=int(224/16))
      >>> print(out.shape)
      torch.Size([1, 1569, 768])
code: def __init__(
      self,
      dim,
      num_heads,
      mlp_ratio=4.0,
      qkv_bias=False,
      qk_scale=None,
      drop=0.0,
      attn_drop=0.0,
      drop_path=0.1,
      act_layer=nn.GELU,
      norm_layer=nn.LayerNorm,
      attention_type="divided_space_time",
  ):
      super().__init__()
      self.attention_type = attention_type
      assert attention_type in [
          "divided_space_time",
          "space_only",
          "joint_space_time",
          "frozen_in_time",
      ]
  
      self.norm1 = norm_layer(dim)
      self.attn = MultiHeadAttention(
          dim,
          num_heads=num_heads,
          qkv_bias=qkv_bias,
          qk_scale=qk_scale,
          attn_drop_ratio=attn_drop,
          proj_drop_ratio=drop,
      )
  
      # Temporal Attention Parameters
      if self.attention_type in [
          "divided_space_time",
          "frozen_in_time",
      ]:
          self.temporal_norm1 = norm_layer(dim)
          self.temporal_attn = MultiHeadAttention(
              dim,
              num_heads=num_heads,
              qkv_bias=qkv_bias,
              qk_scale=qk_scale,
              attn_drop_ratio=attn_drop,
              proj_drop_ratio=drop,
          )
          self.temporal_fc = nn.Linear(dim, dim)
  
      # Drop path
      self.drop_path = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
      self.norm2 = norm_layer(dim)
      mlp_hidden_dim = int(dim * mlp_ratio)
      self.mlp = Mlp(
          in_features=dim,
          hidden_features=mlp_hidden_dim,
          act_layer=act_layer,
          drop=drop,
      )
  
file_path: towhee/towhee/models/timesformer/timesformer_block.py
imports: import os
  import torch
  from torch import nn
  from towhee.models.layers.attention import MultiHeadAttention
  from towhee.models.layers.droppath import DropPath
  from towhee.models.layers.mlp import Mlp
label_desc: Use image node_id 1 to create a new Block object from inherited base classes: nn with example: obj = Block(dim, num_heads, mlp_ratio, qkv_bias, qk_scale, drop, attn_drop, drop_path, act_layer, norm_layer, attention_type)