5

I need to run my script named train.py but I also need to set up the flas, by issuing this command in bash:

train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config

However, it catches this error:

File "/Users/cvsanbuenaventura/miniconda3/lib/python3.6/site-packages/google/protobuf/text_format.py", line 1288, in _ConsumeSingleByteString raise self.ParseError('String missing ending quote: %r' % (text,)) google.protobuf.text_format.ParseError: 123:17 : String missing ending quote: '"/Users/cvsanbuenaventura/Documents/tensorflow/models/research/object_detection/train.record“'

So I want to debug in Python Shell or Jupyter Notebook line by line. However I also need to set th train_dir flag. How do I accomplish this?

Chaine
  • 1,368
  • 4
  • 18
  • 37
  • Is it dumplicate with https://stackoverflow.com/questions/32409629/what-is-the-right-way-to-debug-in-ipython-notebook ? – pwxcoo Aug 15 '18 at 03:28
  • @pwxcoo Not really, I just need to know how to set the flags inside the a notebook – Chaine Aug 15 '18 at 03:33

2 Answers2

5

If anyone else has the problem of not being able to add flags to IPython/Jupyter, here's a quick workaround.

# import sys, app and flags
import sys
sys.argv = " --train_dir training/".split(" ")
from absl import app, flags

# add the flags you need:
flags.FLAGS.train_dir = 'training/'

# add the actual code to a function
def main(argvs):
    # the code you want to debug
app.run(main)
Kuzman Belev
  • 61
  • 1
  • 7
-2

According to the documentation you can add flags to your command line arguments with argparse. An example is given below:

parser.add_argument('integers', metavar='N', type=int, nargs='+',
                    help='an integer for the accumulator')
hypadr1v3
  • 543
  • 4
  • 26
  • The question is specifically about jupyterhub /jupyter notebook. – MAltakrori Aug 15 '21 at 16:02
  • This is a very old post. Also, parser does work in Jupyter if you give the args in`parser.parse_args()`. You could do `parser.parse_args(args=[])` if you have no required arguments. More info can be found here: https://stackoverflow.com/questions/45823991/argparse-in-ipython-notebook-unrecognized-arguments-f – hypadr1v3 Aug 17 '21 at 04:21