docstr: Computes the loss of the generator based on discriminator and generator losses
docstr_tok: ["Computes","the","loss","of","the","generator","based","on","discriminator","and","generator","losses"]
code: def compute_objectives_g3(
      self,
      d_outs,
      predict_wavs,
      clean_wavs,
      batch,
      stage,
      z_mean=None,
      z_logvar=None,
  ):
      """Computes the loss of the generator based on discriminator and generator losses"""
      clean_wavs_orig, lens = batch.clean_sig
      clean_wavs_orig = clean_wavs_orig.to(self.device)
      clean_wavs = clean_wavs.to(self.device)
  
      loss = self.hparams.compute_cost["g3"](
          d_outs,
          predict_wavs,
          clean_wavs,
          lens,
          l1LossCoeff=self.hparams.l1LossCoeff,
          klLossCoeff=self.hparams.klLossCoeff,
          z_mean=z_mean,
          z_logvar=z_logvar,
      )
      self.loss_metric_g3.append(
          batch.id,
          d_outs,
          predict_wavs,
          clean_wavs,
          lens,
          l1LossCoeff=self.hparams.l1LossCoeff,
          klLossCoeff=self.hparams.klLossCoeff,
          z_mean=z_mean,
          z_logvar=z_logvar,
          reduction="batch",
      )
  
      if stage != sb.Stage.TRAIN:
          # Evaluate speech quality/intelligibility
          predict_wavs = predict_wavs.reshape(self.batch_current, -1)
          clean_wavs = clean_wavs.reshape(self.batch_current, -1)
  
          predict_wavs = predict_wavs[:, 0 : self.original_len]
          clean_wavs = clean_wavs[:, 0 : self.original_len]
  
          self.stoi_metric.append(
              batch.id,
              predict_wavs,
              clean_wavs,
              lens,
              reduction="batch",
          )
          self.pesq_metric.append(
              batch.id,
              predict=predict_wavs.cpu(),
              target=clean_wavs.cpu(),
          )
  
          # Write enhanced test wavs to file
          if stage == sb.Stage.TEST:
              lens = lens * clean_wavs.shape[1]
              for name, pred_wav, length in zip(
                  batch.id, predict_wavs, lens
              ):
                  name += ".wav"
                  enhance_path = os.path.join(
                      self.hparams.enhanced_folder, name
                  )
                  print(enhance_path)
  
                  pred_wav = (
                      pred_wav / torch.max(torch.abs(pred_wav)) * 0.99
                  )
                  torchaudio.save(
                      enhance_path,
                      pred_wav[: int(length)].cpu().unsqueeze(0),
                      hparams["sample_rate"],
                  )
      return loss
  
imports: import os
  import sys
  import torch
  import torchaudio
  import speechbrain
  from pesq import pesq
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.metric_stats import MetricStats
  from speechbrain.nnet.loss.stoi_loss import stoi_loss
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 5 for calling the SEBrain obj's underlying member method code with example usage: obj.compute_objectives_g3(d_outs, predict_wavs, clean_wavs, batch, stage, z_mean, z_logvar) and returns: loss