我正在尝试使用hyperas库对该keras模型进行超参数优化,我之前从未做过此操作,因此我基本上遵循了逐步完成的示例here,但是我得到了提到错误。预先感谢。
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 ```
答案 0 :(得分:1)
您需要将choice
的选项作为list
而不是多个参数。
更改
choice(32, 64, 128, 256, 512, 1024)
到
choice([32, 64, 128, 256, 512, 1024])