How to run tensorflow object detection api (model_main_tf2) from code?

0

Issue

I want to run a training with the tensorflow object detection api. In the command line I can use the

python model_main_tf2.py --pipeline_config_path=path/to/pipeline.config --model_dir=path/to/trainedModel

But how can I start it from code?

model_main_tf2.FLAGS.pipeline_config_path = pipeline_config_path
model_main_tf2.FLAGS.model_dir = model_path
tf.compat.v1.app.run(model_main_tf2.main)

This is working, but the tf.compat.v1.app.run() calls the main function by using sys.exit(main). However I do not want, that the system exits.

How can I solve this?

Or maybe, how can I get around the usage of model_main_tf2 and the app.run()?

Solution

Since sys.exit(...) basically raises SystemExit you may just catch the SystemExit:

try:
  tf.compat.v1.app.run(model_main_tf2.main)
except SystemExit:
  pass

# cool stuff happening here!

Answered By – Franz Diebold

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More