class_docstr: UHiFiGAN generator module.
class_docstr_tok: ["UHiFiGAN","generator","module","."]
docstr: Initialize Unet-based HiFiGANGenerator module.
  
  Args:
      in_channels (int): Number of input channels.
      out_channels (int): Number of output channels.
      channels (int): Number of hidden representation channels.
      global_channels (int): Number of global conditioning channels.
      kernel_size (int): Kernel size of initial and final conv layer.
      upsample_scales (list): List of upsampling scales.
      upsample_kernel_sizes (list): List of kernel sizes for upsampling layers.
      resblock_kernel_sizes (list): List of kernel sizes for residual blocks.
      resblock_dilations (list): List of dilation list for residual blocks.
      use_additional_convs (bool): Whether to use additional conv layers
          in residual blocks.
      bias (bool): Whether to add bias parameter in convolution layers.
      nonlinear_activation (str): Activation function module name.
      nonlinear_activation_params (dict): Hyperparameters for activation function.
      use_causal_conv (bool): Whether to use causal structure.
      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","Unet-based","HiFiGANGenerator","module",".","Args",":","in_channels","(","int",")",":","Number","of","input","channels",".","out_channels","(","int",")",":","Number","of","output","channels",".","channels","(","int",")",":","Number","of","hidden","representation","channels",".","global_channels","(","int",")",":","Number","of","global","conditioning","channels",".","kernel_size","(","int",")",":","Kernel","size","of","initial","and","final","conv","layer",".","upsample_scales","(","list",")",":","List","of","upsampling","scales",".","upsample_kernel_sizes","(","list",")",":","List","of","kernel","sizes","for","upsampling","layers",".","resblock_kernel_sizes","(","list",")",":","List","of","kernel","sizes","for","residual","blocks",".","resblock_dilations","(","list",")",":","List","of","dilation","list","for","residual","blocks",".","use_additional_convs","(","bool",")",":","Whether","to","use","additional","conv","layers","in","residual","blocks",".","bias","(","bool",")",":","Whether","to","add","bias","parameter","in","convolution","layers",".","nonlinear_activation","(","str",")",":","Activation","function","module","name",".","nonlinear_activation_params","(","dict",")",":","Hyperparameters","for","activation","function",".","use_causal_conv","(","bool",")",":","Whether","to","use","causal","structure",".","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=80,
      out_channels=1,
      channels=512,
      global_channels: int = -1,
      kernel_size=7,
      downsample_scales=(2, 2, 8, 8),
      downsample_kernel_sizes=(4, 4, 16, 16),
      upsample_scales=(8, 8, 2, 2),
      upsample_kernel_sizes=(16, 16, 4, 4),
      resblock_kernel_sizes=(3, 7, 11),
      resblock_dilations=[(1, 3, 5), (1, 3, 5), (1, 3, 5)],
      projection_filters: List[int] = [0, 1, 1, 1],
      projection_kernels: List[int] = [0, 5, 7, 11],
      dropout=0.3,
      use_additional_convs=True,
      bias=True,
      nonlinear_activation="LeakyReLU",
      nonlinear_activation_params={"negative_slope": 0.1},
      use_causal_conv=False,
      use_weight_norm=True,
      use_avocodo=False,
  ):
      """Initialize Unet-based HiFiGANGenerator module.
  
      Args:
          in_channels (int): Number of input channels.
          out_channels (int): Number of output channels.
          channels (int): Number of hidden representation channels.
          global_channels (int): Number of global conditioning channels.
          kernel_size (int): Kernel size of initial and final conv layer.
          upsample_scales (list): List of upsampling scales.
          upsample_kernel_sizes (list): List of kernel sizes for upsampling layers.
          resblock_kernel_sizes (list): List of kernel sizes for residual blocks.
          resblock_dilations (list): List of dilation list for residual blocks.
          use_additional_convs (bool): Whether to use additional conv layers
              in residual blocks.
          bias (bool): Whether to add bias parameter in convolution layers.
          nonlinear_activation (str): Activation function module name.
          nonlinear_activation_params (dict): Hyperparameters for activation function.
          use_causal_conv (bool): Whether to use causal structure.
          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 hyperparameters are valid
      assert kernel_size % 2 == 1, "Kernel size must be odd number."
      assert len(upsample_scales) == len(upsample_kernel_sizes)
      assert len(resblock_dilations) == len(resblock_kernel_sizes)
  
      # define modules
      self.num_upsamples = len(upsample_kernel_sizes)
      self.num_blocks = len(resblock_kernel_sizes)
      self.use_causal_conv = use_causal_conv
  
      self.input_conv = None
  
      self.downsamples = torch.nn.ModuleList()
      self.downsamples_mrf = torch.nn.ModuleList()
  
      self.hidden_conv = None
  
      self.upsamples = torch.nn.ModuleList()
      self.upsamples_mrf = torch.nn.ModuleList()
  
      self.output_conv = None
      self.use_avocodo = use_avocodo
  
      if (
          CausalConv1d is None
          or CausalConvTranspose1d is None
          or ResidualBlock is None
      ):
          raise ImportError(
              "`parallel_wavegan` is not installed. "
              "Please install via `pip install -U parallel_wavegan`."
          )
  
      if not use_causal_conv:
          self.input_conv = torch.nn.Sequential(
              torch.nn.Conv1d(
                  out_channels,
                  channels,
                  kernel_size=kernel_size,
                  bias=bias,
                  padding=(kernel_size - 1) // 2,
              ),
              getattr(torch.nn, nonlinear_activation)(
                  **nonlinear_activation_params
              ),
              torch.nn.Dropout(dropout),
          )
      else:
          self.input_conv = torch.nn.Sequential(
              CausalConv1d(
                  out_channels,
                  channels,
                  kernel_size=kernel_size,
                  bias=bias,
                  padding=(kernel_size - 1) // 2,
              ),
              getattr(torch.nn, nonlinear_activation)(
                  **nonlinear_activation_params
              ),
              torch.nn.Dropout(dropout),
          )
      hidden_channels = channels
      for i in range(len(downsample_scales)):
          for j in range(len(resblock_kernel_sizes)):
              self.downsamples_mrf += [
                  ResidualBlock(
                      kernel_size=resblock_kernel_sizes[j],
                      channels=channels,
                      # channels=channels * 2**i,
                      dilations=resblock_dilations[j],
                      bias=bias,
                      use_additional_convs=use_additional_convs,
                      nonlinear_activation=nonlinear_activation,
                      nonlinear_activation_params=nonlinear_activation_params,
                      use_causal_conv=use_causal_conv,
                  )
              ]
  
          if not use_causal_conv:
              self.downsamples += [
                  torch.nn.Sequential(
                      torch.nn.Conv1d(
                          channels,
                          channels * 2,
                          # channels * (2 ** (i + 1)),
                          kernel_size=downsample_kernel_sizes[i],
                          stride=downsample_scales[i],
                          bias=bias,
                          padding=downsample_scales[i] // 2
                          + downsample_scales[i] % 2,
                      ),
                      getattr(torch.nn, nonlinear_activation)(
                          **nonlinear_activation_params
                      ),
                      torch.nn.Dropout(dropout),
                  )
              ]
          else:
              self.downsamples += [
                  torch.nn.Sequential(
                      CausalConv1d(
                          channels,
                          channels * 2,
                          # channels * (2 ** (i + 1)),
                          kernel_size=downsample_kernel_sizes[i],
                          stride=downsample_scales[i],
                          bias=bias,
                          padding=downsample_scales[i] // 2
                          + downsample_scales[i] % 2,
                      ),
                      getattr(torch.nn, nonlinear_activation)(
                          **nonlinear_activation_params
                      ),
                      torch.nn.Dropout(dropout),
                  )
              ]
  
          channels = channels * 2
  
      if not use_causal_conv:
          self.hidden_conv = torch.nn.Conv1d(
              in_channels,
              channels,
              kernel_size=kernel_size,
              bias=bias,
              padding=(kernel_size - 1) // 2,
          )
      else:
          self.hidden_conv = CausalConv1d(
              in_channels,
              channels,
              kernel_size=kernel_size,
              bias=bias,
              padding=(kernel_size - 1) // 2,
          )
  
      max_channels = channels
      self.output_conv = torch.nn.ModuleList()
      for i in range(len(upsample_kernel_sizes)):
          # assert upsample_kernel_sizes[i] == 2 * upsample_scales[i]
          if not use_causal_conv:
              self.upsamples += [
                  torch.nn.Sequential(
                      getattr(torch.nn, nonlinear_activation)(
                          **nonlinear_activation_params
                      ),
                      torch.nn.ConvTranspose1d(
                          channels * 2,
                          channels // 2,
                          # channels // (2 ** (i + 1)),
                          upsample_kernel_sizes[i],
                          upsample_scales[i],
                          padding=upsample_scales[i] // 2
                          + upsample_scales[i] % 2,
                          output_padding=upsample_scales[i] % 2,
                          bias=bias,
                      ),
                  )
              ]
          else:
              self.upsamples += [
                  torch.nn.Sequential(
                      getattr(torch.nn, nonlinear_activation)(
                          **nonlinear_activation_params
                      ),
                      CausalConvTranspose1d(
                          channels * 2,
                          channels // 2,
                          # channels // (2 ** (i + 1)),
                          upsample_kernel_sizes[i],
                          upsample_scales[i],
                          bias=bias,
                      ),
                  )
              ]
  
          # hidden_channel for MRF module
          for j in range(len(resblock_kernel_sizes)):
              self.upsamples_mrf += [
                  ResidualBlock(
                      kernel_size=resblock_kernel_sizes[j],
                      channels=channels // 2,
                      # channels=channels // (2 ** (i + 1)),
                      dilations=resblock_dilations[j],
                      bias=bias,
                      use_additional_convs=use_additional_convs,
                      nonlinear_activation=nonlinear_activation,
                      nonlinear_activation_params=nonlinear_activation_params,
                      use_causal_conv=use_causal_conv,
                  )
              ]
  
          channels = channels // 2
  
          if use_avocodo:
              if projection_filters[i] != 0:
                  self.output_conv.append(
                      torch.nn.Conv1d(
                          max_channels // (2 ** (i + 1)),
                          # channels // (2 ** (i + 1)),
                          projection_filters[i],
                          projection_kernels[i],
                          1,
                          padding=projection_kernels[i] // 2,
                      )
                  )
              else:
                  self.output_conv.append(torch.nn.Identity())
      if not use_avocodo:
          if not use_causal_conv:
              self.output_conv = torch.nn.Sequential(
                  # NOTE(kan-bayashi): follow official implementation but why
                  #   using different slope parameter here? (0.1 vs. 0.01)
                  torch.nn.LeakyReLU(),
                  torch.nn.Conv1d(
                      channels,
                      out_channels,
                      kernel_size,
                      bias=bias,
                      padding=(kernel_size - 1) // 2,
                  ),
                  torch.nn.Tanh(),
              )
          else:
              self.output_conv = torch.nn.Sequential(
                  # NOTE(kan-bayashi): follow official implementation but why
                  #   using different slope parameter here? (0.1 vs. 0.01)
                  torch.nn.LeakyReLU(),
                  CausalConv1d(
                      channels,
                      out_channels,
                      kernel_size,
                      bias=bias,
                  ),
                  torch.nn.Tanh(),
              )
  
      if global_channels > 0:
          self.global_conv = torch.nn.Conv1d(
              global_channels, in_channels, 1
          )
  
      # apply weight norm
      if use_weight_norm:
          self.apply_weight_norm()
  
      # reset parameters
      self.reset_parameters()
  
file_path: espnet/espnet2/gan_svs/uhifigan/uhifigan.py
imports: import logging
  from typing import List, Optional
  import numpy
  import torch
  import torch.nn.functional
label_desc: Use image node_id 1 to create a new UHiFiGANGenerator object from inherited base classes: torch.nn with example: obj = UHiFiGANGenerator(in_channels, out_channels, channels, global_channels, kernel_size, downsample_scales, downsample_kernel_sizes, upsample_scales, upsample_kernel_sizes, resblock_kernel_sizes, resblock_dilations, projection_filters, projection_kernels, dropout, use_additional_convs, bias, nonlinear_activation, nonlinear_activation_params, use_causal_conv, use_weight_norm, use_avocodo)