tensorflow object detection 1.15 to 2.0 --> " RuntimeError: tf.placeholder() is not compatible with eager execution.
Dear,
Recently, i was migrating to tensorflow object detetction API version 2.0 from 1.15.0, Able to train & Evaluate the model. But while creating a frozen model using export_inference_graph.py getting below error-
Traceback (most recent call last): File "export_inference_graph.py", line 206, in
Fixed the Raised issue by disabling eager execution , Now getting new error.
File "export_inference_graph.py", line 206, in
and did some research and come to know contrib module is not supported by tensorflow 2.0. Actually, i am stuck now how can i save my trained object detection model on 2.0 and use it for prediction...Please help...!!!!
Can you solved it? I'm stuck at same point now!
Hi, Can I ask which binary are you using? For tf2, model_main_tf2.py should be used. Thanks!
The error is raised when you run export_inference_graph.py file.
Issue also present in export_tflite_ssd_graph.py/export_tflite_ssd_graph_lib.py
Disabling eager execution in export_tflite_ssd_graph.py results in a similar error:
File "/home/mate/venv/tensorflow2.2/lib/python3.7/site-packages/object_detection/exporter.py", line 145, in rewrite_nn_resize_op
while remove_nn():
File "/home/mate/venv/tensorflow2.2/lib/python3.7/site-packages/object_detection/exporter.py", line 100, in remove_nn
input_pattern = graph_matcher.OpTypePattern(
NameError: name 'graph_matcher' is not defined
placeholder and frozengraph are all TF1 features. In TF2 you should use SavedModel. See exporter_main_v2.py
placeholder and frozengraph are all TF1 features. In TF2 you should use SavedModel. See exporter_main_v2.py
I would like to see this info on this page under guides. https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2.md
I have the same issue with export_inference_graph.py. Model trained usign model_main_tf2.py. When I disable eager execution, the new error is same as the one described by the original author. (NameError: name 'contrib_tfprof' is not defined)
I tried using exporter_main_v2.py , this raises an assertion error.
I also came up with an error after using exporter_main_v2.py. Pls, See the issue on the link.
https://github.com/tensorflow/models/issues/8886#issuecomment-659921958
use exporter_main_v2.py script only, for exporting the models. By default it exports recent checkpoint present in checkpoint_dir. If you want it to export a particular checkpoint then change model_checkpoint_path in checkpoint file.
I have the same issue with export_inference_graph.py. Model trained usign model_main_tf2.py. When I disable eager execution, the new error is same as the one described by the original author. (NameError: name 'contrib_tfprof' is not defined)
I tried using exporter_main_v2.py , this raises an assertion error.
I had same error.
When we export the model we need to specify path of directory of chekpoint not path of chekpoint in trained_checkpoint_dir in tfv2
python .\exporter_main_v2.py --input_type image_tensor --pipeline_config_path .\models\my_efficientdet_d1\pipeline.config --trained_checkpoint_dir .\models\my_efficientdet_d1\ --output_directory .\exported-models\my_model
This still does not give me model in output_directory. I am unable to find reason why ?
i came across the same error when i was using this file but when i use exporter_main_v2.py it seems okay
if only the exporter_main_v2.py should be used with tf2, why are they not making an official statement on their webpage? beside that, does it means it won't be possible to get an inference frozen graph pb file with tensorflow2 anymore? if so how do they get the frozengraph on the model zoo with tf2? did anyone find something on this issue? I'm also stock at the same point with xport_inference_graph.py
The exporter_main_v2 does NOT allow to export frozen graph. The output is always a .pb proto plus a checkpoint. If I want to export a frozen graph which includes all weights and stuff of the recent checkpoint, how should I proceed if export_inference_graph obviously isn't working?
placeholder and frozengraph are all TF1 features. In TF2 you should use SavedModel. See exporter_main_v2.py
On using SavedModel for inference, it also causes an error. Is there a TF2 specific inference script?
On using SavedModel for inference, it also causes an error. Is there a TF2 specific inference script?
I tried this and it works! https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/auto_examples/plot_object_detection_saved_model.html
placeholder and frozengraph are all TF1 features. In TF2 you should use SavedModel. See exporter_main_v2.py
@pkulzc The problem is that currently the TF2 installation for C ++ is far from working, and the OpenCV method readNetFromTensorFlow requires the frozen inference graph and the pbtxt file that TF1 provided. There are a lot of workarounds suggested by many users but no one works, at least for the Mask R-CNN Inception Resnet V2 model. Have you got any suggestion on how to proceed? Do you have any insight about future releases of TensorFlow that will solve these problems?
Did you guys succeeded in solving this problem? I have trained Mask RCNN with TF2 Object Detection API and now i want to do inference with OpenCV method readNetFromTensorFlow. I get both the errors stated above 'RuntimeError: tf.placeholder() is not compatible with eager execution' and after disabling eager execution i get 'NameError: name 'contrib_tfprof' is not defined'. Anyone resolved the issue?
I have trained a custom model with TF2 Object Detection API (using this guide). I would like to obtain the frozen inference graph, i tried running the script export_inference_graph.py but i get the same error as the other users describe:
Traceback (most recent call last):
File "export_inference_graph.py", line 206, in <module>
tf.app.run()
File "anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "anaconda3\envs\tensorflow\lib\site-packages\absl\app.py", line 303, in run
_run_main(main, args)
File "anaconda3\envs\tensorflow\lib\site-packages\absl\app.py", line 251, in _run_main
sys.exit(main(argv))
File "export_inference_graph.py", line 194, in main
exporter.export_inference_graph(
File "anaconda3\envs\tensorflow\lib\site-packages\object_detection\exporter.py", line 611, in export_inference_graph
_export_inference_graph(
File "anaconda3\envs\tensorflow\lib\site-packages\object_detection\exporter.py", line 503, in _export_inference_graph
outputs, placeholder_tensor_dict = build_detection_graph(
File "anaconda3\envs\tensorflow\lib\site-packages\object_detection\exporter.py", line 457, in build_detection_graph
placeholder_tensor, input_tensors = input_placeholder_fn_map[input_type](
File "anaconda3\envs\tensorflow\lib\site-packages\object_detection\exporter.py", line 186, in _image_tensor_input_placeholder
input_tensor = tf.placeholder(
File "anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\array_ops.py", line 3286, in placeholder
raise RuntimeError("tf.placeholder() is not compatible with "
RuntimeError: tf.placeholder() is not compatible with eager execution.
whih this line of code:
tf.compat.v1.disable_eager_execution()
inside that script and now the error was:
Traceback (most recent call last):
File "export_inference_graph.py", line 207, in <module>
tf.app.run()
File "anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "anaconda3\envs\tensorflow\lib\site-packages\absl\app.py", line 303, in run
_run_main(main, args)
File "anaconda3\envs\tensorflow\lib\site-packages\absl\app.py", line 251, in _run_main
sys.exit(main(argv))
File "export_inference_graph.py", line 195, in main
exporter.export_inference_graph(
File "anaconda3\envs\tensorflow\lib\site-packages\object_detection\exporter.py", line 611, in export_inference_graph
_export_inference_graph(
File "anaconda3\envs\tensorflow\lib\site-packages\object_detection\exporter.py", line 514, in _export_inference_graph
profile_inference_graph(tf.get_default_graph())
File "anaconda3\envs\tensorflow\lib\site-packages\object_detection\exporter.py", line 642, in profile_inference_graph
contrib_tfprof.model_analyzer.TRAINABLE_VARS_PARAMS_STAT_OPTIONS)
NameError: name 'contrib_tfprof' is not defined