(self, monitor_used=None)
return callbacks
misc_specific callbacks
misc_specific callbacks
misc_specific callbacks
def get_misc_callbacks(self, monitor_used=None):
    '''misc_specific callbacks'''
    callbacks = []
    #tensorboard
    tb_cb = TensorBoard(log_dir=self._model_path)
    callbacks.append(tb_cb)
    logging.info(f"CallBack: Tensorboard")

    # metric history
    metric_log = 'metrics.csv'
    csv_logger = CSVLogger(
        filename=Path(self._model_path).joinpath(metric_log), separator='\t')
    callbacks.append(csv_logger)
    logging.info(f"CallBack: Metric log to {metric_log}")

    #save model
    save_best = Path(self._model_path).joinpath('best_model.ckpt')
    save_best_cb = ParallelModelCheckpoint(
        model=self.model,
        filepath=str(save_best),
        monitor=monitor_used,
        verbose=1,
        save_best_only=True,
        save_weights_only=False,
        period=1)
    callbacks.append(save_best_cb)
    logging.info(f"CallBack: Save Best Model")

    # save checkpoint
    save_file_pattern = self._checkpoint_file_pattern.replace(
        'monitor_used', monitor_used)
    save_ckpt = Path(self._model_path).joinpath(save_file_pattern)
    save_ckpt_cb = ParallelModelCheckpoint(
        model=self.model,
        filepath=str(save_ckpt),
        monitor=monitor_used,
        verbose=1,
        save_best_only=False,
        save_weights_only=False,
        period=1)
    callbacks.append(save_ckpt_cb)
    logging.info(f"CallBack: Save Model Checkpoint.")

    # nan check
    callbacks.append(tf.keras.callbacks.TerminateOnNaN())

    # Stops the model early if the metrics isn't improving
    if self._early_stopping:
      logging.info(f"CallBack: Early Stop on {monitor_used}")
      es_cb = EarlyStopping(
          monitor=monitor_used, min_delta=0, patience=5, verbose=0, mode='auto')
      callbacks.append(es_cb)

    # shcedule  learning rate
    if self._val_metric:
      logging.info(f"CallBack: Learning Rate Shcedule on {monitor_used}")
      lr_shcedule = ReduceLROnPlateau(
          monitor=monitor_used,
          factor=self._decay_rate,
          patience=self._patience,
          verbose=1,
          mode='auto',
          min_delta=0.0001,
          cooldown=0,
          min_lr=self._min_lr)
      callbacks.append(lr_shcedule)
    return callbacks
def get_misc_callbacks ( self , monitor_used = None ) : callbacks = [ ] #tensorboard tb_cb = TensorBoard ( log_dir = self . _model_path ) callbacks . append ( tb_cb ) logging . info ( f"CallBack: Tensorboard" ) # metric history metric_log = 'metrics.csv' csv_logger = CSVLogger ( filename = Path ( self . _model_path ) . joinpath ( metric_log ) , separator = '\t' ) callbacks . append ( csv_logger ) logging . info ( f"CallBack: Metric log to {metric_log}" ) #save model save_best = Path ( self . _model_path ) . joinpath ( 'best_model.ckpt' ) save_best_cb = ParallelModelCheckpoint ( model = self . model , filepath = str ( save_best ) , monitor = monitor_used , verbose = 1 , save_best_only = True , save_weights_only = False , period = 1 ) callbacks . append ( save_best_cb ) logging . info ( f"CallBack: Save Best Model" ) # save checkpoint save_file_pattern = self . _checkpoint_file_pattern . replace ( 'monitor_used' , monitor_used ) save_ckpt = Path ( self . _model_path ) . joinpath ( save_file_pattern ) save_ckpt_cb = ParallelModelCheckpoint ( model = self . model , filepath = str ( save_ckpt ) , monitor = monitor_used , verbose = 1 , save_best_only = False , save_weights_only = False , period = 1 ) callbacks . append ( save_ckpt_cb ) logging . info ( f"CallBack: Save Model Checkpoint." ) # nan check callbacks . append ( tf . keras . callbacks . TerminateOnNaN ( ) ) # Stops the model early if the metrics isn't improving if self . _early_stopping : logging . info ( f"CallBack: Early Stop on {monitor_used}" ) es_cb = EarlyStopping ( monitor = monitor_used , min_delta = 0 , patience = 5 , verbose = 0 , mode = 'auto' ) callbacks . append ( es_cb ) # shcedule  learning rate if self . _val_metric : logging . info ( f"CallBack: Learning Rate Shcedule on {monitor_used}" ) lr_shcedule = ReduceLROnPlateau ( monitor = monitor_used , factor = self . _decay_rate , patience = self . _patience , verbose = 1 , mode = 'auto' , min_delta = 0.0001 , cooldown = 0 , min_lr = self . _min_lr ) callbacks . append ( lr_shcedule ) return callbacks