KeyError when using conditional hyperparameters
See original GitHub issueDescribe the bug
When I use parent_name
and parent_valus
I always get a KeyError
when building a model.
Invalid model 5/5
Traceback (most recent call last):
File "/Users/douira/Documents/dev/uni/bachelorarbeit/tf-time-series/venv/lib/python3.8/site-packages/keras_tuner/engine/hypermodel.py", line 127, in build
model = self.hypermodel.build(hp)
File "keras-tuner-test.py", line 22, in model_builder
dense_units1 = hp.Int(
File "/Users/douira/Documents/dev/uni/bachelorarbeit/tf-time-series/venv/lib/python3.8/site-packages/keras_tuner/engine/hyperparameters.py", line 850, in Int
return self._retrieve(hp)
File "/Users/douira/Documents/dev/uni/bachelorarbeit/tf-time-series/venv/lib/python3.8/site-packages/keras_tuner/engine/hyperparameters.py", line 707, in _retrieve
return self.values[hp.name]
KeyError: 'dense_units1'
To Reproduce Use keras-tuner 1.0.4: https://colab.research.google.com/drive/1dlys0Dmpt9hjLkKOP62SfhYnIQmOgVxy?usp=sharing
import keras_tuner as kt
from tensorflow import keras
def model_builder(hp):
dense_layers = hp.Int("dense_layers", min_value=0, max_value=2, step=1)
dense_units1 = hp.Int(
"dense_units1",
min_value=16,
max_value=512,
step=16,
parent_name="dense_layers",
parent_values=[1, 2],
)
return keras.Sequential()
tuner = kt.RandomSearch(
model_builder,
objective="val_accuracy",
directory="./model_tuning",
max_trials=1,
)
Expected behavior The model should build normally. This worked on keras-tuner 1.0.3. It does not work (this bug happens) on keras-tuner 1.0.4.
Additional context If there is any way of using conditional hyperparameters on keras-tuner while avoiding this bug I’d be interested to hear about it. Otherwise I’ll downgrade my version of keras-tuner until this issue is resolved somehow. Thank you for the great work on this project!
Would you like to help us fix it? I don’t know why it’s happening. Maybe I’m doing something wrong. If this actually is a bug, then looking at what changed between keras-tuner 1.0.3 and 1.0.4 is probably a good idea. (the Google Collab confirms this difference)
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (3 by maintainers)
Top GitHub Comments
@YASIRAQ I downgraded to 1.0.3, which did not have this regression.
Had to search for 5-6 hours for this answer, except with Hyperband’s objective. The downgrade to 1.0.3 was the only thing that worked. Thank you @gerwim