docstr: Given the network predictions and targets computed the total loss
docstr_tok: ["Given","the","network","predictions","and","targets","computed","the","total","loss"]
code: def compute_objectives(
      self, predictions, batch, stage, optim_name=""
  ):
      "Given the network predictions and targets computed the total loss"
      clean_wavs, lens = batch.sig
      batch_size = clean_wavs.size(0)
  
      # Average the predictions of each time step
      clean_wavs = clean_wavs.unsqueeze(-1)
      real_result = self.modules.discriminator(clean_wavs).mean(dim=1)
      simu_result = self.modules.discriminator(predictions).mean(dim=1)
  
      real_cost = 0
      simu_cost = 0
      map_cost = self.hparams.compute_cost(
          predictions, clean_wavs, lens
      )
  
      # One is real, zero is fake
      if optim_name == "generator":
          simu_target = torch.ones(batch_size, 1, device=self.device)
          simu_cost = self.hparams.compute_cost(
              simu_result, simu_target
          )
          real_cost = 0.0
          self.metrics["G"].append(simu_cost.detach())
      elif optim_name == "discriminator":
          real_target = torch.ones(batch_size, 1, device=self.device)
          simu_target = torch.zeros(batch_size, 1, device=self.device)
          real_cost = self.hparams.compute_cost(
              real_result, real_target
          )
          simu_cost = self.hparams.compute_cost(
              simu_result, simu_target
          )
          self.metrics["D"].append((real_cost + simu_cost).detach())
  
      return real_cost + simu_cost + map_cost
  
file_path: speechbrain/tests/integration/enhance_GAN/example_enhance_gan_experiment.py
imports: import torch
  import pathlib
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
label_desc: Use image node_id 2 for calling the EnhanceGanBrain obj's underlying member method code with example usage: obj.compute_objectives(predictions, batch, stage, optim_name) and returns: unknown