docstr: This function calculates the oracle si-snrs and the estimated si-snr on the test set of WHAMR! dataset, and writes these results into a csv file
docstr_tok: ["This","function","calculates","the","oracle","si-snrs","and","the","estimated","si-snr","on","the","test","set","of","WHAMR","!","dataset",",","and","writes","these","results","into","a","csv","file"]
code: def save_results(self, test_data):
      """
      This function calculates the oracle si-snrs and the estimated si-snr on the test set of WHAMR! dataset, and writes these results into a csv file
      """
  
      # Create folders where to store audio
      save_file = os.path.join(
          self.hparams.output_folder, "test_results_wsj.csv"
      )
  
      # Variable init
      all_sisnr1s = []
      all_sisnr1_hats = []
      all_sisnr2s = []
      all_sisnr2_hats = []
  
      csv_columns = ["snt_id", "snr1", "snr1-hat", "snr2", "snr2-hat"]
  
      test_loader = sb.dataio.dataloader.make_dataloader(
          test_data, **self.hparams.dataloader_opts
      )
  
      with open(save_file, "w") as results_csv:
          writer = csv.DictWriter(results_csv, fieldnames=csv_columns)
          writer.writeheader()
  
          # Loop over all test sentence
          with tqdm(test_loader, dynamic_ncols=True) as t:
              for i, batch in enumerate(t):
                  # Apply Separation
                  mixture = batch.mix_sig
                  snt_id = batch.id
                  targets = [batch.s1_sig, batch.s2_sig]
                  if self.hparams.num_spks == 3:
                      targets.append(batch.s3_sig)
  
                  if self.hparams.use_wham_noise:
                      noise = batch.noise_sig[0]
                  else:
                      noise = None
  
                  with torch.no_grad():
                      (
                          predictions,
                          snrhat,
                          snr,
                          snr_compressed,
                      ) = self.compute_forward(
                          mixture, targets, sb.Stage.VALID, noise
                      )
  
                      if self.hparams.use_snr_compression:
                          snrhat = self.gettrue_snrrange(snrhat)
  
                  # Saving on a csv file
                  row = {
                      "snt_id": snt_id[0],
                      "snr1": snr.squeeze()[0].item(),
                      "snr1-hat": snrhat[0].item(),
                      "snr2": snr.squeeze()[1].item(),
                      "snr2-hat": snrhat[1].item(),
                  }
                  writer.writerow(row)
  
                  # Metric Accumulation
                  all_sisnr1s.append(snr.squeeze()[0].item())
                  all_sisnr1_hats.append(snrhat[0].item())
                  all_sisnr2s.append(snr.squeeze()[1].item())
                  all_sisnr2_hats.append(snrhat[1].item())
  
              row = {
                  "snt_id": "avg",
                  "snr1": np.array(all_sisnr1s).mean(),
                  "snr1-hat": np.array(all_sisnr1_hats).mean(),
                  "snr2": np.array(all_sisnr2s).mean(),
                  "snr2-hat": np.array(all_sisnr2_hats).mean(),
              }
              writer.writerow(row)
  
      logger.info(
          "Mean SISNR for source 1 is {}".format(
              np.array(all_sisnr1s).mean()
          )
      )
      logger.info(
          "Mean SISNR hat for source 1 is {}".format(
              np.array(all_sisnr1_hats).mean()
          )
      )
      logger.info(
          "Mean SISNR for source 2 is {}".format(
              np.array(all_sisnr2s).mean()
          )
      )
      logger.info(
          "Mean SISNR hat for source 2 is {}".format(
              np.array(all_sisnr2_hats).mean()
          )
      )
  
imports: import os
  import sys
  import torch
  import speechbrain
  import speechbrain.nnet.schedulers
  from speechbrain.utils.distributed import run_on_main
  from hyperpyyaml import load_hyperpyyaml
  import itertools
  from tqdm import tqdm
  import numpy
  import logging
  import csv
  from speechbrain.core import AMPConfig
label_desc: Use image node_id 11 for calling the Separation obj's underlying member method code with example usage: obj.save_results(test_data) without return types