maxpumperla / hyperas

Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization
http://maxpumperla.com/hyperas/
MIT License
2.18k stars 318 forks source link

Error if no hyperparameter search before choice between different models #224

Open komodovaran opened 5 years ago

komodovaran commented 5 years ago

Using the frontpage complete MNIST example, the below only works if some hyperparameter search is added after Sequential

model = Sequential()

model.add(Dense({{choice([100, 200])}})) # This works
# model.add(Activation({{choice([None])}})) # This also works. Yes, it's commented out!

if {{choice(['mdl1', 'mdl2'])}} == 'mdl1':
    model.add(Dense({{choice([100, 200])}}))
    model.add(Activation('relu'))
else:
    model.add(Dense({{choice([100, 200])}}))
    model.add(Activation('relu'))

model.add(Dense(10))
model.add(Activation('softmax'))

Even commenting out the first line also works. But removing it entirely throws the classic IndexError: list index out of range.

maxpumperla commented 5 years ago

@Komodovaran thanks, this is an interesting edge case I actually never considered. good catch!