class_docstr: Focal Modulation Block.
  Args:
      dim (int): Number of input channels.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
      drop (float, optional): Dropout rate. Default: 0.0
      drop_path (float, optional): Stochastic depth rate. Default: 0.0
      act_layer (nn.Layer, optional): Activation layer. Default: nn.GELU
      norm_layer (nn.Layer, optional): Normalization layer.  Default: nn.LayerNorm
      focal_level (int): number of focal levels
      focal_window (int): focal kernel size at level 1
      use_postln (bool): Whether use layernorm after modulation. Default: False.
      use_postln_in_modulation (bool): Whether use post-modulation layernorm. Default: False.
      normalize_modulator (bool): Whether use normalize in modulator
      use_layerscale (bool): Whether use layerscale proposed in CaiT. Default: False 
      layerscale_value (float): Value for layer scale. Default: 1e-4 
class_docstr_tok: ["Focal","Modulation","Block",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","drop","(","float",",","optional",")",":","Dropout","rate",".","Default",":","0.0","drop_path","(","float",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.0","act_layer","(","nn.Layer",",","optional",")",":","Activation","layer",".","Default",":","nn.GELU","norm_layer","(","nn.Layer",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm","focal_level","(","int",")",":","number","of","focal","levels","focal_window","(","int",")",":","focal","kernel","size","at","level","1","use_postln","(","bool",")",":","Whether","use","layernorm","after","modulation",".","Default",":","False",".","use_postln_in_modulation","(","bool",")",":","Whether","use","post-modulation","layernorm",".","Default",":","False",".","normalize_modulator","(","bool",")",":","Whether","use","normalize","in","modulator","use_layerscale","(","bool",")",":","Whether","use","layerscale","proposed","in","CaiT",".","Default",":","False","layerscale_value","(","float",")",":","Value","for","layer","scale",".","Default",":","1e-4"]
code: def __init__(
      self,
      dim,
      mlp_ratio=4.0,
      drop=0.0,
      drop_path=0.0,
      act_layer=nn.GELU,
      norm_layer=nn.LayerNorm,
      focal_level=2,
      focal_window=9,
      use_postln=False,
      use_postln_in_modulation=False,
      normalize_modulator=False,
      use_layerscale=False,
      layerscale_value=1e-4,
  ):
      super().__init__()
      self.dim = dim
      self.mlp_ratio = mlp_ratio
      self.focal_window = focal_window
      self.focal_level = focal_level
      self.use_postln = use_postln
      self.use_layerscale = use_layerscale
  
      self.norm1 = norm_layer(dim)
      self.modulation = FocalModulation(
          dim,
          proj_drop=drop,
          focal_level=self.focal_level,
          focal_window=self.focal_window,
          use_postln_in_modulation=use_postln_in_modulation,
          normalize_modulator=normalize_modulator,
      )
  
      self.drop_path = (
          DropPath(drop_path) if drop_path > 0.0 else 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,
      )
      self.H = None
      self.W = None
  
      self.gamma_1 = 1.0
      self.gamma_2 = 1.0
      if self.use_layerscale:
          self.gamma_1 = add_parameter(
              self, layerscale_value * paddle.ones([dim])
          )
          self.gamma_2 = add_parameter(
              self, layerscale_value * paddle.ones([dim])
          )
  
imports: import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from ppdet.modeling.shape_spec import ShapeSpec
  from ppdet.core.workspace import register, serializable
  from .transformer_utils import DropPath, Identity
  from .transformer_utils import add_parameter, to_2tuple
  from .transformer_utils import ones_, zeros_, trunc_normal_
  from .swin_transformer import Mlp
label_desc: Use image node_id 1 to create a new FocalModulationBlock object from inherited base classes: nn with example: obj = FocalModulationBlock(dim, mlp_ratio, drop, drop_path, act_layer, norm_layer, focal_level, focal_window, use_postln, use_postln_in_modulation, normalize_modulator, use_layerscale, layerscale_value)