首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用for循环调整进入层的参数?

如何使用for循环调整进入层的参数?
EN

Stack Overflow用户
提问于 2019-08-03 15:55:21
回答 1查看 87关注 0票数 0

以下是我的代码

代码语言:javascript
运行
复制
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循环来测试我的注释中代码中的数字。

我想知道它是如何实现的。

我想知道是否有工具可以像这样调整参数。

我们将非常感谢您的宝贵意见和想法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-03 18:35:45

您可以为模型中要调优的每个参数构建一个列表,其中包含所有可能的配置。如下所示:

代码语言:javascript
运行
复制
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
]

现在您可以执行以下操作:

代码语言:javascript
运行
复制
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。在该函数内部构建和测试网络

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57336527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档