简体   繁体   English

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

[英]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.

相关问题 如何在 Python 中使用 StratifiedKFold 在 LogisticRegression 中进行参数调整? - How to do parameter tuning in LogisticRegression using StratifiedKFold in Python? 使用 AI Platform 超参数调优功能时如何强制参数依赖? - How to force parameter dependency when using AI Platform hyper parameter tuning capability? 多层感知机如何进行超参数调优? - How to carry out hyperparamter Tuning for Multi-layer Perceptron? 微调FC层如何选择感知器数量? - How to choose number of perceptron in fine-tuning FC layer? 使用 GridSearchCV 进行神经网络的超参数调优 - Hyper-parameter Tuning Using GridSearchCV for Neural Network 使用分区基准数据集进行机器学习参数调整 - Machine learning parameter tuning using partitioned benchmark dataset 如何使用for循环创建Keras多LSTM层? - how to create Keras multi LSTM layer using for loop? 如何防止哨兵值进入循环 - How to keep sentinel value from entering loop 如何对庞大的数据集进行交叉验证和超参数调整? - how to do cross validation and hyper parameter tuning for huge dataset? 如何使用Sklearn的管道进行参数调整/交叉验证? - How do to parameter tuning/cross-validation with Sklearn's pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM