class_docstr: GAN-based model to add details to blurry spectrograms from TTS models like Tacotron or FastPitch. Based on StyleGAN 2 [1]
  [1] Karras et. al. - Analyzing and Improving the Image Quality of StyleGAN (https://arxiv.org/abs/1912.04958)
class_docstr_tok: ["GAN-based","model","to","add","details","to","blurry","spectrograms","from","TTS","models","like","Tacotron","or","FastPitch",".","Based","on","StyleGAN","2","[","1","]","[","1","]","Karras","et",".","al",".","-","Analyzing","and","Improving","the","Image","Quality","of","StyleGAN","(","https",":","\/\/arxiv.org\/abs\/1912.04958",")"]
docstr: Generator forward pass. Noise inputs will be generated if None.
  
  input_spectrograms: batch of spectrograms, typically synthetic
  lenghts: length for every spectrogam in the batch
  zs: latent noise inputs on the unit sphere (either this or ws or neither)
  ws: latent noise inputs in the style space (either this or zs or neither)
  noise: per-pixel indepentent gaussian noise
  mixing: style mixing, usually True during training
  normalize: normalize spectrogram range to ~[0, 1], True for normal use
  
  returns: batch of enhanced spectrograms
  
  For explanation of style mixing refer to [1]
  For definititions of z, w [2]
  [1] Karras et. al. - A Style-Based Generator Architecture for Generative Adversarial Networks, 2018 (https://arxiv.org/abs/1812.04948)
  [2] Karras et. al. - Analyzing and Improving the Image Quality of StyleGAN, 2019 (https://arxiv.org/abs/1912.04958)
docstr_tok: ["Generator","forward","pass",".","Noise","inputs","will","be","generated","if","None",".","input_spectrograms",":","batch","of","spectrograms",",","typically","synthetic","lenghts",":","length","for","every","spectrogam","in","the","batch","zs",":","latent","noise","inputs","on","the","unit","sphere","(","either","this","or","ws","or","neither",")","ws",":","latent","noise","inputs","in","the","style","space","(","either","this","or","zs","or","neither",")","noise",":","per-pixel","indepentent","gaussian","noise","mixing",":","style","mixing",",","usually","True","during","training","normalize",":","normalize","spectrogram","range","to","~","[","0",",","1","]",",","True","for","normal","use","returns",":","batch","of","enhanced","spectrograms","For","explanation","of","style","mixing","refer","to","[","1","]","For","definititions","of","z",",","w","[","2","]","[","1","]","Karras","et",".","al",".","-","A","Style-Based","Generator","Architecture","for","Generative","Adversarial","Networks",",","2018","(","https",":","\/\/arxiv.org\/abs\/1812.04948",")","[","2","]","Karras","et",".","al",".","-","Analyzing","and","Improving","the","Image","Quality","of","StyleGAN",",","2019","(","https",":","\/\/arxiv.org\/abs\/1912.04958",")"]
code: def forward_with_custom_noise(
      self,
      input_spectrograms: torch.Tensor,
      lengths: torch.Tensor,
      zs: Optional[List[torch.Tensor]] = None,
      ws: Optional[List[torch.Tensor]] = None,
      noise: Optional[torch.Tensor] = None,
      mixing: bool = False,
      normalize: bool = True,
  ):
      """
      Generator forward pass. Noise inputs will be generated if None.
  
      input_spectrograms: batch of spectrograms, typically synthetic
      lenghts: length for every spectrogam in the batch
      zs: latent noise inputs on the unit sphere (either this or ws or neither)
      ws: latent noise inputs in the style space (either this or zs or neither)
      noise: per-pixel indepentent gaussian noise
      mixing: style mixing, usually True during training
      normalize: normalize spectrogram range to ~[0, 1], True for normal use
  
      returns: batch of enhanced spectrograms
  
      For explanation of style mixing refer to [1]
      For definititions of z, w [2]
      [1] Karras et. al. - A Style-Based Generator Architecture for Generative Adversarial Networks, 2018 (https://arxiv.org/abs/1812.04948)
      [2] Karras et. al. - Analyzing and Improving the Image Quality of StyleGAN, 2019 (https://arxiv.org/abs/1912.04958)
      """
      batch_size, *_, max_length = input_spectrograms.shape
  
      # generate noise
      if zs is not None and ws is not None:
          raise ValueError(
              "Please specify either zs or ws or neither, but not both. It is not clear which one to use."
          )
  
      if zs is None:
          zs = self.generate_zs(batch_size, mixing)
      if ws is None:
          ws = [self.generator.style_mapping(z) for z in zs]
      if noise is None:
          noise = self.generate_noise(batch_size)
  
      input_spectrograms = rearrange(
          input_spectrograms, "b c l -> b 1 c l"
      )
      # normalize if needed, mask and pad appropriately
      if normalize:
          input_spectrograms = self.normalize_spectrograms(
              input_spectrograms, lengths
          )
      input_spectrograms = self.pad_spectrograms(input_spectrograms)
  
      # the main call
      enhanced_spectrograms = self.generator(
          input_spectrograms, lengths, ws, noise
      )
  
      # denormalize if needed, mask and remove padding
      if normalize:
          enhanced_spectrograms = self.unnormalize_spectrograms(
              enhanced_spectrograms, lengths
          )
      enhanced_spectrograms = enhanced_spectrograms[
          :, :, :, :max_length
      ]
      enhanced_spectrograms = rearrange(
          enhanced_spectrograms, "b 1 c l -> b c l"
      )
  
      return enhanced_spectrograms
  
imports: from random import random, randrange
  from typing import List, Optional
  import torch
  import torch.nn.functional
  from einops import rearrange
  from hydra.utils import instantiate
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from pytorch_lightning.loggers import TensorBoardLogger, WandbLogger
  from torch.utils.tensorboard.writer import SummaryWriter
  from nemo.collections.tts.losses.spectrogram_enhancer_losses import ConsistencyLoss, GeneratorLoss, GradientPenaltyLoss, HingeLoss
  from nemo.collections.tts.parts.utils.helpers import mask_sequence_tensor, to_device_recursive
  from nemo.core import Exportable, ModelPT, PretrainedModelInfo, typecheck
  from nemo.core.neural_types import LengthsType, MelSpectrogramType, NeuralType
  from nemo.core.neural_types.elements import BoolType
  from nemo.utils import logging
label_desc: Use image node_id 9 for calling the SpectrogramEnhancerModel obj's underlying member method code with example usage: obj.forward_with_custom_noise(input_spectrograms, lengths, zs, ws, noise, mixing, normalize) and returns: enhanced_spectrograms