class_docstr: NCSN++ model, adapted from https://github.com/yang-song/score_sde and
  https://github.com/sp-uhh/sgmse repository
code: def __init__(
      self,
      scale_by_sigma=True,
      nonlinearity="swish",
      nf=128,
      ch_mult=(1, 1, 2, 2, 2, 2, 2),
      num_res_blocks=2,
      attn_resolutions=(16,),
      resamp_with_conv=True,
      conditional=True,
      fir=True,
      fir_kernel=[1, 3, 3, 1],
      skip_rescale=True,
      resblock_type="biggan",
      progressive="output_skip",
      progressive_input="input_skip",
      progressive_combine="sum",
      init_scale=0.0,
      fourier_scale=16,
      image_size=256,
      embedding_type="fourier",
      dropout=0.0,
      centered=True,
      **unused_kwargs,
  ):
      super().__init__()
      self.act = act = get_act(nonlinearity)
  
      self.nf = nf = nf
      ch_mult = ch_mult
      self.num_res_blocks = num_res_blocks = num_res_blocks
      self.attn_resolutions = attn_resolutions = attn_resolutions
      dropout = dropout
      resamp_with_conv = resamp_with_conv
      self.num_resolutions = num_resolutions = len(ch_mult)
      self.all_resolutions = all_resolutions = [
          image_size // (2**i) for i in range(num_resolutions)
      ]
  
      self.conditional = conditional = conditional  # noise-conditional
      self.centered = centered
      self.scale_by_sigma = scale_by_sigma
  
      fir = fir
      fir_kernel = fir_kernel
      self.skip_rescale = skip_rescale = skip_rescale
      self.resblock_type = resblock_type = resblock_type.lower()
      self.progressive = progressive = progressive.lower()
      self.progressive_input = (
          progressive_input
      ) = progressive_input.lower()
      self.embedding_type = embedding_type = embedding_type.lower()
      init_scale = init_scale
      assert progressive in ["none", "output_skip", "residual"]
      assert progressive_input in ["none", "input_skip", "residual"]
      assert embedding_type in ["fourier", "positional"]
      combine_method = progressive_combine.lower()
      combiner = functools.partial(Combine, method=combine_method)
  
      num_channels = 4  # x.real, x.imag, y.real, y.imag
      self.output_layer = nn.Conv2d(num_channels, 2, 1)
  
      modules = []
      # timestep/noise_level embedding
      if embedding_type == "fourier":
          # Gaussian Fourier features embeddings.
          modules.append(
              layerspp.GaussianFourierProjection(
                  embedding_size=nf, scale=fourier_scale
              )
          )
          embed_dim = 2 * nf
      elif embedding_type == "positional":
          embed_dim = nf
      else:
          raise ValueError(f"embedding type {embedding_type} unknown.")
  
      if conditional:
          modules.append(nn.Linear(embed_dim, nf * 4))
          modules[-1].weight.data = default_initializer()(
              modules[-1].weight.shape
          )
          nn.init.zeros_(modules[-1].bias)
          modules.append(nn.Linear(nf * 4, nf * 4))
          modules[-1].weight.data = default_initializer()(
              modules[-1].weight.shape
          )
          nn.init.zeros_(modules[-1].bias)
  
      AttnBlock = functools.partial(
          layerspp.AttnBlockpp,
          init_scale=init_scale,
          skip_rescale=skip_rescale,
      )
  
      Upsample = functools.partial(
          layerspp.Upsample,
          with_conv=resamp_with_conv,
          fir=fir,
          fir_kernel=fir_kernel,
      )
  
      if progressive == "output_skip":
          self.pyramid_upsample = layerspp.Upsample(
              fir=fir, fir_kernel=fir_kernel, with_conv=False
          )
      elif progressive == "residual":
          pyramid_upsample = functools.partial(
              layerspp.Upsample,
              fir=fir,
              fir_kernel=fir_kernel,
              with_conv=True,
          )
  
      Downsample = functools.partial(
          layerspp.Downsample,
          with_conv=resamp_with_conv,
          fir=fir,
          fir_kernel=fir_kernel,
      )
  
      if progressive_input == "input_skip":
          self.pyramid_downsample = layerspp.Downsample(
              fir=fir, fir_kernel=fir_kernel, with_conv=False
          )
      elif progressive_input == "residual":
          pyramid_downsample = functools.partial(
              layerspp.Downsample,
              fir=fir,
              fir_kernel=fir_kernel,
              with_conv=True,
          )
  
      if resblock_type == "ddpm":
          ResnetBlock = functools.partial(
              ResnetBlockDDPM,
              act=act,
              dropout=dropout,
              init_scale=init_scale,
              skip_rescale=skip_rescale,
              temb_dim=nf * 4,
          )
  
      elif resblock_type == "biggan":
          ResnetBlock = functools.partial(
              ResnetBlockBigGAN,
              act=act,
              dropout=dropout,
              fir=fir,
              fir_kernel=fir_kernel,
              init_scale=init_scale,
              skip_rescale=skip_rescale,
              temb_dim=nf * 4,
          )
  
      else:
          raise ValueError(
              f"resblock type {resblock_type} unrecognized."
          )
  
      # Downsampling block
  
      channels = num_channels
      if progressive_input != "none":
          input_pyramid_ch = channels
  
      modules.append(conv3x3(channels, nf))
      hs_c = [nf]
  
      in_ch = nf
      for i_level in range(num_resolutions):
          # Residual blocks for this resolution
          for i_block in range(num_res_blocks):
              out_ch = nf * ch_mult[i_level]
              modules.append(ResnetBlock(in_ch=in_ch, out_ch=out_ch))
              in_ch = out_ch
  
              if all_resolutions[i_level] in attn_resolutions:
                  modules.append(AttnBlock(channels=in_ch))
              hs_c.append(in_ch)
  
          if i_level != num_resolutions - 1:
              if resblock_type == "ddpm":
                  modules.append(Downsample(in_ch=in_ch))
              else:
                  modules.append(ResnetBlock(down=True, in_ch=in_ch))
  
              if progressive_input == "input_skip":
                  modules.append(
                      combiner(dim1=input_pyramid_ch, dim2=in_ch)
                  )
                  if combine_method == "cat":
                      in_ch *= 2
  
              elif progressive_input == "residual":
                  modules.append(
                      pyramid_downsample(
                          in_ch=input_pyramid_ch, out_ch=in_ch
                      )
                  )
                  input_pyramid_ch = in_ch
  
              hs_c.append(in_ch)
  
      in_ch = hs_c[-1]
      modules.append(ResnetBlock(in_ch=in_ch))
      modules.append(AttnBlock(channels=in_ch))
      modules.append(ResnetBlock(in_ch=in_ch))
  
      pyramid_ch = 0
      # Upsampling block
      for i_level in reversed(range(num_resolutions)):
          for i_block in range(num_res_blocks + 1):
              # +1 blocks in upsampling because of skip connection from
              # combiner (after downsampling)
              out_ch = nf * ch_mult[i_level]
              modules.append(
                  ResnetBlock(in_ch=in_ch + hs_c.pop(), out_ch=out_ch)
              )
              in_ch = out_ch
  
          if all_resolutions[i_level] in attn_resolutions:
              modules.append(AttnBlock(channels=in_ch))
  
          if progressive != "none":
              if i_level == num_resolutions - 1:
                  if progressive == "output_skip":
                      modules.append(
                          nn.GroupNorm(
                              num_groups=min(in_ch // 4, 32),
                              num_channels=in_ch,
                              eps=1e-6,
                          )
                      )
                      modules.append(
                          conv3x3(
                              in_ch, channels, init_scale=init_scale
                          )
                      )
                      pyramid_ch = channels
                  elif progressive == "residual":
                      modules.append(
                          nn.GroupNorm(
                              num_groups=min(in_ch // 4, 32),
                              num_channels=in_ch,
                              eps=1e-6,
                          )
                      )
                      modules.append(conv3x3(in_ch, in_ch, bias=True))
                      pyramid_ch = in_ch
                  else:
                      raise ValueError(
                          f"{progressive} is not a valid name."
                      )
              else:
                  if progressive == "output_skip":
                      modules.append(
                          nn.GroupNorm(
                              num_groups=min(in_ch // 4, 32),
                              num_channels=in_ch,
                              eps=1e-6,
                          )
                      )
                      modules.append(
                          conv3x3(
                              in_ch,
                              channels,
                              bias=True,
                              init_scale=init_scale,
                          )
                      )
                      pyramid_ch = channels
                  elif progressive == "residual":
                      modules.append(
                          pyramid_upsample(
                              in_ch=pyramid_ch, out_ch=in_ch
                          )
                      )
                      pyramid_ch = in_ch
                  else:
                      raise ValueError(
                          f"{progressive} is not a valid name"
                      )
  
          if i_level != 0:
              if resblock_type == "ddpm":
                  modules.append(Upsample(in_ch=in_ch))
              else:
                  modules.append(ResnetBlock(in_ch=in_ch, up=True))
  
      assert not hs_c
  
      if progressive != "output_skip":
          modules.append(
              nn.GroupNorm(
                  num_groups=min(in_ch // 4, 32),
                  num_channels=in_ch,
                  eps=1e-6,
              )
          )
          modules.append(
              conv3x3(in_ch, channels, init_scale=init_scale)
          )
  
      self.all_modules = nn.ModuleList(modules)
  
file_path: espnet/espnet2/enh/layers/ncsnpp.py
imports: import functools
  import numpy
  import torch
  import torch.nn
  from espnet2.enh.layers.ncsnpp_utils import layers, layerspp, normalization
label_desc: Use image node_id 1 to create a new NCSNpp object from inherited base classes: nn with example: obj = NCSNpp(scale_by_sigma, nonlinearity, nf, ch_mult, num_res_blocks, attn_resolutions, resamp_with_conv, conditional, fir, fir_kernel, skip_rescale, resblock_type, progressive, progressive_input, progressive_combine, init_scale, fourier_scale, image_size, embedding_type, dropout, centered)