class_docstr: MelGAN generator module.
docstr: Initialize MelGANGenerator module.
  
  Args:
      in_channels (int): Number of input channels.
      out_channels (int): Number of output channels.
      kernel_size (int): Kernel size of initial and final conv layer.
      channels (int): Initial number of channels for conv layer.
      bias (bool): Whether to add bias parameter in convolution layers.
      upsample_scales (List[int]): List of upsampling scales.
      stack_kernel_size (int): Kernel size of dilated conv layers in residual
          stack.
      stacks (int): Number of stacks in a single residual stack.
      nonlinear_activation (str): Activation function module name.
      nonlinear_activation_params (Dict[str, Any]): Hyperparameters for activation
          function.
      pad (str): Padding function module name before dilated convolution layer.
      pad_params (Dict[str, Any]): Hyperparameters for padding function.
      use_final_nonlinear_activation (torch.nn.Module): Activation function for
          the final layer.
      use_weight_norm (bool): Whether to use weight norm.
          If set to true, it will be applied to all of the conv layers.
docstr_tok: ["Initialize","MelGANGenerator","module",".","Args",":","in_channels","(","int",")",":","Number","of","input","channels",".","out_channels","(","int",")",":","Number","of","output","channels",".","kernel_size","(","int",")",":","Kernel","size","of","initial","and","final","conv","layer",".","channels","(","int",")",":","Initial","number","of","channels","for","conv","layer",".","bias","(","bool",")",":","Whether","to","add","bias","parameter","in","convolution","layers",".","upsample_scales","(","List","[","int","]",")",":","List","of","upsampling","scales",".","stack_kernel_size","(","int",")",":","Kernel","size","of","dilated","conv","layers","in","residual","stack",".","stacks","(","int",")",":","Number","of","stacks","in","a","single","residual","stack",".","nonlinear_activation","(","str",")",":","Activation","function","module","name",".","nonlinear_activation_params","(","Dict","[","str",",","Any","]",")",":","Hyperparameters","for","activation","function",".","pad","(","str",")",":","Padding","function","module","name","before","dilated","convolution","layer",".","pad_params","(","Dict","[","str",",","Any","]",")",":","Hyperparameters","for","padding","function",".","use_final_nonlinear_activation","(","torch.nn.Module",")",":","Activation","function","for","the","final","layer",".","use_weight_norm","(","bool",")",":","Whether","to","use","weight","norm",".","If","set","to","true",",","it","will","be","applied","to","all","of","the","conv","layers","."]
code: def __init__(
      self,
      in_channels: int = 80,
      out_channels: int = 1,
      kernel_size: int = 7,
      channels: int = 512,
      bias: bool = True,
      upsample_scales: List[int] = [8, 8, 2, 2],
      stack_kernel_size: int = 3,
      stacks: int = 3,
      nonlinear_activation: str = "LeakyReLU",
      nonlinear_activation_params: Dict[str, Any] = {
          "negative_slope": 0.2
      },
      pad: str = "ReflectionPad1d",
      pad_params: Dict[str, Any] = {},
      use_final_nonlinear_activation: bool = True,
      use_weight_norm: bool = True,
  ):
      """Initialize MelGANGenerator module.
  
      Args:
          in_channels (int): Number of input channels.
          out_channels (int): Number of output channels.
          kernel_size (int): Kernel size of initial and final conv layer.
          channels (int): Initial number of channels for conv layer.
          bias (bool): Whether to add bias parameter in convolution layers.
          upsample_scales (List[int]): List of upsampling scales.
          stack_kernel_size (int): Kernel size of dilated conv layers in residual
              stack.
          stacks (int): Number of stacks in a single residual stack.
          nonlinear_activation (str): Activation function module name.
          nonlinear_activation_params (Dict[str, Any]): Hyperparameters for activation
              function.
          pad (str): Padding function module name before dilated convolution layer.
          pad_params (Dict[str, Any]): Hyperparameters for padding function.
          use_final_nonlinear_activation (torch.nn.Module): Activation function for
              the final layer.
          use_weight_norm (bool): Whether to use weight norm.
              If set to true, it will be applied to all of the conv layers.
  
      """
      super().__init__()
  
      # check hyper parameters is valid
      assert channels >= np.prod(upsample_scales)
      assert channels % (2 ** len(upsample_scales)) == 0
      assert (
          kernel_size - 1
      ) % 2 == 0, "Not support even number kernel size."
  
      # add initial layer
      layers = []
      layers += [
          getattr(torch.nn, pad)((kernel_size - 1) // 2, **pad_params),
          torch.nn.Conv1d(
              in_channels, channels, kernel_size, bias=bias
          ),
      ]
  
      self.upsample_factor = int(
          np.prod(upsample_scales) * out_channels
      )
      for i, upsample_scale in enumerate(upsample_scales):
          # add upsampling layer
          layers += [
              getattr(torch.nn, nonlinear_activation)(
                  **nonlinear_activation_params
              )
          ]
          layers += [
              torch.nn.ConvTranspose1d(
                  channels // (2**i),
                  channels // (2 ** (i + 1)),
                  upsample_scale * 2,
                  stride=upsample_scale,
                  padding=upsample_scale // 2 + upsample_scale % 2,
                  output_padding=upsample_scale % 2,
                  bias=bias,
              )
          ]
  
          # add residual stack
          for j in range(stacks):
              layers += [
                  ResidualStack(
                      kernel_size=stack_kernel_size,
                      channels=channels // (2 ** (i + 1)),
                      dilation=stack_kernel_size**j,
                      bias=bias,
                      nonlinear_activation=nonlinear_activation,
                      nonlinear_activation_params=nonlinear_activation_params,
                      pad=pad,
                      pad_params=pad_params,
                  )
              ]
  
      # add final layer
      layers += [
          getattr(torch.nn, nonlinear_activation)(
              **nonlinear_activation_params
          )
      ]
      layers += [
          getattr(torch.nn, pad)((kernel_size - 1) // 2, **pad_params),
          torch.nn.Conv1d(
              channels // (2 ** (i + 1)),
              out_channels,
              kernel_size,
              bias=bias,
          ),
      ]
      if use_final_nonlinear_activation:
          layers += [torch.nn.Tanh()]
  
      # define the model as a single function
      self.melgan = torch.nn.Sequential(*layers)
  
      # apply weight norm
      if use_weight_norm:
          self.apply_weight_norm()
  
      # reset parameters
      self.reset_parameters()
  
imports: import logging
  from typing import Any, Dict, List
  import numpy
  import torch
  from espnet2.gan_tts.melgan.residual_stack import ResidualStack
label_desc: Use image node_id 1 to create a new MelGANGenerator object from inherited base classes: torch.nn with example: obj = MelGANGenerator(in_channels, out_channels, kernel_size, channels, bias, upsample_scales, stack_kernel_size, stacks, nonlinear_activation, nonlinear_activation_params, pad, pad_params, use_final_nonlinear_activation, use_weight_norm)