class_docstr: A basic Focal Transformer layer for one stage.
      
class_docstr_tok: ["A","basic","Focal","Transformer","layer","for","one","stage","."]
docstr: Args:
      dim: Number of input channels.
      out_dim: Number of output channels.
      depth: Number of blocks.
      mlp_ratio: Ratio of mlp hidden dim to embedding dim.
      downsample: Downsample layer at start of the layer.
      focal_level: Number of focal levels
      focal_window: Focal window size at first focal level
      use_overlap_down: User overlapped convolution in downsample layer.
      use_post_norm: Whether to use layer norm after modulation.
      use_post_norm_in_modulation: Whether to use layer norm in modulation.
      layerscale_value: Initial layerscale value
      proj_drop: Dropout rate for projections.
      drop_path: Stochastic depth rate.
      norm_layer: Normalization layer.
docstr_tok: ["Args",":","dim",":","Number","of","input","channels",".","out_dim",":","Number","of","output","channels",".","depth",":","Number","of","blocks",".","mlp_ratio",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","downsample",":","Downsample","layer","at","start","of","the","layer",".","focal_level",":","Number","of","focal","levels","focal_window",":","Focal","window","size","at","first","focal","level","use_overlap_down",":","User","overlapped","convolution","in","downsample","layer",".","use_post_norm",":","Whether","to","use","layer","norm","after","modulation",".","use_post_norm_in_modulation",":","Whether","to","use","layer","norm","in","modulation",".","layerscale_value",":","Initial","layerscale","value","proj_drop",":","Dropout","rate","for","projections",".","drop_path",":","Stochastic","depth","rate",".","norm_layer",":","Normalization","layer","."]
code: def __init__(
      self,
      dim: int,
      out_dim: int,
      depth: int,
      mlp_ratio: float = 4.0,
      downsample: bool = True,
      focal_level: int = 1,
      focal_window: int = 1,
      use_overlap_down: bool = False,
      use_post_norm: bool = False,
      use_post_norm_in_modulation: bool = False,
      normalize_modulator: bool = False,
      layerscale_value: float = 1e-4,
      proj_drop: float = 0.0,
      drop_path: float = 0.0,
      norm_layer: Callable = LayerNorm2d,
  ):
      """
      Args:
          dim: Number of input channels.
          out_dim: Number of output channels.
          depth: Number of blocks.
          mlp_ratio: Ratio of mlp hidden dim to embedding dim.
          downsample: Downsample layer at start of the layer.
          focal_level: Number of focal levels
          focal_window: Focal window size at first focal level
          use_overlap_down: User overlapped convolution in downsample layer.
          use_post_norm: Whether to use layer norm after modulation.
          use_post_norm_in_modulation: Whether to use layer norm in modulation.
          layerscale_value: Initial layerscale value
          proj_drop: Dropout rate for projections.
          drop_path: Stochastic depth rate.
          norm_layer: Normalization layer.
      """
      super().__init__()
      self.dim = dim
      self.depth = depth
      self.grad_checkpointing = False
  
      if downsample:
          self.downsample = Downsample(
              in_chs=dim,
              out_chs=out_dim,
              stride=2,
              overlap=use_overlap_down,
              norm_layer=norm_layer,
          )
      else:
          self.downsample = nn.Identity()
  
      # build blocks
      self.blocks = nn.ModuleList(
          [
              FocalNetBlock(
                  dim=out_dim,
                  mlp_ratio=mlp_ratio,
                  focal_level=focal_level,
                  focal_window=focal_window,
                  use_post_norm=use_post_norm,
                  use_post_norm_in_modulation=use_post_norm_in_modulation,
                  normalize_modulator=normalize_modulator,
                  layerscale_value=layerscale_value,
                  proj_drop=proj_drop,
                  drop_path=drop_path[i]
                  if isinstance(drop_path, list)
                  else drop_path,
                  norm_layer=norm_layer,
              )
              for i in range(depth)
          ]
      )
  
imports: from functools import partial
  from typing import Callable, Optional, Tuple
  import torch
  import torch.nn
  import torch.utils.checkpoint
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import Mlp, DropPath, LayerNorm2d, trunc_normal_, ClassifierHead, NormMlpClassifierHead
  from ._builder import build_model_with_cfg
  from ._manipulate import named_apply
  from ._registry import generate_default_cfgs, register_model
label_desc: Use image node_id 1 to create a new FocalNetStage object from inherited base classes: nn with example: obj = FocalNetStage(dim, out_dim, depth, mlp_ratio, downsample, focal_level, focal_window, use_overlap_down, use_post_norm, use_post_norm_in_modulation, normalize_modulator, layerscale_value, proj_drop, drop_path, norm_layer)