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



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

python --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

This is working, but the 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


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

except SystemExit:

# 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