HyperbandOracle
classkeras_tuner.oracles.HyperbandOracle(
objective=None,
max_epochs=100,
factor=3,
hyperband_iterations=1,
seed=None,
hyperparameters=None,
allow_new_entries=True,
tune_new_entries=True,
max_retries_per_trial=0,
max_consecutive_failed_trials=3,
)
Oracle class for Hyperband.
Note that to use this Oracle with your own subclassed Tuner, your Tuner
class must be able to handle in Tuner.run_trial
three special
hyperparameters that will be set by this Tuner:
These hyperparameters will be set during the "successive halving" portion of the Hyperband algorithm.
Examples
def run_trial(self, trial, *args, **kwargs):
hp = trial.hyperparameters
if "tuner/trial_id" in hp:
past_trial = self.oracle.get_trial(hp['tuner/trial_id'])
model = self.load_model(past_trial)
else:
model = self.hypermodel.build(hp)
initial_epoch = hp['tuner/initial_epoch']
last_epoch = hp['tuner/epochs']
for epoch in range(initial_epoch, last_epoch):
self.on_epoch_begin(...)
for step in range(...):
# Run model training step here.
self.on_epoch_end(...)
Arguments
keras_tuner.Objective
instance, or a list of
keras_tuner.Objective
s and strings. If a string, the direction of
the optimization (min or max) will be inferred. If a list of
keras_tuner.Objective
, we will minimize the sum of all the
objectives to minimize subtracting the sum of all the objectives to
maximize. The objective
argument is optional when
Tuner.run_trial()
or HyperModel.fit()
returns a single float as
the objective to minimize.tf.keras.callbacks.EarlyStopping
). Defaults to 100.max_epochs * (math.log(max_epochs, factor) ** 2)
cumulative epochs across all trials. It is recommended to set this
to as high a value as is within your resource budget. Defaults to
1.hyperparameters
should be added to the search space, or not. If
not, then the default value for these parameters will be used.
Defaults to True.hyperparameters
.
Defaults to True.Trial
if the trial crashed or the results are
invalid.Trial
s. When this number is reached,
the search will be stopped. A Trial
is marked as failed when none
of the retries succeeded.