TypeError: hp_choice() takes 2 positional arguments but 7 were given
I'm trying to do hyperparameter optimization to this keras model with the hyperas library, I've never done this before so I basically followed the step-by-step complete example here but I'm getting the error mentioned. Thanks in advance.
model = Sequential()
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
input_shape=input_shape, activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
input_shape=input_shape, activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
input_shape=input_shape, activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
input_shape=input_shape, activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(Conv2D({{choice(32, 64, 128, 256, 512, 1024)}}, 3, 3, border_mode='same',
activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense({{choice(32, 64, 128, 256, 512, 1024)}},
activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(Dropout({{uniform(0, 0.75)}}))
model.add(Dense({{choice(32, 64, 128, 256, 512, 1024)}},
activation={{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.add(Dropout({{uniform(0, 0.75)}}))
model.add(Dense(1))
model.add(Activation({{choice('relu', 'sigmoid', 'softmax', 'tanh')}}))
model.compile(loss='binary_crossentropy',
optimizer={{choice(RMSprop, Adam, SGD)}},
metrics=['accuracy'])
"/home/bjorn/PycharmProjects/Test/HyperoptModel.py", line 113, in <module> trials=Trials()) File "/home/bjorn/PycharmProjects/Test/venv/lib/python3.5/site-packages/hyperas/optim.py", line 69, in minimize keep_temp=keep_temp) File "/home/bjorn/PycharmProjects/Test/venv/lib/python3.5/site-packages/hyperas/optim.py", line 134, in base_minimizer space=get_space(), File "/home/bjorn/PycharmProjects/Test/temp_model.py", line 149, in get_space File "/home/bjorn/PycharmProjects/Test/venv/lib/python3.5/site-packages/hyperopt/pyll_utils.py", line 22, in wrapper return f(label, *args, **kwargs) TypeError: hp_choice() takes 2 positional arguments but 7 were given ```
1 ответ
Решение
You need to give the options for choice
as a list
instead as multiple parameters.
change
choice(32, 64, 128, 256, 512, 1024)
to
choice([32, 64, 128, 256, 512, 1024])