docstr: Computes and combines generator and discriminator losses
docstr_tok: ["Computes","and","combines","generator","and","discriminator","losses"]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes and combines generator and discriminator losses"""
      batch = batch.to(self.device)
      x, _ = batch.mel
      y, _ = batch.sig
  
      # Hold on to the batch for the inference sample. This is needed because
      # the infernece sample is run from on_stage_end only, where
      # batch information is not available
      self.last_batch = (x, y)
  
      # Hold on to a sample (for logging)
      self._remember_sample(self.last_batch, predictions)
  
      (
          y_hat,
          scores_fake,
          feats_fake,
          scores_real,
          feats_real,
      ) = predictions
      loss_g = self.hparams.generator_loss(
          stage, y_hat, y, scores_fake, feats_fake, feats_real
      )
      loss_d = self.hparams.discriminator_loss(scores_fake, scores_real)
      loss = {**loss_g, **loss_d}
      self.last_loss_stats[stage] = scalarize(loss)
      return loss
  
file_path: speechbrain/recipes/LibriTTS/vocoder/hifigan/train.py
imports: import sys
  import torch
  from hyperpyyaml import load_hyperpyyaml
  import speechbrain
  from speechbrain.utils.data_utils import scalarize
  import torchaudio
  import os
label_desc: Use image node_id 2 for calling the HifiGanBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss