Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does tf.app.flags do? why we need that? [duplicate]

I'm reading the tensorflow tutorial file fully_connected_feed.py which contains the following code. I do not understand what those mean. Why do we need that? It seems that it's just defining some global variables. Why not just define those directly? Any help is appreciated. thanks

flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
flags.DEFINE_integer('max_steps', 2000, 'Number of steps to run trainer.')
flags.DEFINE_integer('hidden1', 128, 'Number of units in hidden layer 1.')
flags.DEFINE_integer('hidden2', 32, 'Number of units in hidden layer 2.')
flags.DEFINE_integer('batch_size', 100, 'Batch size.  '
                     'Must divide evenly into the dataset sizes.')
flags.DEFINE_string('train_dir', 'data', 'Directory to put the training data.')
flags.DEFINE_boolean('fake_data', False, 'If true, uses fake data '
                     'for unit testing.')
like image 873
zesla Avatar asked Jun 15 '16 20:06

zesla


1 Answers

This is google's way for parsing arguments from the commandline. Have a look at python-gflags. As far as I'm aware, google is the primary user of this commandline parsing library. The rest of the world uses argparse these days.

But basically, the "tl;dr;" is that you're right -- They are setting up global data. However, it's global data that can be fiddled with via the commandline.

like image 104
mgilson Avatar answered Sep 22 '22 16:09

mgilson