docstr: Wrap a generator and a discriminator network. It provides a compatible interface for the trainer.
  It also helps mixing and matching different generator and disciminator networks easily.
  
  To implement a new GAN models, you just need to define the generator and the discriminator networks, the rest
  is handled by the `GAN` class.
  
  Args:
      config (Coqpit): Model configuration.
      ap (AudioProcessor): 🐸TTS AudioProcessor instance. Defaults to None.
  
  Examples:
      Initializing the GAN model with HifiGAN generator and discriminator.
      >>> from TTS.vocoder.configs import HifiganConfig
      >>> config = HifiganConfig()
      >>> model = GAN(config)
docstr_tok: ["Wrap","a","generator","and","a","discriminator","network",".","It","provides","a","compatible","interface","for","the","trainer",".","It","also","helps","mixing","and","matching","different","generator","and","disciminator","networks","easily",".","To","implement","a","new","GAN","models",",","you","just","need","to","define","the","generator","and","the","discriminator","networks",",","the","rest","is","handled","by","the","`","GAN","`","class",".","Args",":","config","(","Coqpit",")",":","Model","configuration",".","ap","(","AudioProcessor",")",":","\ud83d\udc38TTS","AudioProcessor","instance",".","Defaults","to","None",".","Examples",":","Initializing","the","GAN","model","with","HifiGAN","generator","and","discriminator",".",">",">",">","from","TTS.vocoder.configs","import","HifiganConfig",">",">",">","config","=","HifiganConfig","(",")",">",">",">","model","=","GAN","(","config",")"]
code: def __init__(self, config: Coqpit, ap: AudioProcessor = None):
      """Wrap a generator and a discriminator network. It provides a compatible interface for the trainer.
      It also helps mixing and matching different generator and disciminator networks easily.
  
      To implement a new GAN models, you just need to define the generator and the discriminator networks, the rest
      is handled by the `GAN` class.
  
      Args:
          config (Coqpit): Model configuration.
          ap (AudioProcessor): 🐸TTS AudioProcessor instance. Defaults to None.
  
      Examples:
          Initializing the GAN model with HifiGAN generator and discriminator.
          >>> from TTS.vocoder.configs import HifiganConfig
          >>> config = HifiganConfig()
          >>> model = GAN(config)
      """
      super().__init__(config)
      self.config = config
      self.model_g = setup_generator(config)
      self.model_d = setup_discriminator(config)
      self.train_disc = False  # if False, train only the generator.
      self.y_hat_g = None  # the last generator prediction to be passed onto the discriminator
      self.ap = ap
  
imports: from inspect import signature
  from typing import Dict, List, Tuple
  import numpy
  import torch
  from coqpit import Coqpit
  from torch import nn
  from torch.utils.data import DataLoader
  from torch.utils.data.distributed import DistributedSampler
  from trainer.trainer_utils import get_optimizer, get_scheduler
  from TTS.utils.audio import AudioProcessor
  from TTS.utils.io import load_fsspec
  from TTS.vocoder.datasets.gan_dataset import GANDataset
  from TTS.vocoder.layers.losses import DiscriminatorLoss, GeneratorLoss
  from TTS.vocoder.models import setup_discriminator, setup_generator
  from TTS.vocoder.models.base_vocoder import BaseVocoder
  from TTS.vocoder.utils.generic_utils import plot_results
label_desc: Use image node_id 1 to create a new GAN object from inherited base classes: BaseVocoder with example: obj = GAN(config, ap)