class_docstr: SegResNetDS based on `3D MRI brain tumor segmentation using autoencoder regularization
  <https://arxiv.org/pdf/1810.11654.pdf>`_.
  It is similar to https://docs.monai.io/en/stable/networks.html#segresnet, with several
  improvements including deep supervision and non-isotropic kernel support.
  
  Args:
      spatial_dims: spatial dimension of the input data. Defaults to 3.
      init_filters: number of output channels for initial convolution layer. Defaults to 32.
      in_channels: number of input channels for the network. Defaults to 1.
      out_channels: number of output channels for the network. Defaults to 2.
      act: activation type and arguments. Defaults to ``RELU``.
      norm: feature normalization type and arguments. Defaults to ``BATCH``.
      blocks_down: number of downsample blocks in each layer. Defaults to ``[1,2,2,4]``.
      blocks_up: number of upsample blocks (optional).
      dsdepth: number of levels for deep supervision. This will be the length of the list of outputs at each scale level.
               At dsdepth==1,only a single output is returned.
      preprocess: optional callable function to apply before the model's forward pass
      resolution: optional input image resolution. When provided, the network will first use non-isotropic kernels to bring
                  image spacing into an approximately isotropic space.
                  Otherwise, by default, the kernel size and downsampling is always isotropic.
class_docstr_tok: ["SegResNetDS","based","on","`","3D","MRI","brain","tumor","segmentation","using","autoencoder","regularization","<","https",":","\/\/arxiv.org\/pdf\/1810.11654.pdf",">","`","_",".","It","is","similar","to","https",":","\/\/docs.monai.io\/en\/stable\/networks.html","#","segresnet",",","with","several","improvements","including","deep","supervision","and","non-isotropic","kernel","support",".","Args",":","spatial_dims",":","spatial","dimension","of","the","input","data",".","Defaults","to","3.","init_filters",":","number","of","output","channels","for","initial","convolution","layer",".","Defaults","to","32.","in_channels",":","number","of","input","channels","for","the","network",".","Defaults","to","1.","out_channels",":","number","of","output","channels","for","the","network",".","Defaults","to","2.","act",":","activation","type","and","arguments",".","Defaults","to","``","RELU","``",".","norm",":","feature","normalization","type","and","arguments",".","Defaults","to","``","BATCH","``",".","blocks_down",":","number","of","downsample","blocks","in","each","layer",".","Defaults","to","``","[","1,2,2,4","]","``",".","blocks_up",":","number","of","upsample","blocks","(","optional",")",".","dsdepth",":","number","of","levels","for","deep","supervision",".","This","will","be","the","length","of","the","list","of","outputs","at","each","scale","level",".","At","dsdepth==1",",","only","a","single","output","is","returned",".","preprocess",":","optional","callable","function","to","apply","before","the","model","'s","forward","pass","resolution",":","optional","input","image","resolution",".","When","provided",",","the","network","will","first","use","non-isotropic","kernels","to","bring","image","spacing","into","an","approximately","isotropic","space",".","Otherwise",",","by","default",",","the","kernel","size","and","downsampling","is","always","isotropic","."]
code: def __init__(
      self,
      spatial_dims: int = 3,
      init_filters: int = 32,
      in_channels: int = 1,
      out_channels: int = 2,
      act: tuple | str = "relu",
      norm: tuple | str = "batch",
      blocks_down: tuple = (1, 2, 2, 4),
      blocks_up: tuple | None = None,
      dsdepth: int = 1,
      preprocess: nn.Module | Callable | None = None,
      upsample_mode: UpsampleMode | str = "deconv",
      resolution: tuple | None = None,
  ):
      super().__init__()
  
      if spatial_dims not in (1, 2, 3):
          raise ValueError("`spatial_dims` can only be 1, 2 or 3.")
  
      self.spatial_dims = spatial_dims
      self.init_filters = init_filters
      self.in_channels = in_channels
      self.out_channels = out_channels
      self.act = act
      self.norm = norm
      self.blocks_down = blocks_down
      self.dsdepth = max(dsdepth, 1)
      self.resolution = resolution
      self.preprocess = preprocess
  
      if resolution is not None:
          if not isinstance(resolution, (list, tuple)):
              raise TypeError("resolution must be a tuple")
          elif not all(r > 0 for r in resolution):
              raise ValueError("resolution must be positive")
  
      # ensure normalization had affine trainable parameters (if not specified)
      norm = split_args(norm)
      if has_option(Norm[norm[0], spatial_dims], "affine"):
          norm[1].setdefault("affine", True)  # type: ignore
  
      # ensure activation is inplace (if not specified)
      act = split_args(act)
      if has_option(Act[act[0]], "inplace"):
          act[1].setdefault("inplace", True)  # type: ignore
  
      anisotropic_scales = None
      if resolution:
          anisotropic_scales = scales_for_resolution(
              resolution, n_stages=len(blocks_down)
          )
      self.anisotropic_scales = anisotropic_scales
  
      self.encoder = SegResEncoder(
          spatial_dims=spatial_dims,
          init_filters=init_filters,
          in_channels=in_channels,
          act=act,
          norm=norm,
          blocks_down=blocks_down,
          anisotropic_scales=anisotropic_scales,
      )
  
      n_up = len(blocks_down) - 1
      if blocks_up is None:
          blocks_up = (1,) * n_up  # assume 1 upsample block per level
      self.blocks_up = blocks_up
  
      filters = init_filters * 2**n_up
      self.up_layers = nn.ModuleList()
  
      for i in range(n_up):
          filters = filters // 2
          kernel_size, _, stride = (
              aniso_kernel(anisotropic_scales[len(blocks_up) - i - 1])
              if anisotropic_scales
              else (3, 1, 2)
          )
  
          level = nn.ModuleDict()
          level["upsample"] = UpSample(
              mode=upsample_mode,
              spatial_dims=spatial_dims,
              in_channels=2 * filters,
              out_channels=filters,
              kernel_size=kernel_size,
              scale_factor=stride,
              bias=False,
              align_corners=False,
          )
          blocks = [
              SegResBlock(
                  spatial_dims=spatial_dims,
                  in_channels=filters,
                  kernel_size=kernel_size,
                  norm=norm,
                  act=act,
              )
              for _ in range(blocks_up[i])
          ]
          level["blocks"] = nn.Sequential(*blocks)
  
          if len(blocks_up) - i <= dsdepth:  # deep supervision heads
              level["head"] = Conv[Conv.CONV, spatial_dims](
                  in_channels=filters,
                  out_channels=out_channels,
                  kernel_size=1,
                  bias=True,
              )
          else:
              level["head"] = nn.Identity()
  
          self.up_layers.append(level)
  
      if (
          n_up == 0
      ):  # in a corner case of flat structure (no downsampling), attache a single head
          level = nn.ModuleDict(
              {
                  "upsample": nn.Identity(),
                  "blocks": nn.Identity(),
                  "head": Conv[Conv.CONV, spatial_dims](
                      in_channels=filters,
                      out_channels=out_channels,
                      kernel_size=1,
                      bias=True,
                  ),
              }
          )
          self.up_layers.append(level)
  
imports: from __future__ import annotations
  from collections.abc import Callable
  from typing import Union
  import numpy
  import torch
  import torch.nn
  from monai.networks.blocks.upsample import UpSample
  from monai.networks.layers.factories import Act, Conv, Norm, split_args
  from monai.networks.layers.utils import get_act_layer, get_norm_layer
  from monai.utils import UpsampleMode, has_option
label_desc: Use image node_id 1 to create a new SegResNetDS object from inherited base classes: nn with example: obj = SegResNetDS(spatial_dims, init_filters, in_channels, out_channels, act, norm, blocks_down, blocks_up, dsdepth, preprocess, upsample_mode, resolution)