Skip to content

Cannot convert ssd_mobilenetv2_oidv4 to the format of tflite #8148

@stereomatchingkiss

Description

@stereomatchingkiss

I want to convert the ssd_mobilenetv2_oidv4 to the format which could be read by the tflite library, I follow instructions at here and able to create the frozen graph, but when I try to optimize the model by toco, error happen

System information

  • What is the top-level directory of the model you are using: ssd_mobilenetv2_oidv4
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04 64bits
  • TensorFlow installed from (source or binary): Installed from source, v1.15.0, cpu only
  • TensorFlow version (use command below): v1.15.0
  • Bazel version (if compiling from source): 0.26.1
  • CUDA/cuDNN version: None, cpu only
  • GPU model and memory: 16GB of ram(not ram of gpu)
  • Exact command to reproduce:
bazel run --config=opt tensorflow/lite/toco:toco -- \
--input_file=$OUTPUT_DIR/tflite_graph.pb \
--output_file=$OUTPUT_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=FLOAT \
--allow_custom_ops

This will trigger error messages

INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=110
INFO: Reading rc options for 'run' from /home/yyyy/Qt/3rdLibs/tensorflow/.bazelrc:
  Inherited 'build' options: --apple_platform_type=macos --define framework_shared_object=true --define open_source_build=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone --strategy=Genrule=standalone -c opt --announce_rc --define=grpc_no_ares=true --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include
INFO: Reading rc options for 'run' from /home/yyyy/Qt/3rdLibs/tensorflow/.tf_configure.bazelrc:
  Inherited 'build' options: --action_env PYTHON_BIN_PATH=/home/yyyy/anaconda3/envs/tensorflow_lite/bin/python --action_env PYTHON_LIB_PATH=/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages --python_path=/home/yyyy/anaconda3/envs/tensorflow_lite/bin/python --action_env ANDROID_NDK_HOME=/home/yyyy/Android/Sdk/ndk/17.2.4988734 --action_env ANDROID_NDK_API_LEVEL=24 --action_env ANDROID_BUILD_TOOLS_VERSION=29.0.3 --action_env ANDROID_SDK_API_LEVEL=29 --action_env ANDROID_SDK_HOME=/home/yyyy/Android/Sdk --action_env TF_CONFIGURE_IOS=0
INFO: Found applicable config definition build:opt in file /home/yyyy/Qt/3rdLibs/tensorflow/.tf_configure.bazelrc: --copt=-march=native --copt=-Wno-sign-compare --host_copt=-march=native --define with_default_optimizations=true
ERROR: Skipping 'tensorflow/lite/toco:toco': no such package 'tensorflow/tensorflow/lite/toco': BUILD file not found on package path
WARNING: Target pattern parsing failed.
ERROR: no such package 'tensorflow/tensorflow/lite/toco': BUILD file not found on package path
INFO: Elapsed time: 0.138s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)

I try to convert the model by python script.

import tensorflow as tf

graph_def_file = "tflite_graph.pb"
input_arrays = ["normalized_input_image_tensor"]
output_arrays = ["'TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3'"]

converter = tf.lite.TFLiteConverter.from_frozen_graph(
        graph_def_file, input_arrays, output_arrays, {"normalized_input_image_tensor": [1, 300, 300, 3]})

converter.allow_custom_ops = True
converter.experimental_new_converter = True

tflite_model = converter.convert()
open("detect.tflite", "wb").write(tflite_model)

This give me error messages

Traceback (most recent call last):
  File "converter.py", line 13, in <module>
    tflite_model = converter.convert()
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/tensorflow_core/lite/python/lite.py", line 989, in convert
    **converter_kwargs)
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/tensorflow_core/lite/python/convert.py", line 412, in toco_convert_graph_def
    enable_mlir_converter=enable_mlir_converter)
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/tensorflow_core/lite/python/convert.py", line 200, in toco_convert_protos
    raise ConverterError("See console for info.\n%s\n%s\n" % (stdout, stderr))
tensorflow.lite.python.convert.ConverterError: See console for info.
2020-02-18 15:03:59.977666: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TFLite_Detection_PostProcess
2020-02-18 15:03:59.989573: F tensorflow/lite/toco/tooling_util.cc:935] Check failed: GetOpWithOutput(model, output_array) Specified output array "'TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3'" is not produced by any op in this graph. Is it a typo? This should not happen. If you trigger this error please send a bug report (with code to reporduce this error), to the TensorFlow Lite team.
Fatal Python error: Aborted

Current thread 0x00007f56003fa740 (most recent call first):
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 52 in execute
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/absl/app.py", line 250 in _run_main
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/absl/app.py", line 299 in run
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/tensorflow_core/python/platform/app.py", line 40 in run
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/lib/python3.6/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 89 in main
  File "/home/yyyy/anaconda3/envs/tensorflow_lite/bin/toco_from_protos", line 8 in <module>
Aborted (core dumped)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions