models icon indicating copy to clipboard operation
models copied to clipboard

tensorflow object detection 1.15 to 2.0 --> " RuntimeError: tf.placeholder() is not compatible with eager execution.

Open anmol101093AIML opened this issue 6 years ago • 31 comments

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 tf.app.run() File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 299, in run _run_main(main, args) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "export_inference_graph.py", line 202, in main side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 625, in export_inference_graph side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 512, in _export_inference_graph side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 458, in build_detection_graph **placeholder_args) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 187, in _image_tensor_input_placeholder dtype=tf.uint8, shape=input_shape, name='image_tensor') File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py", line 3023, in placeholder raise Traceback (most recent call last): File "export_inference_graph.py", line 206, in tf.app.run() File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 299, in run _run_main(main, args) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "export_inference_graph.py", line 202, in main side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 625, in export_inference_graph side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 512, in _export_inference_graph side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 458, in build_detection_graph **placeholder_args) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 187, in _image_tensor_input_placeholder dtype=tf.uint8, shape=input_shape, name='image_tensor') File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py", line 3023, in placeholder raise RuntimeError("tf.placeholder() is not compatible with " RuntimeError: tf.placeholder() is not compatible with eager execution.

anmol101093AIML avatar Jul 12 '20 05:07 anmol101093AIML

Fixed the Raised issue by disabling eager execution , Now getting new error.

File "export_inference_graph.py", line 206, in tf.app.run() File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 299, in run _run_main(main, args) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "export_inference_graph.py", line 202, in main side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 625, in export_inference_graph side_input_types=side_input_types) File "/usr/local/lib/python3.6/dist-packages/object_detection/exporter.py", line 514, in _export_inference_graph profile_inference_graph(tf.get_default_graph()) File "/usr/local/lib/python3.6/dist-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

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...!!!!

anmol101093AIML avatar Jul 12 '20 06:07 anmol101093AIML

Can you solved it? I'm stuck at same point now!

MaxiLibrandi avatar Jul 12 '20 23:07 MaxiLibrandi

Hi, Can I ask which binary are you using? For tf2, model_main_tf2.py should be used. Thanks!

syiming avatar Jul 13 '20 10:07 syiming

The error is raised when you run export_inference_graph.py file.

MaxiLibrandi avatar Jul 13 '20 12:07 MaxiLibrandi

Issue also present in export_tflite_ssd_graph.py/export_tflite_ssd_graph_lib.py

03vmate avatar Jul 14 '20 01:07 03vmate

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

03vmate avatar Jul 14 '20 12:07 03vmate

placeholder and frozengraph are all TF1 features. In TF2 you should use SavedModel. See exporter_main_v2.py

pkulzc avatar Jul 14 '20 23:07 pkulzc

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

hasansalimkanmaz avatar Jul 17 '20 08:07 hasansalimkanmaz

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.

Dhivya-rav avatar Jul 17 '20 09:07 Dhivya-rav

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

hasansalimkanmaz avatar Jul 17 '20 09:07 hasansalimkanmaz

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.

change2014 avatar Sep 04 '20 06:09 change2014

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 ?

vis7 avatar Sep 18 '20 13:09 vis7

i came across the same error when i was using this file but when i use exporter_main_v2.py it seems okay

aLLLiyyy avatar Oct 18 '20 15:10 aLLLiyyy

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

savadortades avatar Dec 08 '20 03:12 savadortades

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?

MattVoge avatar Jan 06 '21 10:01 MattVoge

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?

devloper13 avatar Jan 12 '21 11:01 devloper13

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

shamilam avatar Jan 13 '21 08:01 shamilam

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?

JJonahJson avatar Feb 03 '21 13:02 JJonahJson

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?

AI-P-K avatar Jul 09 '21 10:07 AI-P-K

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

diego200052 avatar Dec 29 '21 23:12 diego200052