docstr: Computes the loss given the predicted and targeted outputs
docstr_tok: ["Computes","the","loss","given","the","predicted","and","targeted","outputs"]
code: def compute_objectives(self, predictions, batch, stage):
      """Computes the loss given the predicted and targeted outputs"""
      predict_spec, predict_wav = predictions
      clean_wavs, lens = batch.clean_sig
  
      if getattr(self.hparams, "waveform_target", False):
          loss = self.hparams.compute_cost(
              predict_wav, clean_wavs, lens
          )
          self.loss_metric.append(
              batch.id, predict_wav, clean_wavs, lens, reduction="batch"
          )
      else:
          clean_spec = self.compute_feats(clean_wavs)
          loss = self.hparams.compute_cost(
              predict_spec, clean_spec, lens
          )
          self.loss_metric.append(
              batch.id,
              predict_spec,
              clean_spec,
              lens,
              reduction="batch",
          )
  
      if stage != sb.Stage.TRAIN:
          # Evaluate speech quality/intelligibility
          self.stoi_metric.append(
              batch.id, predict_wav, clean_wavs, lens, reduction="batch"
          )
          self.pesq_metric.append(
              batch.id,
              predict=predict_wav,
              target=clean_wavs,
              lengths=lens,
          )
  
          # Write wavs to file
          if stage == sb.Stage.TEST:
              lens = lens * clean_wavs.shape[1]
              for name, pred_wav, length in zip(
                  batch.id, predict_wav, lens
              ):
                  name += ".wav"
                  enhance_path = os.path.join(
                      self.hparams.enhanced_folder, name
                  )
                  torchaudio.save(
                      enhance_path,
                      torch.unsqueeze(pred_wav[: int(length)].cpu(), 0),
                      16000,
                  )
  
      return loss
  
file_path: speechbrain/recipes/Voicebank/enhance/spectral_mask/train.py
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.processing.features import spectral_magnitude
  from speechbrain.nnet.loss.stoi_loss import stoi_loss
  from speechbrain.utils.distributed import run_on_main
label_desc: Use image node_id 3 for calling the SEBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage) and returns: loss