tensorflow-onnx icon indicating copy to clipboard operation
tensorflow-onnx copied to clipboard

Segmentation fault core dump when converting tflite model to onnx

Open Jerryzhangzhao opened this issue 3 years ago • 3 comments

Describe the bug I am converting a tflite model to onnx with tf2onnx, but it causecore dump. The model is pose_detection.tflite, model link

System information

  • OS Platform and Distribution: Linux Ubuntu 20.04
  • Tensorflow Version: 2.6.0
  • Python version: 3.7.0
  • onnx version: 1.10.1
  • tf2onnx version: 1.10.0/425d8 (installed with pip install git+https://github.com/onnx/tensorflow-onnx)
  • venv: anaconda3

I've also tried on windows10, with anaconda env, the same error.

To Reproduce with the command line: python -m tf2onnx.convert --tflite ./pose_detection.tflite --output pose_detection.onnx

Screenshots If applicable, add screenshots to help explain your problem. image The chinese character in above image is "Segmentation fault (core dumped)"

Additional context The model is about human detection. model link

Jerryzhangzhao avatar Oct 19 '21 03:10 Jerryzhangzhao

The model has the "densify" op which I haven't seen before. Seems to crash while trying to extract tensor data from tflite interpreter.

image

TomWildenhain-Microsoft avatar Oct 19 '21 19:10 TomWildenhain-Microsoft

@TomWildenhain-Microsoft Thanks. I've convert the tflite model to saved_model format with tflite2tensorflow which support Densify op, and then convert the .pb file to onnx format. Is there a plan to support the Densify op in near future?

Jerryzhangzhao avatar Oct 20 '21 02:10 Jerryzhangzhao

Hi @TomWildenhain-Microsoft, based on the result of my debugging, this repro code is crashed by this line. https://github.com/onnx/tensorflow-onnx/blob/a1a9343cef193ef45b7f91d511e9c7bd1dffb3e3/tf2onnx/tflite_utils.py#L200 Cause the _get_tensor_details() function will catch the TensorSparsityParameters of tflite interpreter. While TensorSparsityParameters is missing in one of the tensor.

    tensor_sparsity_params = self._interpreter.TensorSparsityParameters(tensor_index)

However, we don't use the tensor_sparsity_params in details. If I remove the above line in _get_tensor_details() function. There will get the shape error.

cannot reshape array of size 96 into shape (16,1,1,24)

Do you have any idea about this case?

hwangdeyu avatar Nov 22 '21 12:11 hwangdeyu