Ejemplo n.º 1
0
def test_overwrite_init(base_tuner_init, tmp_dir):
    tuner_module.AutoTuner(
        oracle=mock.Mock(),
        hypermodel=lambda hp: None,
        directory=tmp_dir)

    assert not base_tuner_init.call_args_list[0][1]['overwrite']
Ejemplo n.º 2
0
def test_overwrite_search(fit_fn, base_tuner_search, tmp_path):
    graph = utils.build_graph()
    tuner = tuner_module.AutoTuner(
        oracle=greedy.GreedyOracle(graph, objective='val_loss'),
        hypermodel=graph,
        directory=tmp_path)

    tuner.search(epochs=10)

    assert tuner._finished
Ejemplo n.º 3
0
def test_add_early_stopping(fit_fn, base_tuner_search, tmp_path):
    graph = utils.build_graph()
    tuner = tuner_module.AutoTuner(
        oracle=greedy.GreedyOracle(graph, objective='val_loss'),
        hypermodel=graph,
        directory=tmp_path)

    tuner.search(x=None, epochs=10)

    callbacks = base_tuner_search.call_args_list[0][1]['callbacks']
    assert any([isinstance(callback, tf.keras.callbacks.EarlyStopping)
                for callback in callbacks])
Ejemplo n.º 4
0
def test_no_epochs(best_epochs, fit_fn, base_tuner_search, tmp_path):
    best_epochs.return_value = 2
    graph = utils.build_graph()
    tuner = tuner_module.AutoTuner(
        oracle=greedy.GreedyOracle(graph, objective='val_loss'),
        hypermodel=graph,
        directory=tmp_path)

    tuner.search(x=mock.Mock(), epochs=None, fit_on_val_data=True,
                 validation_data=mock.Mock())

    callbacks = fit_fn.call_args_list[0][1]['callbacks']
    print(callbacks)
    assert not any([isinstance(callback, tf.keras.callbacks.EarlyStopping)
                    for callback in callbacks])
Ejemplo n.º 5
0
def test_overwrite_search(fit_fn, base_tuner_search, init, tmp_dir):
    graph = utils.build_graph()
    tuner = tuner_module.AutoTuner(oracle=mock.Mock(), hypermodel=graph)
    tuner.hypermodel = graph
    tuner.oracle = mock.Mock()
    tuner.directory = tmp_dir
    tuner.project_name = ''
    hp = kerastuner.HyperParameters()
    trial = mock.Mock()
    trial.hyperparameters = hp
    oracle = mock.Mock()
    oracle.get_best_trials.return_value = (trial,)
    tuner.oracle = oracle

    tuner.search()

    assert tuner._finished
Ejemplo n.º 6
0
def test_add_early_stopping(fit_fn, base_tuner_search, init, tmp_dir):
    graph = utils.build_graph()
    tuner = tuner_module.AutoTuner(oracle=mock.Mock(), hypermodel=graph)
    tuner.hypermodel = graph
    tuner.oracle = mock.Mock()
    tuner.directory = tmp_dir
    tuner.project_name = ''
    hp = kerastuner.HyperParameters()
    trial = mock.Mock()
    trial.hyperparameters = hp
    oracle = mock.Mock()
    oracle.get_best_trials.return_value = (trial,)
    tuner.oracle = oracle

    tuner.search()

    callbacks = base_tuner_search.call_args_list[0][1]['callbacks']
    assert any([isinstance(callback, tf.keras.callbacks.EarlyStopping)
                for callback in callbacks])