original_docstring: Gets called at the end of a epoch.
docstring: Gets called at the end of a epoch.
docstring_tokens: 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."""
          if hasattr(self.hparams, "switch_training_type"):
              if not hasattr(self.hparams, "switch_training_epoch"):
                  raise ValueError(
                      "Please specify `switch_training_epoch` in `params`"
                  )
              if (
                  self.hparams.epoch_counter.current
                  == self.hparams.switch_training_epoch
              ) and stage == sb.Stage.VALID:
                  self.training_type = self.hparams.switch_training_type
                  print("Switching to training type", self.training_type)
  
          if stage == sb.Stage.TRAIN:
              self.train_loss = stage_loss
          else:
              acc = self.accuracy_metrics.summarize("average")
  
          if stage == sb.Stage.VALID:
              old_lr, new_lr = self.hparams.lr_annealing(acc)
              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={"loss": self.train_loss},
                  valid_stats={"loss": stage_loss, "accuracy": acc},
              )
              self.checkpointer.save_and_keep_only(
                  meta={"accuracy": acc}, max_keys=["accuracy"],
              )
  
          elif stage == sb.Stage.TEST:
              self.hparams.train_logger.log_stats(
                  stats_meta={"Epoch loaded": self.hparams.epoch_counter.current},
                  test_stats={"loss": stage_loss, "accuracy": acc},
              )
code_tokens: def on_stage_end ( self , stage , stage_loss , epoch ) : if hasattr ( self . hparams , "switch_training_type" ) : if not hasattr ( self . hparams , "switch_training_epoch" ) : raise ValueError ( "Please specify `switch_training_epoch` in `params`" ) if ( self . hparams . epoch_counter . current == self . hparams . switch_training_epoch ) and stage == sb . Stage . VALID : self . training_type = self . hparams . switch_training_type print ( "Switching to training type" , self . training_type ) if stage == sb . Stage . TRAIN : self . train_loss = stage_loss else : acc = self . accuracy_metrics . summarize ( "average" ) if stage == sb . Stage . VALID : old_lr , new_lr = self . hparams . lr_annealing ( acc ) 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 = { "loss" : self . train_loss } , valid_stats = { "loss" : stage_loss , "accuracy" : acc } , ) self . checkpointer . save_and_keep_only ( meta = { "accuracy" : acc } , max_keys = [ "accuracy" ] , ) elif stage == sb . Stage . TEST : self . hparams . train_logger . log_stats ( stats_meta = { "Epoch loaded" : self . hparams . epoch_counter . current } , test_stats = { "loss" : stage_loss , "accuracy" : acc } , )
short_docstring: Gets called at the end of a epoch.
short_docstring_tokens: Gets called at the end of a epoch .
comment: """Gets called at the end of a epoch."""