docstr: Gets called at the end of an epoch.
docstr_tok: ["Gets","called","at","the","end","of","an","epoch","."]
code: def on_stage_end(self, stage, stage_loss, epoch):
      """Gets called at the end of an epoch."""
  
      # Save loss and metrics.
      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["COER"] = self.coer_metric.summarize("error_rate")
          stage_stats["CVER"] = self.cver_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["loss"]
          )
          (
              old_lr_wav2vec,
              new_lr_wav2vec,
          ) = self.hparams.lr_annealing_wav2vec(stage_stats["loss"])
          sb.nnet.schedulers.update_learning_rate(
              self.optimizer, new_lr
          )
          sb.nnet.schedulers.update_learning_rate(
              self.optimizer_wav2vec, new_lr_wav2vec
          )
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "epoch": epoch,
                  "lr": old_lr,
                  "lr_wav2vec": old_lr_wav2vec,
              },
              train_stats=self.train_stats,
              valid_stats=stage_stats,
          )
          self.checkpointer.save_and_keep_only(
              meta={"CER": stage_stats["CER"]},
              min_keys=["CER"],
          )
  
      # Same plus write results in txt files.
      elif stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              stats_meta={
                  "Epoch loaded": self.hparams.epoch_counter.current
              },
              test_stats=stage_stats,
          )
          with open(hparams["cer_file_test"], "w") as w:
              self.cer_metric.write_stats(w)
          with open(hparams["ctc_file_test"], "w") as w:
              self.ctc_metric.write_stats(w)
          with open(hparams["coer_file_test"], "w") as w:
              self.coer_metric.write_stats(w)
          with open(hparams["cver_file_test"], "w") as w:
              self.cver_metric.write_stats(w)
  
file_path: speechbrain/recipes/MEDIA/SLU/CTC/train_hf_wav2vec.py
imports: import sys
  import torch
  import logging
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.dataio.batch import PaddedBatch
  from speechbrain.utils.distributed import run_on_main
  from media_prepare import prepare_media
label_desc: Use image node_id 5 for calling the SLU obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types