class_docstr: Collection of useful functions to manage training sessions.
  
  Args:
      generator: Keras model, the super-scaling, or generator, network.
      logs_dir: path to the directory where the tensorboard logs are saved.
      weights_dir: path to the directory where the weights are saved.
      lr_train_dir: path to the directory containing the Low-Res images.
      feature_extractor: Keras model, feature extractor network for the deep features
          component of perceptual loss function.
      discriminator: Keras model, the discriminator network for the adversarial
          component of the perceptual loss.
      dataname: string, used to identify what dataset is used for the training session.
      weights_dictionarycontains the paths, if any to the
          pre-trained generator's and to the pre-trained discriminator's weights,
          for transfer learning.
      fallback_save_every_n_epochs: integer, determines after how many epochs that did not trigger
          weights saving the weights are despite no metric improvement.
      max_n_best_weights: maximum amount of weights that are best on some metric that are kept.
      max_n_other_weights: maximum amount of non-best weights that are kept.
  
  
  Methods:
      print_training_setting: see docstring.
      on_epoch_end: see docstring.
      epoch_n_from_weights_name: see docstring.
      initialize_training: see docstring.
class_docstr_tok: ["Collection","of","useful","functions","to","manage","training","sessions",".","Args",":","generator",":","Keras","model",",","the","super-scaling",",","or","generator",",","network",".","logs_dir",":","path","to","the","directory","where","the","tensorboard","logs","are","saved",".","weights_dir",":","path","to","the","directory","where","the","weights","are","saved",".","lr_train_dir",":","path","to","the","directory","containing","the","Low-Res","images",".","feature_extractor",":","Keras","model",",","feature","extractor","network","for","the","deep","features","component","of","perceptual","loss","function",".","discriminator",":","Keras","model",",","the","discriminator","network","for","the","adversarial","component","of","the","perceptual","loss",".","dataname",":","string",",","used","to","identify","what","dataset","is","used","for","the","training","session",".","weights_dictionarycontains","the","paths",",","if","any","to","the","pre-trained","generator","'s","and","to","the","pre-trained","discriminator","'s","weights",",","for","transfer","learning",".","fallback_save_every_n_epochs",":","integer",",","determines","after","how","many","epochs","that","did","not","trigger","weights","saving","the","weights","are","despite","no","metric","improvement",".","max_n_best_weights",":","maximum","amount","of","weights","that","are","best","on","some","metric","that","are","kept",".","max_n_other_weights",":","maximum","amount","of","non-best","weights","that","are","kept",".","Methods",":","print_training_setting",":","see","docstring",".","on_epoch_end",":","see","docstring",".","epoch_n_from_weights_name",":","see","docstring",".","initialize_training",":","see","docstring","."]
docstr: Saves the weights of the non-None models. 
docstr_tok: ["Saves","the","weights","of","the","non-None","models","."]
code: def _save_weights(
      self,
      epoch,
      generator,
      discriminator=None,
      metric=None,
      best=False,
  ):
      """Saves the weights of the non-None models."""
  
      if best:
          gen_path = self.weights_name["generator"].with_name(
              (self.weights_name["generator"].name).format(
                  metric="_best-" + metric, epoch=epoch + 1
              )
          )
      else:
          gen_path = self.weights_name["generator"].with_name(
              (self.weights_name["generator"].name).format(
                  metric="", epoch=epoch + 1
              )
          )
      # CANT SAVE MODEL DUE TO TF LAYER INSIDE LAMBDA (PIXELSHUFFLE)
      generator.save_weights(gen_path.as_posix())
      if discriminator:
          if best:
              discr_path = self.weights_name["discriminator"].with_name(
                  (self.weights_name["discriminator"].name).format(
                      metric="_best-" + metric, epoch=epoch + 1
                  )
              )
          else:
              discr_path = self.weights_name["discriminator"].with_name(
                  (self.weights_name["discriminator"].name).format(
                      metric="", epoch=epoch + 1
                  )
              )
          discriminator.model.save_weights(discr_path.as_posix())
      try:
          self._remove_old_weights(
              self.max_n_other_weights, max_best=self.max_n_best_weights
          )
      except Exception as e:
          self.logger.warning("Could not remove weights: {}".format(e))
  
file_path: image-super-resolution/ISR/utils/train_helper.py
imports: import yaml
  import numpy
  from pathlib import Path
  from ISR.utils.logger import get_logger
  from ISR.utils.utils import get_timestamp
label_desc: Use image node_id 9 for calling the TrainerHelper obj's underlying member method code with example usage: obj._save_weights(epoch, generator, discriminator, metric, best) without return types