class_docstr: Args:
      dim (int): Number of input channels.
      proj_drop (float, optional): Dropout ratio of output. Default: 0.0
      focal_level (int): Number of focal levels
      focal_window (int): Focal window size at focal level 1
      focal_factor (int): Step to increase the focal window. Default: 2
      use_postln_in_modulation (bool): Whether use post-modulation layernorm
      normalize_modulator (bool): Whether use normalize in modulator
class_docstr_tok: ["Args",":","dim","(","int",")",":","Number","of","input","channels",".","proj_drop","(","float",",","optional",")",":","Dropout","ratio","of","output",".","Default",":","0.0","focal_level","(","int",")",":","Number","of","focal","levels","focal_window","(","int",")",":","Focal","window","size","at","focal","level","1","focal_factor","(","int",")",":","Step","to","increase","the","focal","window",".","Default",":","2","use_postln_in_modulation","(","bool",")",":","Whether","use","post-modulation","layernorm","normalize_modulator","(","bool",")",":","Whether","use","normalize","in","modulator"]
docstr: Forward function.
  Args:
      x: input features with shape of (B, H, W, C)
docstr_tok: ["Forward","function",".","Args",":","x",":","input","features","with","shape","of","(","B",",","H",",","W",",","C",")"]
code: def forward(self, x):
      """Forward function.
      Args:
          x: input features with shape of (B, H, W, C)
      """
      _, _, _, C = x.shape
      x = self.f(x)
      x = x.transpose([0, 3, 1, 2])
      q, ctx, gates = paddle.split(x, (C, C, self.focal_level + 1), 1)
  
      ctx_all = 0
      for l in range(self.focal_level):
          ctx = self.focal_layers[l](ctx)
          ctx_all = ctx_all + ctx * gates[:, l : l + 1]
      ctx_global = self.act(
          ctx.mean(2, keepdim=True).mean(3, keepdim=True)
      )
      ctx_all = ctx_all + ctx_global * gates[:, self.focal_level :]
      if self.normalize_modulator:
          ctx_all = ctx_all / (self.focal_level + 1)
  
      x_out = q * self.h(ctx_all)
      x_out = x_out.transpose([0, 2, 3, 1])
      if self.use_postln_in_modulation:
          x_out = self.ln(x_out)
      x_out = self.proj(x_out)
      x_out = self.proj_drop(x_out)
      return x_out
  
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 2 for calling the FocalModulation obj's underlying member method code with example usage: obj.forward(x) and returns: x_out