docstr: Discriminator module for VISinger2, including MSD, MPD, and MFD.
  
  Args:
      scales (int): Number of scales to be used in the multi-scale discriminator.
      scale_downsample_pooling (str): Type of pooling used for downsampling.
      scale_downsample_pooling_params (Dict[str, Any]): Parameters for the
                                                        downsampling pooling
                                                        layer.
      scale_discriminator_params (Dict[str, Any]): Parameters for the scale
                                                   discriminator.
      follow_official_norm (bool): Whether to follow the official normalization.
      periods (List[int]): List of periods to be used in the multi-period
                           discriminator.
      period_discriminator_params (Dict[str, Any]): Parameters for the period
                                                    discriminator.
      multi_freq_disc_params (Dict[str, Any]): Parameters for the
                                               multi-frequency discriminator.
      use_spectral_norm (bool): Whether to use spectral normalization or not.
code: def __init__(
      self,
      # Multi-scale discriminator related
      scales: int = 1,
      scale_downsample_pooling: str = "AvgPool1d",
      scale_downsample_pooling_params: Dict[str, Any] = {
          "kernel_size": 4,
          "stride": 2,
          "padding": 2,
      },
      scale_discriminator_params: Dict[str, Any] = {
          "in_channels": 1,
          "out_channels": 1,
          "kernel_sizes": [15, 41, 5, 3],
          "channels": 128,
          "max_downsample_channels": 1024,
          "max_groups": 16,
          "bias": True,
          "downsample_scales": [2, 2, 4, 4, 1],
          "nonlinear_activation": "LeakyReLU",
          "nonlinear_activation_params": {"negative_slope": 0.1},
      },
      follow_official_norm: bool = True,
      # Multi-period discriminator related
      periods: List[int] = [2, 3, 5, 7, 11],
      period_discriminator_params: Dict[str, Any] = {
          "in_channels": 1,
          "out_channels": 1,
          "kernel_sizes": [5, 3],
          "channels": 32,
          "downsample_scales": [3, 3, 3, 3, 1],
          "max_downsample_channels": 1024,
          "bias": True,
          "nonlinear_activation": "LeakyReLU",
          "nonlinear_activation_params": {"negative_slope": 0.1},
          "use_weight_norm": True,
          "use_spectral_norm": False,
      },
      # Multi-frequency discriminator related
      multi_freq_disc_params: Dict[str, Any] = {
          "sample_rate": 22050,
          "hop_length_factors": [4, 8, 16],
          "hidden_channels": [256, 512, 512],
          "domain": "double",
          "mel_scale": True,
          "divisors": [32, 16, 8, 4, 2, 1, 1],
          "strides": [1, 2, 1, 2, 1, 2, 1],
      },
  ):
      """
      Discriminator module for VISinger2, including MSD, MPD, and MFD.
  
      Args:
          scales (int): Number of scales to be used in the multi-scale discriminator.
          scale_downsample_pooling (str): Type of pooling used for downsampling.
          scale_downsample_pooling_params (Dict[str, Any]): Parameters for the
                                                            downsampling pooling
                                                            layer.
          scale_discriminator_params (Dict[str, Any]): Parameters for the scale
                                                       discriminator.
          follow_official_norm (bool): Whether to follow the official normalization.
          periods (List[int]): List of periods to be used in the multi-period
                               discriminator.
          period_discriminator_params (Dict[str, Any]): Parameters for the period
                                                        discriminator.
          multi_freq_disc_params (Dict[str, Any]): Parameters for the
                                                   multi-frequency discriminator.
          use_spectral_norm (bool): Whether to use spectral normalization or not.
      """
      super().__init__()
  
      # Multi-scale discriminator related
      self.msd = HiFiGANMultiScaleDiscriminator(
          scales=scales,
          downsample_pooling=scale_downsample_pooling,
          downsample_pooling_params=scale_downsample_pooling_params,
          discriminator_params=scale_discriminator_params,
          follow_official_norm=follow_official_norm,
      )
  
      # Multi-period discriminator related
      self.mpd = HiFiGANMultiPeriodDiscriminator(
          periods=periods,
          discriminator_params=period_discriminator_params,
      )
  
      # Multi-frequency discriminator related
      if "hop_lengths" not in multi_freq_disc_params:
          # Transfer hop lengths factors to hop lengths
          multi_freq_disc_params["hop_lengths"] = []
  
          for i in range(
              len(multi_freq_disc_params["hop_length_factors"])
          ):
              multi_freq_disc_params["hop_lengths"].append(
                  int(
                      multi_freq_disc_params["sample_rate"]
                      * multi_freq_disc_params["hop_length_factors"][i]
                      / 1000
                  )
              )
  
          del multi_freq_disc_params["hop_length_factors"]
  
      self.mfd = MultiFrequencyDiscriminator(
          **multi_freq_disc_params,
      )
  
imports: import logging
  import math
  from typing import Any, Dict, List, Optional
  import numpy
  import torch
  import torch.nn.functional
  from espnet2.gan_svs.visinger2.ddsp import remove_above_nyquist, scale_function, upsample
  from espnet2.gan_tts.hifigan import HiFiGANMultiPeriodDiscriminator, HiFiGANMultiScaleDiscriminator, HiFiGANMultiScaleMultiPeriodDiscriminator, HiFiGANPeriodDiscriminator, HiFiGANScaleDiscriminator
  from espnet2.gan_tts.hifigan.residual_block import ResidualBlock
label_desc: Use image node_id 1 to create a new VISinger2Discriminator object from inherited base classes: torch.nn with example: obj = VISinger2Discriminator(scales, scale_downsample_pooling, scale_downsample_pooling_params, scale_discriminator_params, follow_official_norm, periods, period_discriminator_params, multi_freq_disc_params)