1

I have some tensorflow code that contains tensorflow flags written as below:

from tensorflow.python.platform import flags

FLAGS = flags.FLAGS

## Logging, saving, and testing options
flags.DEFINE_bool('log', True, 'if false, do not log summaries, for debugging code.')
flags.DEFINE_string('logdir', 'trained_mdl/', 'directory for summaries and checkpoints.')
flags.DEFINE_bool('resume', True, 'resume training if there is a model available')
flags.DEFINE_bool('train', False, 'True to train, False to test.')
flags.DEFINE_integer('test_iter', -1, 'iteration to load model (-1 for latest model)')
flags.DEFINE_bool('test_set', True, 'Set to true to test on the the test set, False for the validation set.')
flags.DEFINE_integer('train_update_batch_size', -1, 'number of examples used for gradient update during training (use if you want to test with a different number).')
flags.DEFINE_float('train_update_lr', -1, 'value of inner gradient step step during training. (use if you want to test with a different value)') # 0.1 for omniglot

I want to do several runs, and for that, I wrote a bash script as follows:

#!/usr/bin/env bash

  python main.py
  --meta_batch_size 8
  --train True
  --test_set False

  > main1_train.txt

But it starts over then never executes. Does bash with tensorflow flags do not work at all ? If that then I have no other option that using argparse instead of FLAGS?

Update 1

I am getting the following error:

run_main1.sh: line 5: --meta_batch_size: command not found
run_main1.sh: line 6: --train: command not found
run_main1.sh: line 7: --test_set: command not found
Perl Del Rey
  • 959
  • 1
  • 11
  • 25

1 Answers1

2

Try:

#!/usr/bin/env bash

python main.py \
    --meta_batch_size 8 \
    --train True \
    --test_set False \
    > main1_train.txt

In bash a newline is like pressing the enter button. "--meta_batch_size 8" is seen as a command and is being executed instead. Therefore you have to use \ at the end of the line to make it a parameter to your script.

Bayou
  • 3,293
  • 1
  • 9
  • 22
  • Do you have any idea how to pass the boolean arguments ? The ones in the answer are not taken properly – Perl Del Rey Jan 23 '21 at 10:23
  • I haven't used tensorflow myself. Are you sure you case the incoming string False to a boolean? See [this](https://stackoverflow.com/questions/21732123/convert-true-false-value-read-from-file-to-boolean?lq=1#answer-35412300) – Bayou Jan 24 '21 at 14:54