以下是我的代码
model = Sequential()
model.add(LSTM(128, input_shape=(None, 1),return_sequences=True))
model.add(Dropout(0.3))
#I want test 32,64,128,256,512,1024 number of entering the layer
model.add(LSTM(128))
model.add(Dropout(0.3))
#I want test 32,64,128,256,512,1024 number of entering the layer
model.add(Dense(128))
model.add(Dropout(0.3))
#I want test 32,64,128,256,512,1024 number of entering the layer
#and if possible, I want to add more layer using for loop like below
for i in [LSTM, Dense]
model.add(i,(j))
model.add(Dense(1))我想将数字调优为LSTM和Dense。
我想使用for循环来测试我的注释中代码中的数字。
我想知道它是如何实现的。
我想知道是否有工具可以像这样调整参数。
我们将非常感谢您的宝贵意见和想法。
发布于 2019-08-03 18:35:45
您可以为模型中要调优的每个参数构建一个列表,其中包含所有可能的配置。如下所示:
all_configurations = [
(32, 64, 128, 256, 512, 1024), # Number of output for the 1st layer
(32, 64, 128, 256, 512, 1024), # Outputs for the 2nd layer
(32,64,128,256,512,1024) # Outputs for the 3th layer
]现在您可以执行以下操作:
from itertools import product
def test_nn(a, b, c):
# a is the number of outputs for 1st layer, b for the 2nd and c for 3th
# Build network with those parameters and test it
# TODO
pass
for configuration in product(all_configurations):
test_nn(*configuration)对于您的三个超参数的每个可能的配置,将调用test_nn。在该函数内部构建和测试网络
https://stackoverflow.com/questions/57336527
复制相似问题