neptunecontrib.monitoring.kerastuner

Module Contents

Classes

NeptuneLogger(experiment=None)

Logs hyperparameter optimization process to Neptune.

Functions

log_tuner_info(tuner, experiment=None, log_project_dir=True)

Logs runs results and parameters to neptune.

class neptunecontrib.monitoring.kerastuner.NeptuneLogger(experiment=None)

Bases: kerastuner.engine.logger.Logger

Logs hyperparameter optimization process to Neptune.

For each iteration it logs run parameters (‘hyperparameters/values’ text log),

and all the metrics and losses to Neptune.

Parameters

experiment (neptune.experiments.Experiment) – Neptune experiment. Default is None.

Examples

Initialize neptune_monitor:

import neptune
import neptunecontrib.monitoring.kerastuner as npt_utils

neptune.init(api_token='ANONYMOUS',
             project_qualified_name='shared/keras-tuner-integration')
neptune.create_experiment(name='bayesian-sweep')

neptune_logger = npt_utils.NeptuneLogger()

Run Keras Tuner search passing neptune_logger as logger:

...
tuner =  BayesianOptimization(
    build_model,
    objective='val_accuracy',
    max_trials=10,
    num_initial_points=3,
    executions_per_trial=3,
    project_name='bayesian-sweep',
    logger=npt_utils.NeptuneLogger())

You can explore an example experiment in Neptune: https://ui.neptune.ai/o/shared/org/keras-tuner-integration/e/KER-19/charts

report_trial_state(self, trial_id, trial_state)

Gives the logger information about trial status.

register_tuner(self, tuner_state)
register_trial(self, trial_id, trial_state)
exit(self)
neptunecontrib.monitoring.kerastuner.log_tuner_info(tuner, experiment=None, log_project_dir=True)

Logs runs results and parameters to neptune.

Logs all hyperparameter optimization results to Neptune. Those include best score (‘best_score’ metric), best parameters (‘best_parameters’ property), score for every run (‘run_score’ metric), tuner project directory as an artifact, parameter space (‘hyperparameters/space’ text log), tuner id (‘tuner_id’ property), best trial id (‘best_trial_id’ property), name of the metric/loss used as objective, and it’s direction (‘objective/name’ and ‘objective/direction’ property).

Parameters
  • tuner ('kerastuner.engine.tuner.Tuner') – Keras Tuner object after training is completed.

  • experiment (neptune.experiments.Experiment) – Neptune experiment. Default is None.

  • log_project_dir ('bool') – Whether Keras Tuner project directory, with all the trial information, should be logged to Neptune.

Examples

Initialize neptune experiment:

import neptune

neptune.init(api_token='ANONYMOUS',
             project_qualified_name='shared/keras-tuner-integration')
neptune.create_experiment(name='bayesian-sweep')

Run Keras Tuner search:

...
tuner =  BayesianOptimization(...)
tuner.search(x=x, y=y,
             epochs=5,
             validation_data=(val_x, val_y))

Log information from the Tuner object to Neptune:

import neptunecontrib.monitoring.kerastuner as npt_utils
npt_utils.log_tuner_info(tuner)

You can explore an example experiment in Neptune: https://ui.neptune.ai/o/shared/org/keras-tuner-integration/e/KER-19/details