1

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)?

orome
  • 45,163
  • 57
  • 202
  • 418

1 Answers1

3

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.

fabrizioM
  • 46,639
  • 15
  • 102
  • 119
  • What about "nested" (see question)? – orome May 18 '16 at 17:12
  • 1
    for nested I would suggest to just pass a string and then `eval` the string in python. – fabrizioM May 18 '16 at 17:27
  • 1
    Any idea where the documentation for this has gone? I'm having trouble finding any (e.g, to set defaults, valid values, short names, required flags). The link above is dead. – orome Jun 04 '16 at 13:53