pythoncommand-lineparameter-passingtensorflowgflags

How do I pass a nested list of integers to Google's command line flags?


How do I pass a nested list of integers to gflags? I can get my code working with something like

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

But attempting to use this at the command line with something like

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

results (not surprisingly) in an error:

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

How do I pass a nested list of integers to gflags (or TensofFlow's tf.app.flags)?


Solution

  • From the documentation: 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.
    

    So you would have to pass it as a list of string --network_nodes=784,100,10 and then convert the strings to floats.