class_docstr: Class for sound class embedding training" 
class_docstr_tok: ["Class","for","sound","class","embedding","training","''"]
docstr: Gets called at the end of an epoch.
  Plots in subplots the values of `self.batch_to_plot` and saves the
  plot to the experiment folder. `self.hparams.output_folder`
docstr_tok: ["Gets","called","at","the","end","of","an","epoch",".","Plots","in","subplots","the","values","of","`","self.batch_to_plot","`","and","saves","the","plot","to","the","experiment","folder",".","`","self.hparams.output_folder","`"]
code: def on_stage_end(self, stage, stage_loss, epoch=None):
      """Gets called at the end of an epoch.
      Plots in subplots the values of `self.batch_to_plot` and saves the
      plot to the experiment folder. `self.hparams.output_folder`"""
  
      if stage == sb.Stage.TRAIN:
          self.train_loss = stage_loss
          self.train_stats = {
              "loss": self.train_loss,
              "acc": self.acc_metric.summarize("average"),
              "rec_error": self.recons_err.summarize("average"),
          }
          if self.hparams.use_mask_output:
              self.train_stats["mask_ll"] = self.mask_ll.summarize(
                  "average"
              )
  
      if stage == sb.Stage.VALID:
          current_fid = self.top_3_fidelity.summarize("average")
          old_lr, new_lr = self.hparams.lr_annealing(
              [self.optimizer], epoch, -current_fid
          )
          sb.nnet.schedulers.update_learning_rate(
              self.optimizer, new_lr
          )
          valid_stats = {
              "loss": stage_loss,
              "acc": self.acc_metric.summarize("average"),
              "input_fidelity": current_fid,
              "rec_error": self.recons_err.summarize("average"),
              "faithfulness_median": torch.Tensor(
                  self.faithfulness.scores
              ).median(),
              "faithfulness_mean": torch.Tensor(
                  self.faithfulness.scores
              ).mean(),
          }
          if self.hparams.use_mask_output:
              valid_stats["mask_ll"] = self.mask_ll.summarize("average")
  
          # The train_logger writes a summary to stdout and to the logfile.
          self.hparams.train_logger.log_stats(
              stats_meta={"epoch": epoch, "lr": old_lr},
              train_stats=self.train_stats,
              valid_stats=valid_stats,
          )
  
          # Save the current checkpoint and delete previous checkpoints,
          self.checkpointer.save_and_keep_only(
              meta=valid_stats, max_keys=["top-3_fid"]
          )
  
      if stage == sb.Stage.TEST:
          current_fid = self.top_3_fidelity.summarize("average")
          test_stats = {
              "loss": stage_loss,
              "acc": self.acc_metric.summarize("average"),
              "input_fidelity": current_fid,
              "faithfulness_median": torch.Tensor(
                  self.faithfulness.scores
              ).median(),
              "faithfulness_mean": torch.Tensor(
                  self.faithfulness.scores
              ).mean(),
          }
  
          # The train_logger writes a summary to stdout and to the logfile.
          self.hparams.train_logger.log_stats(
              stats_meta={"epoch": epoch}, test_stats=test_stats
          )
  
imports: import os
  import sys
  import torch
  import torchaudio
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main
  from esc50_prepare import prepare_esc50
  from speechbrain.utils.metric_stats import MetricStats
  from os import makedirs
  import torch.nn.functional
  from speechbrain.processing.NMF import spectral_phase
  import matplotlib.pyplot
label_desc: Use image node_id 11 for calling the InterpreterESC50Brain obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types