Please answer the following questions for yourself before submitting an issue.
Traceback (most recent call last):
File "C:\models\research\object_detection\export_tflite_ssd_graph.py", line 146, in <module>
tf.app.run(main)
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "C:\models\research\object_detection\export_tflite_ssd_graph.py", line 139, in main
export_tflite_ssd_graph_lib.export_tflite_graph(
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\object_detection\export_tflite_ssd_graph_lib.py", line 282, in export_tflite_graph
exporter.rewrite_nn_resize_op(is_quantized)
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\object_detection\exporter.py", line 145, in rewrite_nn_resize_op
while remove_nn():
File "C:\Users\me\AppData\Roaming\Python\Python38\site-packages\object_detection\exporter.py", line 100, in remove_nn
input_pattern = graph_matcher.OpTypePattern(
NameError: name 'graph_matcher' is not defined
3. Steps to reproduce
I am using model_main_tf2.py
to train my model and then I use exporter_main_v2
to convert the ckpt files to a saved model from which I then use export_tflite_ssd_graph.py
and then would use tflite_convert.exe
(if the bug were not there).
4. Expected behavior
The expected behavior is that it should run both python files without getting an error. Since export_tflite_ssd_graph.py
gives an error of NameError: name 'graph_matcher' is not defined
, I cannot use tflite_convert.exe
because the first file didn't execute without errors
6. System information
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
Mobile device name if the issue happens on a mobile device: None
TensorFlow installed from (source or binary): binary
TensorFlow version (use command below): 2.3.0
Python version: 3.8
Bazel version (if compiling from source): None
GCC/Compiler version (if compiling from source): None
CUDA/cuDNN version: None
GPU model and memory: No GPU
I have tried using tf-nightly, but that does not work because when I try running on an Android phone, it gives an error:
java.lang.IllegalArgumentException: ByteBuffer is not a valid flatbuffer model
changed the title
TFLiteConverter (Saved Model -> TFLite) requires all operands and results to have compatible element types
TFLiteConverter (Saved Model -> TFLite) NameError: name 'graph_matcher' is not defined
Aug 31, 2020
@ravikyram
Thanks for the reply. To train the model, I am using model_main_tf2.py
, but to convert I am using exporter_main_v2.py
as @pkulzc had commented. Once it has outputted in the output directory, I then would use export_tflite_ssd_graph.py
and then tflite_convert.exe
to convert to tflite, but the NameError: name 'graph_matcher' is not defined
error happens when using export_tflite_ssd_graph.py
.
Here is how I am doing these:
For training, I have a batch file which includes:
set PIPELINE_CONFIG="path to my\pipeline.config"
set MODEL_DIR="path to my\saved_model"
set TFOD_API="C:\models\research\object_detection"
python %TFOD_API%\model_main_tf2.py ^
--pipeline_config_path=%PIPELINE_CONFIG% ^
--model_dir=%MODEL_DIR% ^
--alsologtostderr
For creating the Saved Model, I use another batch file which has:
set NETWORK_DIR=directory to the main folder
set PIPELINE_CONFIG=%NETWORK_DIR%\pipeline.config
set MODEL_DIR=%NETWORK_DIR%\saved_model
set INFERENCE_GRAPH_DIR=%NETWORK_DIR%\output_saved_model
set TFOD_API="C:\models\research\object_detection"
set INPUT_TYPE=image_tensor
if exist %INFERENCE_GRAPH_DIR% rmdir %INFERENCE_GRAPH_DIR% /Q /S
python %TFOD_API%\exporter_main_v2.py ^
--input_type=%INPUT_TYPE% ^
--pipeline_config_path=%PIPELINE_CONFIG% ^
--trained_checkpoint_dir=%MODEL_DIR% ^
--output_directory=%INFERENCE_GRAPH_DIR%
copy train_data\label.pbtxt %INFERENCE_GRAPH_DIR% /Y
For converting to TFLite, this is the other batch file:
set NETWORK_DIR=directory to the main folder
set PIPELINE_CONFIG=%NETWORK_DIR%\pipeline.config
set MODEL_DIR=%NETWORK_DIR%\saved_model
set INFERENCE_GRAPH_DIR=%NETWORK_DIR%\tflite
set TFOD_API="C:\models\research\object_detection"
set INPUT_TYPE=image_tensor
set MODEL_PREFIX=ckpt-6
if exist %INFERENCE_GRAPH_DIR% rmdir %INFERENCE_GRAPH_DIR% /Q /S
python %TFOD_API%\export_tflite_ssd_graph.py ^
--pipeline_config_path=%PIPELINE_CONFIG% ^
--trained_checkpoint_prefix=%MODEL_DIR%\%MODEL_PREFIX% ^
--output_directory=%INFERENCE_GRAPH_DIR% ^
--add_postprocessing_op=true
tflite_convert.exe ^
--saved_model_dir=%INFERENCE_GRAPH_DIR% ^
--output_file=%INFERENCE_GRAPH_DIR%\detect.tflite ^
--input_shapes=1,300,300,3 ^
--input_arrays=normalized_input_image_tensor ^
--output_arrays="TFLite_Detection_PostProcess","TFLite_Detection_PostProcess:1","TFLite_Detection_PostProcess:2","TFLite_Detection_PostProcess:3" ^
--inference_type=QUANTIZED_UINT8 ^
--mean_values=128 ^
--std_dev_values=128 ^
--change_concat_input_ranges=false ^
--allow_custom_ops
copy train_data\label.pbtxt %INFERENCE_GRAPH_DIR% /Y
Please let me know if any of these are causing the issue. Thanks!
Please let us know if you have any solutions.
Python version 3.8
File "/home/gowtham/Desktop/localtests/livellotrain/models/research/object_detection/export_tflite_ssd_graph.py", line 146, in
tf.app.run(main)
File "/home/gowtham/.local/lib/python3.8/site-packages/tensorflow/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/home/gowtham/.local/lib/python3.8/site-packages/absl/app.py", line 300, in run
_run_main(main, args)
File "/home/gowtham/.local/lib/python3.8/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "/home/gowtham/Desktop/localtests/livellotrain/models/research/object_detection/export_tflite_ssd_graph.py", line 139, in main
export_tflite_ssd_graph_lib.export_tflite_graph(
File "/usr/local/lib/python3.8/dist-packages/object_detection-0.1-py3.8.egg/object_detection/export_tflite_ssd_graph_lib.py", line 282, in export_tflite_graph
exporter.rewrite_nn_resize_op(is_quantized)
File "/usr/local/lib/python3.8/dist-packages/object_detection-0.1-py3.8.egg/object_detection/exporter.py", line 145, in rewrite_nn_resize_op
while remove_nn():
File "/usr/local/lib/python3.8/dist-packages/object_detection-0.1-py3.8.egg/object_detection/exporter.py", line 100, in remove_nn
input_pattern = graph_matcher.OpTypePattern(
NameError: name 'graph_matcher' is not defined