code: def __init__(
      self,
      img_size: int,
      latent_dim: int = 512,
      out_channels: int = 3,
      *,
      channel_base: int = 32768,
      max_channels: int = 512,
      num_classes: Optional[int] = None,
      conv_clamp: Optional[float] = 256.0,
      **block_kwargs: Any,
  ):
      assert img_size >= 4 and img_size & (img_size - 1) == 0
      super().__init__()
      self.w_dim = latent_dim
      self.img_size = img_size
      self.img_size_log2 = int(round(math.log2(img_size)))
      self.img_channels = out_channels
      self.block_resolutions = [
          2**i for i in range(2, self.img_size_log2 + 1)
      ]
      channels_dict = {
          resolution: min(channel_base // resolution, max_channels)
          for resolution in self.block_resolutions
      }
      self.out_channels = out_channels
      self.num_upsample = len(self.block_resolutions)
      self.latent_resolution = self.block_resolutions[0]
      self.latent_channels = channels_dict[self.latent_resolution]
      self.num_classes = num_classes
      shape = (
          (1 if num_classes is None else num_classes),
          self.latent_channels,
          4,
          4,
      )
      self.const = nn.Parameter(torch.randn(*shape))
      blocks = {}
      self.num_ws = 0
      for resolution in self.block_resolutions:
          in_nc = (
              channels_dict[resolution // 2] if resolution > 4 else 0
          )
          out_nc = channels_dict[resolution]
          is_last = resolution == self.img_size
          block = StyleGAN2Block(
              in_nc,
              out_nc,
              latent_dim=latent_dim,
              resolution=resolution,
              img_channels=out_channels,
              is_last=is_last,
              conv_clamp=conv_clamp,
              **block_kwargs,
          )
          self.num_ws += block.num_conv
          if is_last:
              self.num_ws += block.num_to_rgb
          blocks[str(resolution)] = block
      self.blocks = nn.ModuleDict(blocks)
  
imports: import math
  import torch
  import numpy
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from typing import Any
  from typing import List
  from typing import Tuple
  from typing import Optional
  from cftool.types import tensor_dict_type
  from .schema import Decoder1DMixin
  from ....constants import INPUT_KEY
  from ....constants import LABEL_KEY
  from ....modules.blocks import Conv2d
  from ....modules.blocks import Activation
  from ....modules.blocks import UpsampleConv2d
label_desc: Use image node_id 1 to create a new StyleGAN2Decoder object from inherited base classes: nn with example: obj = StyleGAN2Decoder(img_size, latent_dim, out_channels)