深度学习调参-超参数排列组合

2020-02-22  本文已影响0人  洗洗睡吧i

ref: https://docs.python.org/3/library/itertools.html#itertools.product

import itertools
import subprocess

# === define paras ==================
para_names = ['layer_n', 'activition', 'seed']

layer_n = [1, 2, 3, 4, 5, 6]
activition = ['tanh', 'sigmod', 'relu']
seed = [11, 17, 19]

# calc cases number
i = 1
nums = sum(1 for _ in itertools.product(layer_n, activition, seed))
print(f'==== we have {nums} cases in total', '===' * 3)

# === run all case ===========
for values in itertools.product(layer_n, activition, seed):
    print(f' *** {i} / {nums} ', '***' * 3)
    
    cmd = f'python mnist_cnn.py'
    for p, v in zip(para_names, values):
        cmd += f' --{p}={v}'
    print(cmd)
    
    # p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    # print(p.stdout.read().decode('utf8'))
    
    i += 1
    
    

输出:

==== we have 54 cases in total =========
 *** 1 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=tanh --seed=11
 *** 2 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=tanh --seed=17
 *** 3 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=tanh --seed=19
 *** 4 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=sigmod --seed=11
 *** 5 / 54  *********
python mnist_cnn.py --layer_n=1 --activition=sigmod --seed=17
 *** 6 / 54  *********
 
 ...

 *** 53 / 54  *********
python mnist_cnn.py --layer_n=6 --activition=relu --seed=17
 *** 54 / 54  *********
python mnist_cnn.py --layer_n=6 --activition=relu --seed=19
上一篇 下一篇

猜你喜欢

热点阅读