docstr: Iterate test_set and create output file (id, predictions, true values).
  
  Arguments
  ---------
  test_set : Dataset, DataLoader
      If a DataLoader is given, it is iterated directly. Otherwise passed
      to ``self.make_dataloader()``.
  max_key : str
      Key to use for finding best checkpoint, passed to
      ``on_evaluate_start()``.
  min_key : str
      Key to use for finding best checkpoint, passed to
      ``on_evaluate_start()``.
  progressbar : bool
      Whether to display the progress in a progressbar.
  test_loader_kwargs : dict
      Kwargs passed to ``make_dataloader()`` if ``test_set`` is not a
      DataLoader. NOTE: ``loader_kwargs["ckpt_prefix"]`` gets
      automatically overwritten to ``None`` (so that the test DataLoader
      is not added to the checkpointer).
docstr_tok: ["Iterate","test_set","and","create","output","file","(","id",",","predictions",",","true","values",")",".","Arguments","--","--","--","--","-","test_set",":","Dataset",",","DataLoader","If","a","DataLoader","is","given",",","it","is","iterated","directly",".","Otherwise","passed","to","``","self.make_dataloader","(",")","``",".","max_key",":","str","Key","to","use","for","finding","best","checkpoint",",","passed","to","``","on_evaluate_start","(",")","``",".","min_key",":","str","Key","to","use","for","finding","best","checkpoint",",","passed","to","``","on_evaluate_start","(",")","``",".","progressbar",":","bool","Whether","to","display","the","progress","in","a","progressbar",".","test_loader_kwargs",":","dict","Kwargs","passed","to","``","make_dataloader","(",")","``","if","``","test_set","``","is","not","a","DataLoader",".","NOTE",":","``","loader_kwargs","[","``","ckpt_prefix","''","]","``","gets","automatically","overwritten","to","``","None","``","(","so","that","the","test","DataLoader","is","not","added","to","the","checkpointer",")","."]
code: def output_predictions_test_set(
      self,
      test_set,
      max_key=None,
      min_key=None,
      progressbar=None,
      test_loader_kwargs={},
  ):
      """Iterate test_set and create output file (id, predictions, true values).
  
      Arguments
      ---------
      test_set : Dataset, DataLoader
          If a DataLoader is given, it is iterated directly. Otherwise passed
          to ``self.make_dataloader()``.
      max_key : str
          Key to use for finding best checkpoint, passed to
          ``on_evaluate_start()``.
      min_key : str
          Key to use for finding best checkpoint, passed to
          ``on_evaluate_start()``.
      progressbar : bool
          Whether to display the progress in a progressbar.
      test_loader_kwargs : dict
          Kwargs passed to ``make_dataloader()`` if ``test_set`` is not a
          DataLoader. NOTE: ``loader_kwargs["ckpt_prefix"]`` gets
          automatically overwritten to ``None`` (so that the test DataLoader
          is not added to the checkpointer).
      """
      if progressbar is None:
          progressbar = not self.noprogressbar
  
      if not isinstance(test_set, DataLoader):
          test_loader_kwargs["ckpt_prefix"] = None
          test_set = self.make_dataloader(
              test_set, Stage.TEST, **test_loader_kwargs
          )
  
          save_file = os.path.join(
              self.hparams.output_folder, "predictions.csv"
          )
          with open(save_file, "w", newline="") as csvfile:
              outwriter = csv.writer(csvfile, delimiter=",")
              outwriter.writerow(["id", "prediction", "true_value"])
  
      self.on_evaluate_start(
          max_key=max_key, min_key=min_key
      )  # done before
      self.modules.eval()
      with torch.no_grad():
          for batch in tqdm(
              test_set, dynamic_ncols=True, disable=not progressbar
          ):
              self.step += 1
  
              emo_ids = batch.id
              true_vals = batch.emo_encoded.data.squeeze(dim=1).tolist()
              output = self.compute_forward(batch, stage=Stage.TEST)
              predictions = (
                  torch.argmax(output, dim=-1).squeeze(dim=1).tolist()
              )
  
              with open(save_file, "a", newline="") as csvfile:
                  outwriter = csv.writer(csvfile, delimiter=",")
                  for emo_id, prediction, true_val in zip(
                      emo_ids, predictions, true_vals
                  ):
                      outwriter.writerow([emo_id, prediction, true_val])
  
              # Debug mode only runs a few batches
              if self.debug and self.step == self.debug_batches:
                  break
      self.step = 0
  
file_path: speechbrain/recipes/IEMOCAP/emotion_recognition/train.py
imports: import os
  import sys
  import csv
  import speechbrain
  import torch
  from torch.utils.data import DataLoader
  from enum import Enum, auto
  from tqdm.contrib import tqdm
  from hyperpyyaml import load_hyperpyyaml
label_desc: Use image node_id 5 for calling the EmoIdBrain obj's underlying member method code with example usage: obj.output_predictions_test_set(test_set, max_key, min_key, progressbar, test_loader_kwargs) without return types