1

Hi I am running through the /models-master/tutorials/image/cifar10 examples provided by google at https://github.com/tensorflow/models.

I am running the tensorflow-1.0.1 and python 3.5 in a virtual env.

From the command line, and in the virtualenv, running: python3 cifar10_train.py Works fine.

But when I try: pudb3 cifar10_train.py

I get this error:

Traceback (most recent call last):
File "~/interpreters/p35/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
TypeError: main() takes 0 positional arguments but 1 was given

Checking the args gives:

print (_sys.argv[:1])
['cifar10_train.py']
print (flags_passthrough)
[ ]

I know pudb is in the same virtualenv that runs the code from the command line, as pudb goes through the tensorflow import fine, and the virtualenv is the only location in which the tensorflow package resides.

I am assuming this is some issue with passing between some layer pudb introduces... does anyone have a quick suggestion for getting through this... I just want to step through the code :)

Thanks,

nt

alphaXed
  • 21
  • 3
  • Also, adding a print statement to cifar10_train.py and running it (succesfully) again from the command line shows that main is getting the same args as in pudb. – alphaXed Apr 11 '17 at 15:28

3 Answers3

0

I've encountered this same problem when using pudb and TensorFlow. It has to do with the tf.flags. I just use python's Argparse class and not tf.flags.

As an alternative, I believe you can leave the tf.flags as is and just add from pudb import set_trace; set_trace() in your code after the tensorflow import. Call your script as python script.py wihtout -m pudb and it shouldn't freak out.

vega
  • 2,150
  • 15
  • 21
0

vega's suggestions worked... thanks. I'd rate up your comment but I've got a rep of <15... what else is new :)

So as per vega...

Included "from pudb import set_trace" after the "import tensorflow as tf" statement. Then added set_trace() as follows...

def main(argv=None):  # pylint: disable=unused-argument
  cifar10.maybe_download_and_extract()
  if tf.gfile.Exists(FLAGS.train_dir):
    tf.gfile.DeleteRecursively(FLAGS.train_dir)
  tf.gfile.MakeDirs(FLAGS.train_dir)
  train()


if __name__ == '__main__':
  set_trace()    
  tf.app.run()

Called the script from the command line: python3 cifar10_train.py

And it worked as desired.

PuDB looks like its going to be a great tool.

alphaXed
  • 21
  • 3
0

It seems that tensorflow is calling the wrong main function.I had a similar problem when using cProfile and calling script with

python -m cProfile train.py

Seems like the problem was that tf.app.run called main inside cProfile which wasn't ready for argument passing. In my case the solution was to specify main in tf.app.run():

tf.app.run(main=main)

Also fake argument in main is neeeded def main(_):.

vozman
  • 1,198
  • 1
  • 14
  • 19