class_docstr: FocalNet backbone
  Args:
      arch (str): Architecture of FocalNet
      out_indices (Sequence[int]): Output from which stages.
      frozen_stages (int): Stages to be frozen (stop grad and set eval mode).
          -1 means not freezing any parameters.
      patch_size (int | tuple(int)): Patch size. Default: 4.
      in_chans (int): Number of input image channels. Default: 3.
      embed_dim (int): Number of linear projection output channels. Default: 96.
      depths (tuple[int]): Depths of each FocalNet Transformer stage.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.
      drop_rate (float): Dropout rate.
      drop_path_rate (float): Stochastic depth rate. Default: 0.2.
      norm_layer (nn.Layer): Normalization layer. Default: nn.LayerNorm.
      patch_norm (bool): If True, add normalization after patch embedding. Default: True.
      focal_levels (Sequence[int]): Number of focal levels at four stages
      focal_windows (Sequence[int]): Focal window sizes at first focal level at four stages
      use_conv_embed (bool): Whether use overlapped convolution for patch embedding
      use_layerscale (bool): Whether use layerscale proposed in CaiT. Default: False 
      layerscale_value (float): Value of layerscale
      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_checkpoint (bool): Whether to use checkpointing to save memory. Default: False.
class_docstr_tok: ["FocalNet","backbone","Args",":","arch","(","str",")",":","Architecture","of","FocalNet","out_indices","(","Sequence","[","int","]",")",":","Output","from","which","stages",".","frozen_stages","(","int",")",":","Stages","to","be","frozen","(","stop","grad","and","set","eval","mode",")",".","-1","means","not","freezing","any","parameters",".","patch_size","(","int","|","tuple","(","int",")",")",":","Patch","size",".","Default",":","4.","in_chans","(","int",")",":","Number","of","input","image","channels",".","Default",":","3.","embed_dim","(","int",")",":","Number","of","linear","projection","output","channels",".","Default",":","96.","depths","(","tuple","[","int","]",")",":","Depths","of","each","FocalNet","Transformer","stage",".","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","Default",":","4.","drop_rate","(","float",")",":","Dropout","rate",".","drop_path_rate","(","float",")",":","Stochastic","depth","rate",".","Default",":","0.2.","norm_layer","(","nn.Layer",")",":","Normalization","layer",".","Default",":","nn.LayerNorm",".","patch_norm","(","bool",")",":","If","True",",","add","normalization","after","patch","embedding",".","Default",":","True",".","focal_levels","(","Sequence","[","int","]",")",":","Number","of","focal","levels","at","four","stages","focal_windows","(","Sequence","[","int","]",")",":","Focal","window","sizes","at","first","focal","level","at","four","stages","use_conv_embed","(","bool",")",":","Whether","use","overlapped","convolution","for","patch","embedding","use_layerscale","(","bool",")",":","Whether","use","layerscale","proposed","in","CaiT",".","Default",":","False","layerscale_value","(","float",")",":","Value","of","layerscale","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_checkpoint","(","bool",")",":","Whether","to","use","checkpointing","to","save","memory",".","Default",":","False","."]
code: def __init__(
      self,
      arch="focalnet_T_224_1k_srf",
      out_indices=(0, 1, 2, 3),
      frozen_stages=-1,
      patch_size=4,
      in_chans=3,
      embed_dim=96,
      depths=[2, 2, 6, 2],
      mlp_ratio=4.0,
      drop_rate=0.0,
      drop_path_rate=0.2,  # 0.5 better for large+ models
      norm_layer=nn.LayerNorm,
      patch_norm=True,
      focal_levels=[2, 2, 2, 2],
      focal_windows=[3, 3, 3, 3],
      use_conv_embed=False,
      use_layerscale=False,
      layerscale_value=1e-4,
      use_postln=False,
      use_postln_in_modulation=False,
      normalize_modulator=False,
      use_checkpoint=False,
      pretrained=None,
  ):
      super(FocalNet, self).__init__()
      assert arch in MODEL_cfg.keys(), "Unsupported arch: {}".format(
          arch
      )
  
      embed_dim = MODEL_cfg[arch]["embed_dim"]
      depths = MODEL_cfg[arch]["depths"]
      drop_path_rate = MODEL_cfg[arch]["drop_path_rate"]
      focal_levels = MODEL_cfg[arch]["focal_levels"]
      focal_windows = MODEL_cfg[arch]["focal_windows"]
      use_conv_embed = MODEL_cfg[arch]["use_conv_embed"]
      use_layerscale = MODEL_cfg[arch]["use_layerscale"]
      use_postln = MODEL_cfg[arch]["use_postln"]
      use_postln_in_modulation = MODEL_cfg[arch][
          "use_postln_in_modulation"
      ]
      normalize_modulator = MODEL_cfg[arch]["normalize_modulator"]
      if pretrained is None:
          pretrained = MODEL_cfg[arch]["pretrained"]
  
      self.out_indices = out_indices
      self.frozen_stages = frozen_stages
      self.num_layers = len(depths)
      self.patch_norm = patch_norm
  
      # split image into non-overlapping patches
      self.patch_embed = PatchEmbed(
          patch_size=patch_size,
          in_chans=in_chans,
          embed_dim=embed_dim,
          norm_layer=norm_layer if self.patch_norm else None,
          use_conv_embed=use_conv_embed,
          is_stem=True,
      )
  
      self.pos_drop = nn.Dropout(p=drop_rate)
  
      # stochastic depth decay rule
      dpr = np.linspace(0, drop_path_rate, sum(depths))
  
      # build layers
      self.layers = nn.LayerList()
      for i_layer in range(self.num_layers):
          layer = BasicLayer(
              dim=int(embed_dim * 2**i_layer),
              depth=depths[i_layer],
              mlp_ratio=mlp_ratio,
              drop=drop_rate,
              drop_path=dpr[
                  sum(depths[:i_layer]) : sum(depths[: i_layer + 1])
              ],
              norm_layer=norm_layer,
              downsample=PatchEmbed
              if (i_layer < self.num_layers - 1)
              else None,
              focal_level=focal_levels[i_layer],
              focal_window=focal_windows[i_layer],
              use_conv_embed=use_conv_embed,
              use_layerscale=use_layerscale,
              layerscale_value=layerscale_value,
              use_postln=use_postln,
              use_postln_in_modulation=use_postln_in_modulation,
              normalize_modulator=normalize_modulator,
              use_checkpoint=use_checkpoint,
          )
          self.layers.append(layer)
  
      num_features = [
          int(embed_dim * 2**i) for i in range(self.num_layers)
      ]
      self.num_features = num_features
  
      # add a norm layer for each output
      for i_layer in out_indices:
          layer = norm_layer(num_features[i_layer])
          layer_name = f"norm{i_layer}"
          self.add_sublayer(layer_name, layer)
  
      self.apply(self._init_weights)
      self._freeze_stages()
      if pretrained:
          if "http" in pretrained:  # URL
              path = paddle.utils.download.get_weights_path_from_url(
                  pretrained
              )
          else:  # model in local path
              path = pretrained
          self.set_state_dict(paddle.load(path))
  
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 FocalNet object from inherited base classes: nn with example: obj = FocalNet(arch, out_indices, frozen_stages, patch_size, in_chans, embed_dim, depths, mlp_ratio, drop_rate, drop_path_rate, norm_layer, patch_norm, focal_levels, focal_windows, use_conv_embed, use_layerscale, layerscale_value, use_postln, use_postln_in_modulation, normalize_modulator, use_checkpoint, pretrained)