簡體   English   中英

如何使用for循環調整進入層的參數?

[英]how to tuning parameter entering the layer using for loop?

這是我的代碼

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循環來測試注釋中代碼中的數字。

我不知道該如何實施。

我想知道是否有一種工具可以像這樣調整參數。

您的寶貴意見和想法將不勝感激。

您可以為要調整的模型中的每個參數構建具有所有可能配置的列表。 像這樣:

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 在該功能內構建和測試網絡

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM