class_docstr: ConvNeXt
  A PyTorch impl of : `A ConvNet for the 2020s`  - https://arxiv.org/pdf/2201.03545.pdf
class_docstr_tok: ["ConvNeXt","A","PyTorch","impl","of",":","`","A","ConvNet","for","the","2020s","`","-","https",":","\/\/arxiv.org\/pdf\/2201.03545.pdf"]
docstr: Args:
      in_chans: Number of input image channels.
      num_classes: Number of classes for classification head.
      global_pool: Global pooling type.
      output_stride: Output stride of network, one of (8, 16, 32).
      depths: Number of blocks at each stage.
      dims: Feature dimension at each stage.
      kernel_sizes: Depthwise convolution kernel-sizes for each stage.
      ls_init_value: Init value for Layer Scale, disabled if None.
      stem_type: Type of stem.
      patch_size: Stem patch size for patch stem.
      head_init_scale: Init scaling value for classifier weights and biases.
      head_norm_first: Apply normalization before global pool + head.
      head_hidden_size: Size of MLP hidden layer in head if not None and head_norm_first == False.
      conv_mlp: Use 1x1 conv in MLP, improves speed for small networks w/ chan last.
      conv_bias: Use bias layers w/ all convolutions.
      use_grn: Use Global Response Norm (ConvNeXt-V2) in MLP.
      act_layer: Activation layer type.
      norm_layer: Normalization layer type.
      drop_rate: Head pre-classifier dropout rate.
      drop_path_rate: Stochastic depth drop rate.
code: def __init__(
      self,
      in_chans: int = 3,
      num_classes: int = 1000,
      global_pool: str = "avg",
      output_stride: int = 32,
      depths: Tuple[int, ...] = (3, 3, 9, 3),
      dims: Tuple[int, ...] = (96, 192, 384, 768),
      kernel_sizes: Union[int, Tuple[int, ...]] = 7,
      ls_init_value: Optional[float] = 1e-6,
      stem_type: str = "patch",
      patch_size: int = 4,
      head_init_scale: float = 1.0,
      head_norm_first: bool = False,
      head_hidden_size: Optional[int] = None,
      conv_mlp: bool = False,
      conv_bias: bool = True,
      use_grn: bool = False,
      act_layer: Union[str, Callable] = "gelu",
      norm_layer: Optional[Union[str, Callable]] = None,
      norm_eps: Optional[float] = None,
      drop_rate: float = 0.0,
      drop_path_rate: float = 0.0,
  ):
      """
      Args:
          in_chans: Number of input image channels.
          num_classes: Number of classes for classification head.
          global_pool: Global pooling type.
          output_stride: Output stride of network, one of (8, 16, 32).
          depths: Number of blocks at each stage.
          dims: Feature dimension at each stage.
          kernel_sizes: Depthwise convolution kernel-sizes for each stage.
          ls_init_value: Init value for Layer Scale, disabled if None.
          stem_type: Type of stem.
          patch_size: Stem patch size for patch stem.
          head_init_scale: Init scaling value for classifier weights and biases.
          head_norm_first: Apply normalization before global pool + head.
          head_hidden_size: Size of MLP hidden layer in head if not None and head_norm_first == False.
          conv_mlp: Use 1x1 conv in MLP, improves speed for small networks w/ chan last.
          conv_bias: Use bias layers w/ all convolutions.
          use_grn: Use Global Response Norm (ConvNeXt-V2) in MLP.
          act_layer: Activation layer type.
          norm_layer: Normalization layer type.
          drop_rate: Head pre-classifier dropout rate.
          drop_path_rate: Stochastic depth drop rate.
      """
      super().__init__()
      assert output_stride in (8, 16, 32)
      kernel_sizes = to_ntuple(4)(kernel_sizes)
      if norm_layer is None:
          norm_layer = LayerNorm2d
          norm_layer_cl = norm_layer if conv_mlp else LayerNorm
          if norm_eps is not None:
              norm_layer = partial(norm_layer, eps=norm_eps)
              norm_layer_cl = partial(norm_layer_cl, eps=norm_eps)
      else:
          assert (
              conv_mlp
          ), "If a norm_layer is specified, conv MLP must be used so all norm expect rank-4, channels-first input"
          norm_layer_cl = norm_layer
          if norm_eps is not None:
              norm_layer_cl = partial(norm_layer_cl, eps=norm_eps)
  
      self.num_classes = num_classes
      self.drop_rate = drop_rate
      self.feature_info = []
  
      assert stem_type in ("patch", "overlap", "overlap_tiered")
      if stem_type == "patch":
          # NOTE: this stem is a minimal form of ViT PatchEmbed, as used in SwinTransformer w/ patch_size = 4
          self.stem = nn.Sequential(
              nn.Conv2d(
                  in_chans,
                  dims[0],
                  kernel_size=patch_size,
                  stride=patch_size,
                  bias=conv_bias,
              ),
              norm_layer(dims[0]),
          )
          stem_stride = patch_size
      else:
          mid_chs = (
              make_divisible(dims[0] // 2)
              if "tiered" in stem_type
              else dims[0]
          )
          self.stem = nn.Sequential(
              nn.Conv2d(
                  in_chans,
                  mid_chs,
                  kernel_size=3,
                  stride=2,
                  padding=1,
                  bias=conv_bias,
              ),
              nn.Conv2d(
                  mid_chs,
                  dims[0],
                  kernel_size=3,
                  stride=2,
                  padding=1,
                  bias=conv_bias,
              ),
              norm_layer(dims[0]),
          )
          stem_stride = 4
  
      self.stages = nn.Sequential()
      dp_rates = [
          x.tolist()
          for x in torch.linspace(0, drop_path_rate, sum(depths)).split(
              depths
          )
      ]
      stages = []
      prev_chs = dims[0]
      curr_stride = stem_stride
      dilation = 1
      # 4 feature resolution stages, each consisting of multiple residual blocks
      for i in range(4):
          stride = 2 if curr_stride == 2 or i > 0 else 1
          if curr_stride >= output_stride and stride > 1:
              dilation *= stride
              stride = 1
          curr_stride *= stride
          first_dilation = 1 if dilation in (1, 2) else 2
          out_chs = dims[i]
          stages.append(
              ConvNeXtStage(
                  prev_chs,
                  out_chs,
                  kernel_size=kernel_sizes[i],
                  stride=stride,
                  dilation=(first_dilation, dilation),
                  depth=depths[i],
                  drop_path_rates=dp_rates[i],
                  ls_init_value=ls_init_value,
                  conv_mlp=conv_mlp,
                  conv_bias=conv_bias,
                  use_grn=use_grn,
                  act_layer=act_layer,
                  norm_layer=norm_layer,
                  norm_layer_cl=norm_layer_cl,
              )
          )
          prev_chs = out_chs
          # NOTE feature_info use currently assumes stage 0 == stride 1, rest are stride 2
          self.feature_info += [
              dict(
                  num_chs=prev_chs,
                  reduction=curr_stride,
                  module=f"stages.{i}",
              )
          ]
      self.stages = nn.Sequential(*stages)
      self.num_features = prev_chs
  
      # if head_norm_first == true, norm -> global pool -> fc ordering, like most other nets
      # otherwise pool -> norm -> fc, the default ConvNeXt ordering (pretrained FB weights)
      if head_norm_first:
          assert not head_hidden_size
          self.norm_pre = norm_layer(self.num_features)
          self.head = ClassifierHead(
              self.num_features,
              num_classes,
              pool_type=global_pool,
              drop_rate=self.drop_rate,
          )
      else:
          self.norm_pre = nn.Identity()
          self.head = NormMlpClassifierHead(
              self.num_features,
              num_classes,
              hidden_size=head_hidden_size,
              pool_type=global_pool,
              drop_rate=self.drop_rate,
              norm_layer=norm_layer,
              act_layer="gelu",
          )
      named_apply(
          partial(_init_weights, head_init_scale=head_init_scale), self
      )
  
imports: from collections import OrderedDict
  from functools import partial
  from typing import Callable, Optional, Tuple, Union
  import torch
  import torch.nn
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, OPENAI_CLIP_MEAN, OPENAI_CLIP_STD
  from timm.layers import trunc_normal_, AvgPool2dSame, DropPath, Mlp, GlobalResponseNormMlp, LayerNorm2d, LayerNorm, create_conv2d, get_act_layer, make_divisible, to_ntuple
  from timm.layers import NormMlpClassifierHead, ClassifierHead
  from ._builder import build_model_with_cfg
  from ._manipulate import named_apply, checkpoint_seq
  from ._registry import generate_default_cfgs, register_model, register_model_deprecations
label_desc: Use image node_id 1 to create a new ConvNeXt object from inherited base classes: nn with example: obj = ConvNeXt(in_chans, num_classes, global_pool, output_stride, depths, dims, kernel_sizes, ls_init_value, stem_type, patch_size, head_init_scale, head_norm_first, head_hidden_size, conv_mlp, conv_bias, use_grn, act_layer, norm_layer, norm_eps, drop_rate, drop_path_rate)