System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS Mojave, version 10.14.2
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
- TensorFlow installed from (source or binary): binary
- TensorFlow version (use command below): 1.12.0
- Python version: 3.6.6
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version: N/A
- GPU model and memory: N/A
- Exact command to reproduce:
Describe the problem
I have a custom model pre-trained in Pytorch framework. I have converted it to ONNX model, and then to TensorFlow model, so that it can be further converted to TensorFlow Lite model for deployment on mobile devices.
I used the tflite_convert command for the conversion,
tflite_convert
--graph_def_file=model.pb
--output_file=model.lite
--input_format=TENSORFLOW_GRAPH
--output_format=TFLITE
--input_arrays=0
--output_arrays=add_51 \
Yet I got the following error message:
Traceback (most recent call last):
File "/miniconda3/bin/tflite_convert", line 11, in
sys.exit(main())
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 412, in main app.run(main=run_main, argv=sys.argv[:1])
File "/miniconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 408, in run_main _convert_model(tflite_flags)
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 162, in _convert_model output_data = converter.convert()
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/lite.py", line 453, in convert **converter_kwargs)
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 342, in toco_convert_impl input_data.SerializeToString())
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 135, in toco_convert_protos(stdout, stderr))
RuntimeError: TOCO failed see console for info.
b"2018-12-20 17:44:31.127219: F tensorflow/contrib/lite/toco/import_tensorflow.cc:2137] Check failed: status.ok() Unexpected value for attribute 'data_format'. Expected 'NHWC'\n"
None
The custom pre-trained model is adapted from a Pytorch ResNet model. Therefore I also evaluated converting the ResNet model from the torchvision package to TensorFlow model through the ONNX framework, and further to TensorFlow Lite model. And I got the following error message:
Converting unsupported operation: PyFunc\n2018-12-20 18:09:03.357810: F tensorflow/contrib/lite/toco/import_tensorflow.cc:112] Check failed: attr.value_case() == AttrValue::kType (1 vs. 6)\n'
None
I wonder if the errors above were due to some unsupported operators from the model, probably caused from converting Pytorch model to TensorFlow model through the ONNX framework. As I can convert the pre-trained Mobilenet model (https://www.tensorflow.org/lite/models) to tflite model without error on my platform. Thanks.
System information
Describe the problem
I have a custom model pre-trained in Pytorch framework. I have converted it to ONNX model, and then to TensorFlow model, so that it can be further converted to TensorFlow Lite model for deployment on mobile devices.
I used the tflite_convert command for the conversion,
tflite_convert
--graph_def_file=model.pb
--output_file=model.lite
--input_format=TENSORFLOW_GRAPH
--output_format=TFLITE
--input_arrays=0
--output_arrays=add_51 \
Yet I got the following error message:
Traceback (most recent call last):
File "/miniconda3/bin/tflite_convert", line 11, in
sys.exit(main())
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 412, in main app.run(main=run_main, argv=sys.argv[:1])
File "/miniconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 408, in run_main _convert_model(tflite_flags)
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 162, in _convert_model output_data = converter.convert()
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/lite.py", line 453, in convert **converter_kwargs)
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 342, in toco_convert_impl input_data.SerializeToString())
File "/miniconda3/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 135, in toco_convert_protos(stdout, stderr))
RuntimeError: TOCO failed see console for info.
b"2018-12-20 17:44:31.127219: F tensorflow/contrib/lite/toco/import_tensorflow.cc:2137] Check failed: status.ok() Unexpected value for attribute 'data_format'. Expected 'NHWC'\n"
None
The custom pre-trained model is adapted from a Pytorch ResNet model. Therefore I also evaluated converting the ResNet model from the torchvision package to TensorFlow model through the ONNX framework, and further to TensorFlow Lite model. And I got the following error message:
Converting unsupported operation: PyFunc\n2018-12-20 18:09:03.357810: F tensorflow/contrib/lite/toco/import_tensorflow.cc:112] Check failed: attr.value_case() == AttrValue::kType (1 vs. 6)\n'
None
I wonder if the errors above were due to some unsupported operators from the model, probably caused from converting Pytorch model to TensorFlow model through the ONNX framework. As I can convert the pre-trained Mobilenet model (https://www.tensorflow.org/lite/models) to tflite model without error on my platform. Thanks.