class_docstr: HiFi-GAN scale discriminator module.
docstr: Initilize HiFiGAN scale discriminator module.
  
  Args:
      in_channels (int): Number of input channels.
      out_channels (int): Number of output channels.
      kernel_sizes (List[int]): List of four kernel sizes. The first will be used
          for the first conv layer, and the second is for downsampling part, and
          the remaining two are for the last two output layers.
      channels (int): Initial number of channels for conv layer.
      max_downsample_channels (int): Maximum number of channels for downsampling
          layers.
      bias (bool): Whether to add bias parameter in convolution layers.
      downsample_scales (List[int]): List of downsampling scales.
      nonlinear_activation (str): Activation function module name.
      nonlinear_activation_params (Dict[str, Any]): Hyperparameters for activation
          function.
      use_weight_norm (bool): Whether to use weight norm. If set to true, it will
          be applied to all of the conv layers.
      use_spectral_norm (bool): Whether to use spectral norm. If set to true, it
          will be applied to all of the conv layers.
docstr_tok: ["Initilize","HiFiGAN","scale","discriminator","module",".","Args",":","in_channels","(","int",")",":","Number","of","input","channels",".","out_channels","(","int",")",":","Number","of","output","channels",".","kernel_sizes","(","List","[","int","]",")",":","List","of","four","kernel","sizes",".","The","first","will","be","used","for","the","first","conv","layer",",","and","the","second","is","for","downsampling","part",",","and","the","remaining","two","are","for","the","last","two","output","layers",".","channels","(","int",")",":","Initial","number","of","channels","for","conv","layer",".","max_downsample_channels","(","int",")",":","Maximum","number","of","channels","for","downsampling","layers",".","bias","(","bool",")",":","Whether","to","add","bias","parameter","in","convolution","layers",".","downsample_scales","(","List","[","int","]",")",":","List","of","downsampling","scales",".","nonlinear_activation","(","str",")",":","Activation","function","module","name",".","nonlinear_activation_params","(","Dict","[","str",",","Any","]",")",":","Hyperparameters","for","activation","function",".","use_weight_norm","(","bool",")",":","Whether","to","use","weight","norm",".","If","set","to","true",",","it","will","be","applied","to","all","of","the","conv","layers",".","use_spectral_norm","(","bool",")",":","Whether","to","use","spectral","norm",".","If","set","to","true",",","it","will","be","applied","to","all","of","the","conv","layers","."]
code: def __init__(
      self,
      in_channels: int = 1,
      out_channels: int = 1,
      kernel_sizes: List[int] = [15, 41, 5, 3],
      channels: int = 128,
      max_downsample_channels: int = 1024,
      max_groups: int = 16,
      bias: int = True,
      downsample_scales: List[int] = [2, 2, 4, 4, 1],
      nonlinear_activation: str = "LeakyReLU",
      nonlinear_activation_params: Dict[str, Any] = {
          "negative_slope": 0.1
      },
      use_weight_norm: bool = True,
      use_spectral_norm: bool = False,
  ):
      """Initilize HiFiGAN scale discriminator module.
  
      Args:
          in_channels (int): Number of input channels.
          out_channels (int): Number of output channels.
          kernel_sizes (List[int]): List of four kernel sizes. The first will be used
              for the first conv layer, and the second is for downsampling part, and
              the remaining two are for the last two output layers.
          channels (int): Initial number of channels for conv layer.
          max_downsample_channels (int): Maximum number of channels for downsampling
              layers.
          bias (bool): Whether to add bias parameter in convolution layers.
          downsample_scales (List[int]): List of downsampling scales.
          nonlinear_activation (str): Activation function module name.
          nonlinear_activation_params (Dict[str, Any]): Hyperparameters for activation
              function.
          use_weight_norm (bool): Whether to use weight norm. If set to true, it will
              be applied to all of the conv layers.
          use_spectral_norm (bool): Whether to use spectral norm. If set to true, it
              will be applied to all of the conv layers.
  
      """
      super().__init__()
      self.layers = torch.nn.ModuleList()
  
      # check kernel size is valid
      assert len(kernel_sizes) == 4
      for ks in kernel_sizes:
          assert ks % 2 == 1
  
      # add first layer
      self.layers += [
          torch.nn.Sequential(
              torch.nn.Conv1d(
                  in_channels,
                  channels,
                  # NOTE(kan-bayashi): Use always the same kernel size
                  kernel_sizes[0],
                  bias=bias,
                  padding=(kernel_sizes[0] - 1) // 2,
              ),
              getattr(torch.nn, nonlinear_activation)(
                  **nonlinear_activation_params
              ),
          )
      ]
  
      # add downsample layers
      in_chs = channels
      out_chs = channels
      # NOTE(kan-bayashi): Remove hard coding?
      groups = 4
      for downsample_scale in downsample_scales:
          self.layers += [
              torch.nn.Sequential(
                  torch.nn.Conv1d(
                      in_chs,
                      out_chs,
                      kernel_size=kernel_sizes[1],
                      stride=downsample_scale,
                      padding=(kernel_sizes[1] - 1) // 2,
                      groups=groups,
                      bias=bias,
                  ),
                  getattr(torch.nn, nonlinear_activation)(
                      **nonlinear_activation_params
                  ),
              )
          ]
          in_chs = out_chs
          # NOTE(kan-bayashi): Remove hard coding?
          out_chs = min(in_chs * 2, max_downsample_channels)
          # NOTE(kan-bayashi): Remove hard coding?
          groups = min(groups * 4, max_groups)
  
      # add final layers
      out_chs = min(in_chs * 2, max_downsample_channels)
      self.layers += [
          torch.nn.Sequential(
              torch.nn.Conv1d(
                  in_chs,
                  out_chs,
                  kernel_size=kernel_sizes[2],
                  stride=1,
                  padding=(kernel_sizes[2] - 1) // 2,
                  bias=bias,
              ),
              getattr(torch.nn, nonlinear_activation)(
                  **nonlinear_activation_params
              ),
          )
      ]
      self.layers += [
          torch.nn.Conv1d(
              out_chs,
              out_channels,
              kernel_size=kernel_sizes[3],
              stride=1,
              padding=(kernel_sizes[3] - 1) // 2,
              bias=bias,
          ),
      ]
  
      if use_weight_norm and use_spectral_norm:
          raise ValueError(
              "Either use use_weight_norm or use_spectral_norm."
          )
  
      # apply weight norm
      self.use_weight_norm = use_weight_norm
      if use_weight_norm:
          self.apply_weight_norm()
  
      # apply spectral norm
      self.use_spectral_norm = use_spectral_norm
      if use_spectral_norm:
          self.apply_spectral_norm()
  
      # backward compatibility
      self._register_load_state_dict_pre_hook(
          self._load_state_dict_pre_hook
      )
  
imports: import copy
  import logging
  from typing import Any, Dict, List, Optional
  import numpy
  import torch
  import torch.nn.functional
  from espnet2.gan_tts.hifigan.residual_block import ResidualBlock
label_desc: Use image node_id 1 to create a new HiFiGANScaleDiscriminator object from inherited base classes: torch.nn with example: obj = HiFiGANScaleDiscriminator(in_channels, out_channels, kernel_sizes, channels, max_downsample_channels, max_groups, bias, downsample_scales, nonlinear_activation, nonlinear_activation_params, use_weight_norm, use_spectral_norm)