Exemple #1
0
    def init_callbacks(self):
        self.callbacks.append(
            ModelCheckpoint(
                filepath=os.path.join(
                    self.config.callbacks.checkpoint_dir,
                    '%s-{epoch:02d}-{val_loss:.2f}.hdf5' %
                    self.config.exp.name),
                monitor=self.config.callbacks.checkpoint_monitor,
                mode=self.config.callbacks.checkpoint_mode,
                save_best_only=self.config.callbacks.checkpoint_save_best_only,
                save_weights_only=self.config.callbacks.
                checkpoint_save_weights_only,
                verbose=self.config.callbacks.checkpoint_verbose,
            ))

        self.callbacks.append(
            TensorBoard(
                log_dir=self.config.callbacks.tensorboard_log_dir,
                write_graph=self.config.callbacks.tensorboard_write_graph,
            ))

        # if hasattr(self.config,"comet_api_key"):
        if ("comet_api_key" in self.config):
            from comet_ml import Experiment
            experiment = Experiment(api_key=self.config.comet_api_key,
                                    project_name=self.config.exp_name)
            experiment.disable_mp()
            experiment.log_parameters(self.config["trainer"])
            self.callbacks.append(experiment.get_callback('keras'))
    def init_callbacks(self):
        if (self.config.model.name == "encoder"):
            import keras
            from keras.callbacks import ModelCheckpoint, TensorBoard, ReduceLROnPlateau, EarlyStopping
        else:
            import tensorflow.keras as keras
            from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard, ReduceLROnPlateau, EarlyStopping
        self.callbacks.append(
            ModelCheckpoint(
                filepath=os.path.join(
                    self.config.callbacks.checkpoint_dir,
                    '%s-{epoch:02d}-{val_loss:.2f}.hdf5' %
                    self.config.exp.name),
                monitor=self.config.callbacks.checkpoint_monitor,
                mode=self.config.callbacks.checkpoint_mode,
                save_best_only=self.config.callbacks.checkpoint_save_best_only,
                save_weights_only=self.config.callbacks.
                checkpoint_save_weights_only,
                verbose=self.config.callbacks.checkpoint_verbose,
            ))
        self.callbacks.append(
            ModelCheckpoint(
                filepath=os.path.join(
                    self.config.callbacks.checkpoint_dir,
                    'best_model-%s.hdf5' %
                    self.config.callbacks.checkpoint_monitor),
                monitor=self.config.callbacks.checkpoint_monitor,
                mode=self.config.callbacks.checkpoint_mode,
                save_best_only=self.config.callbacks.checkpoint_save_best_only,
            ))
        self.callbacks.append(
            ReduceLROnPlateau(monitor='val_loss',
                              factor=0.5,
                              patience=10,
                              min_lr=0.0001))
        self.callbacks.append(
            EarlyStopping(monitor='val_loss', patience=10, verbose=1), )
        # 在TCN中使用了tensorflow_addson中的WeightNormalization层,与tensorboard不兼容
        # if (self.config.model.name != "tcn"):
        #     self.callbacks.append(
        #         TensorBoard(
        #             log_dir=self.config.callbacks.tensorboard_log_dir,
        #             write_graph=self.config.callbacks.tensorboard_write_graph,
        #             histogram_freq=1,
        #         )
        #     )
        # if self.config.dataset.name == "ptbdb":
        #     self.callbacks.append(
        #         AdvancedLearnignRateScheduler(monitor='val_main_output_loss', patience=6, verbose=1, mode='auto',
        #                                       decayRatio=0.1),
        #     )

        if ("comet_api_key" in self.config):
            from comet_ml import Experiment
            experiment = Experiment(api_key=self.config.comet_api_key,
                                    project_name=self.config.exp_name)
            experiment.disable_mp()
            experiment.log_parameters(self.config["trainer"])
            self.callbacks.append(experiment.get_callback('keras'))
Exemple #3
0
    def init_callbacks(self):
        if (self.config.model.name == "encoder"):
            import keras
        else:
            import tensorflow.keras as keras
        from keras.callbacks import ModelCheckpoint, TensorBoard, ReduceLROnPlateau
        self.callbacks.append(
            ModelCheckpoint(
                filepath=os.path.join(
                    self.config.callbacks.checkpoint_dir,
                    '%s-{epoch:02d}-{val_loss:.2f}.hdf5' %
                    self.config.exp.name),
                monitor=self.config.callbacks.checkpoint_monitor,
                mode=self.config.callbacks.checkpoint_mode,
                save_best_only=self.config.callbacks.checkpoint_save_best_only,
                save_weights_only=self.config.callbacks.
                checkpoint_save_weights_only,
                verbose=self.config.callbacks.checkpoint_verbose,
            ))
        self.callbacks.append(
            ModelCheckpoint(
                filepath=os.path.join(
                    self.config.callbacks.checkpoint_dir,
                    'best_model-%s.hdf5' %
                    self.config.callbacks.checkpoint_monitor),
                monitor=self.config.callbacks.checkpoint_monitor,
                mode=self.config.callbacks.checkpoint_mode,
                save_best_only=self.config.callbacks.checkpoint_save_best_only,
            ))
        self.callbacks.append(
            ReduceLROnPlateau(monitor='val_loss',
                              factor=0.5,
                              patience=50,
                              min_lr=0.0001))
        self.callbacks.append(
            TensorBoard(
                log_dir=self.config.callbacks.tensorboard_log_dir,
                write_graph=self.config.callbacks.tensorboard_write_graph,
                histogram_freq=1,
            ))

        # if hasattr(self.config,"comet_api_key"):
        if ("comet_api_key" in self.config):
            from comet_ml import Experiment
            experiment = Experiment(api_key=self.config.comet_api_key,
                                    project_name=self.config.exp_name)
            experiment.disable_mp()
            experiment.log_parameters(self.config["trainer"])
            self.callbacks.append(experiment.get_callback('keras'))
    def init_callbacks(self):
        self.callbacks.append(
            ModelCheckpoint(
                filepath=os.path.join(self.config.callbacks.checkpoint_dir,
                                      'best_model.hdf5'),
                monitor=self.config.callbacks.checkpoint_monitor,
                mode=self.config.callbacks.checkpoint_mode,
                save_best_only=self.config.callbacks.checkpoint_save_best_only,
                save_weights_only=self.config.callbacks.
                checkpoint_save_weights_only,
                verbose=self.config.callbacks.checkpoint_verbose,
            ))

        self.callbacks.append(
            EarlyStopping(monitor='val_loss', patience=10, verbose=1))

        self.callbacks.append(
            AdvancedLearnignRateScheduler(monitor='val_loss',
                                          patience=5,
                                          verbose=1,
                                          mode='auto',
                                          warmup_batches=10,
                                          decayRatio=0.1))

        self.callbacks.append(
            TensorBoard(
                log_dir=self.config.callbacks.tensorboard_log_dir,
                write_graph=self.config.callbacks.tensorboard_write_graph,
            ))

        # if hasattr(self.config,"comet_api_key"):
        if ("comet_api_key" in self.config):
            from comet_ml import Experiment
            experiment = Experiment(api_key=self.config.comet_api_key,
                                    project_name=self.config.exp_name)
            experiment.disable_mp()
            experiment.log_parameters(self.config["args"])
            self.callbacks.append(experiment.get_callback('keras'))
    def init_callbacks(self):
        # Stops training if accuracy does not change at least 0.005 over 10 epochs
        # self.callbacks.append(
        #     EarlyStopping(monitor='acc', min_delta=.005, patience=10, verbose=1, mode='auto')
        # )

        self.callbacks.append(
            TensorBoard(
                log_dir=self.config.callbacks.tensorboard_log_dir,
                write_graph=self.config.callbacks.tensorboard_write_graph,
            ))

        self.callbacks.append(
            ModelCheckpoint(
                filepath=os.path.join(
                    self.config.callbacks.checkpoint_dir,
                    '%s-{epoch:02d}-{val_loss:.2f}.hdf5' %
                    self.config.exp.name),
                monitor=self.config.callbacks.checkpoint_monitor,
                mode=self.config.callbacks.checkpoint_mode,
                save_best_only=self.config.callbacks.checkpoint_save_best_only,
                save_weights_only=self.config.callbacks.
                checkpoint_save_weights_only,
                verbose=self.config.callbacks.checkpoint_verbose,
            ))

        # log experiments to comet.ml
        if hasattr(self.config.api, "comet"):
            from comet_ml import Experiment
            experiment = Experiment(
                api_key=self.config.api.comet.api_key,
                project_name=self.config.api.comet.exp_name)
            experiment.disable_mp()
            experiment.log_parameters(self.config.toDict())
            self.experiment_id = experiment.id
            self.callbacks.append(experiment.get_callback('keras'))