[英]how to tuning parameter entering the layer using for loop?
here is my code 这是我的代码
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))
I want to tuning the numbers to LSTM and Dense. 我想将数字调整为LSTM和Dense。
I want to use the for loop to test for the numbers in the code in my comments. 我想使用for循环来测试注释中代码中的数字。
I wonder how it can be implemented. 我不知道该如何实施。
and I wonder if there is a tool that can tune the parameters like this. 我想知道是否有一种工具可以像这样调整参数。
Your valuable opinions and thoughts will be very much appreciated. 您的宝贵意见和想法将不胜感激。
You can build a list with all possible configuration for each parameter in your model you want to tune. 您可以为要调整的模型中的每个参数构建具有所有可能配置的列表。 Something like this:
像这样:
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
]
Now you can do: 现在您可以执行以下操作:
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)
For each possible configuration of your three hyperparameters, test_nn
will be called. 对于您的三个超参数的每种可能的配置,都会调用
test_nn
。 Build and test your network inside that function 在该功能内构建和测试网络
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.