docstr: Gets called at the end of a epoch.
docstr_tok: ["Gets","called","at","the","end","of","a","epoch","."]
code: def on_stage_end(self, stage, stage_loss, epoch):
      """Gets called at the end of a epoch."""
      # Compute/store important stats
      stage_stats = {"loss": stage_loss}
      if stage == sb.Stage.TRAIN:
          self.train_stats = stage_stats
      else:
          stage_stats["CER"] = self.cer_metric.summarize("error_rate")
          stage_stats["WER"] = self.wer_metric.summarize("error_rate")
  
      # Perform end-of-iteration things, like annealing, logging, etc.
      if stage == sb.Stage.VALID:
          old_lr, new_lr = self.hparams.lr_annealing(stage_stats["WER"])
          sb.nnet.schedulers.update_learning_rate(
              self.optimizer, new_lr
          )
          self.hparams.train_logger.log_stats(
              stats_meta={"epoch": epoch, "lr": old_lr},
              train_stats=self.train_stats,
              valid_stats=stage_stats,
          )
          self.checkpointer.save_and_keep_only(
              meta={"WER": stage_stats["WER"]},
              min_keys=["WER"],
          )
      elif stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "Epoch loaded": self.hparams.epoch_counter.current
              },
              test_stats=stage_stats,
          )
          if if_main_process():
              with open(self.hparams.test_wer_file, "w") as w:
                  self.wer_metric.write_stats(w)
  
file_path: speechbrain/recipes/fluent-speech-commands/direct/train.py
imports: import sys
  import torch
  import speechbrain
  import logging
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.distributed import run_on_main, if_main_process
label_desc: Use image node_id 4 for calling the SLU obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types