class_docstr: The Brain implementation for Tacotron2
class_docstr_tok: ["The","Brain","implementation","for","Tacotron2"]
docstr: Gets called at the end of an epoch.
  Arguments
  ---------
  stage : sb.Stage
      One of sb.Stage.TRAIN, sb.Stage.VALID, sb.Stage.TEST
  stage_loss : float
      The average loss for all of the data processed in this stage.
  epoch : int
      The currently-starting epoch. This is passed
      `None` during the test stage.
docstr_tok: ["Gets","called","at","the","end","of","an","epoch",".","Arguments","--","--","--","--","-","stage",":","sb.Stage","One","of","sb.Stage.TRAIN",",","sb.Stage.VALID",",","sb.Stage.TEST","stage_loss",":","float","The","average","loss","for","all","of","the","data","processed","in","this","stage",".","epoch",":","int","The","currently-starting","epoch",".","This","is","passed","`","None","`","during","the","test","stage","."]
code: def on_stage_end(self, stage, stage_loss, epoch):
      """Gets called at the end of an epoch.
      Arguments
      ---------
      stage : sb.Stage
          One of sb.Stage.TRAIN, sb.Stage.VALID, sb.Stage.TEST
      stage_loss : float
          The average loss for all of the data processed in this stage.
      epoch : int
          The currently-starting epoch. This is passed
          `None` during the test stage.
      """
  
      # Store the train loss until the validation stage.
  
      # At the end of validation, we can write
      if stage == sb.Stage.VALID:
          # Update learning rate
          lr = self.optimizer.param_groups[-1]["lr"]
          self.last_epoch = epoch
  
          # The train_logger writes a summary to stdout and to the logfile.
          self.hparams.train_logger.log_stats(  # 1#2#
              stats_meta={"Epoch": epoch, "lr": lr},
              train_stats=self.last_loss_stats[sb.Stage.TRAIN],
              valid_stats=self.last_loss_stats[sb.Stage.VALID],
          )
  
          # Save the current checkpoint and delete previous checkpoints.
          epoch_metadata = {
              **{"epoch": epoch},
              **self.last_loss_stats[sb.Stage.VALID],
          }
          self.checkpointer.save_and_keep_only(
              meta=epoch_metadata,
              min_keys=["loss"],
              ckpt_predicate=(
                  lambda ckpt: (
                      ckpt.meta["epoch"]
                      % self.hparams.keep_checkpoint_interval
                      != 0
                  )
              )
              if self.hparams.keep_checkpoint_interval is not None
              else None,
          )
          output_progress_sample = (
              self.hparams.progress_samples
              and epoch % self.hparams.progress_samples_interval == 0
          )
          if output_progress_sample:
              self.run_inference_sample()
              self.hparams.progress_sample_logger.save(epoch)
  
      # We also write statistics about test data to stdout and to the logfile.
      if stage == sb.Stage.TEST:
          self.hparams.train_logger.log_stats(
              {"Epoch loaded": self.hparams.epoch_counter.current},
              test_stats=self.last_loss_stats[sb.Stage.TEST],
          )
          if self.hparams.progress_samples:
              self.run_inference_sample()
              self.hparams.progress_sample_logger.save("test")
  
file_path: speechbrain/recipes/LJSpeech/TTS/tacotron2/train.py
imports: import torch
  import speechbrain
  import sys
  import logging
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.text_to_sequence import text_to_sequence
  from speechbrain.utils.data_utils import scalarize
label_desc: Use image node_id 9 for calling the Tacotron2Brain obj's underlying member method code with example usage: obj.on_stage_end(stage, stage_loss, epoch) without return types