【问题标题】:How do I pass a nested list of integers to Google's command line flags?如何将嵌套的整数列表传递给 Google 的命令行标志?
【发布时间】:2016-09-15 07:09:21
【问题描述】:

如何将嵌套的整数列表传递给gflags?我可以让我的代码使用类似的东西

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_float('network_nodes', [784, [5, 5, 32], [5, 5, 64], 1200, 10], 'The network structure')

但尝试在命令行中使用类似

python test.py --network_nodes=[784, 100, 10]

导致(不足为奇)错误:

test.py: error: argument --network_nodes: invalid int value: '[784, 100, 10]'

如何将嵌套的整数列表传递给gflags(或TensofFlow 的tf.app.flags)?

【问题讨论】:

    标签: python command-line parameter-passing tensorflow gflags


    【解决方案1】:

    来自文档:https://github.com/gflags/python-gflags/blob/master/gflags.py

    DEFINE_list: Takes a comma-separated list of strings on the commandline.
             Stores them in a python list object.
    

    因此,您必须将其作为字符串列表传递--network_nodes=784,100,10,然后将字符串转换为浮点数。

    【讨论】:

    • “嵌套”怎么样(见问题)?
    • 对于嵌套,我建议只传递一个字符串,然后 eval python 中的字符串。
    • 知道这方面的文档去哪儿了吗?我找不到任何东西(例如,设置默认值、有效值、短名称、所需标志)。上面的链接失效了。
    猜你喜欢
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 2011-11-24
    相关资源
    最近更新 更多