Ali Raza
Ali Raza

Reputation: 57

Sending parameters to Keras Tuner model- builder function

I want to send parameters to Keras Tuner's model-builder function to parameterize

for hyperparameter tuning.

However, I'm not able to send parameters to model-builder function. My code:

        hp = HyperParameters()

        learning_rate = [1e-2, 1e-3, 1e-4]
        hp.Choice('learning_rate', values=learning_rate)

        layers = [1, 2, 3]
        hp.Choice("layers", values=layers)

        layer2= [500]
        hp.Choice("layer2", values=layer2)

        layer3 = [500, 400]
        hp.Choice("layer3", values=layer3)

        activations = ['relu', 'tanh', 'sigmoid']
        hp.Choice("activations", values=activations)

        tuner = kt.Hyperband(model_builder_hp_copy,
                             hyperparameters=hp,
                             objective='val_accuracy',
                             max_epochs=10,
                             factor=3,
                             directory='my_dir',
                             project_name='intro_to_kt')

In the above code I added some choices to HyperParameters() instance to get them in model-builder function. But in that function, to get some other parameters, I don't know how they are added by default.

I want to be able send choices from out of the model-builder function and be able to use them inside.

Upvotes: 4

Views: 944

Answers (1)

zaw ish
zaw ish

Reputation: 89

If you have an existing hypermodel and you want to search over only a few parameters (such as the learning_rate), you can pass a hyperparameters argument to the tuner constructor. You also need to set tune_new_entries=False to specify that parameters that you didn't list should not be tuned. For these parameters, the default value is used.

Source: Keras Tuner documentation

Upvotes: 2

Related Questions