tensorflow: TensorFlow Lite Conversion Fails (Check failed: start_indices_size <= num_input_axes (2 vs. 1)StridedSlice op requires no more than 1 start indices)

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux CentOS 7.5
  • TensorFlow installed from (source or binary): Tensorflow is preinstalled on the server.
  • TensorFlow version (or github SHA if from source): Tensorflow/2.0.0

Command used to run the converter or code if you’re using the Python API

import tensorflow as tf
# Note: full quantization requires tf 1.15 or higher
import numpy as np
from PIL import Image

def representative_dataset_gen():
  data = np.random.rand(100,416,416,3).astype(dtype=np.float32)
  for i in range(num_calibration_steps):
    # Get sample input data as a numpy array in a method of your choosing.
    # image, = data.take(1)
    image = np.expand_dims(data[i,:,:,:], axis=0)
    yield [image]

num_calibration_steps = 100
saved_model_dir = '/projectnb/ec720prj/nakamura/Spring2020/tf2-yolov3/savedmodel/yolov3/1' # dir of YOLOv3 tf implementation

converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
# converter.representative_dataset = tf.lite.RepresentativeDataset(representative_dataset_gen)
converter.representative_dataset = representative_dataset_gen

# Enforce full integer quantization for all ops and use int input/output
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8

tflite_quant_model = converter.convert()
open("./converted_model.tflite", "wb").write(tflite_quant_model)

The output from the converter invocation

2020-02-06 10:53:25.407210: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations:  AVX AVX2 FMA
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.
2020-02-06 10:53:25.425952: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2394310000 Hz
2020-02-06 10:53:25.427429: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0xce6d420 executing computations on platform Host. Devices:
2020-02-06 10:53:25.427467: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
2020-02-06 10:53:25.436305: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 28. Tune using inter_op_parallelism_threads for best performance.
2020-02-06 10:53:42.002931: I tensorflow/core/grappler/devices.cc:60] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA support)
2020-02-06 10:53:42.003093: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2020-02-06 10:53:42.111911: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:716] Optimization results for grappler item: graph_to_optimize
2020-02-06 10:53:42.111960: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   function_optimizer: Graph size after: 2070 nodes (1696), 5733 edges (5354), time = 66.938ms.
2020-02-06 10:53:42.111973: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   function_optimizer: function_optimizer did nothing. time = 1.093ms.
2020-02-06 10:53:48.038844: I tensorflow/core/grappler/devices.cc:60] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA support)
2020-02-06 10:53:48.038997: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2020-02-06 10:53:49.980217: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:716] Optimization results for grappler item: graph_to_optimize
2020-02-06 10:53:49.980262: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   constant folding: Graph size after: 1268 nodes (-370), 4423 edges (-734), time = 922.534ms.
2020-02-06 10:53:49.980274: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:718]   constant folding: Graph size after: 1268 nodes (0), 4423 edges (0), time = 255.534ms.
Traceback (most recent call last):
  File "coral/coral_quantizer.py", line 38, in <module>
    tflite_quant_model = converter.convert()
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../python3.6/site-packages/tensorflow_core/lite/python/lite.py", line 446, in convert
    **converter_kwargs)
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../python3.6/site-packages/tensorflow_core/lite/python/convert.py", line 449, in toco_convert_impl
    enable_mlir_converter=enable_mlir_converter)
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../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-06 10:54:00.060634: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 676 operators, 1271 arrays (0 quantized)
2020-02-06 10:54:00.077126: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 676 operators, 1271 arrays (0 quantized)
2020-02-06 10:54:00.465306: F tensorflow/lite/toco/graph_transformations/resolve_strided_slice_attributes.cc:95] Check failed: start_indices_size <= num_input_axes (2 vs. 1)StridedSlice op requires no more than 1 start indices
Fatal Python error: Aborted

Current thread 0x00007fbbde05b740 (most recent call first):
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../python3.6/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 52 in execute
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../python3.6/site-packages/absl/app.py", line 250 in _run_main
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../python3.6/site-packages/absl/app.py", line 299 in run
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../python3.6/site-packages/tensorflow_core/python/platform/app.py", line 40 in run
  File "/share/pkg.7/tensorflow/2.0.0/install/lib/SCC/../python3.6/site-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 89 in main
  File "/share/pkg.7/tensorflow/2.0.0/install/bin/toco_from_protos", line 10 in <module>

Also, please include a link to the saved model or GraphDef

# Put link here or attach to the issue.
https://drive.google.com/a/bu.edu/file/d/1STaqguXrsKaqNbzxmvGVwzpwWZEiC4K6/view?usp=sharing

Failure details Hello, I am trying to run the full YOLOv3 on Coral EdgeTPU. To do this, I am currently trying to convert the savedmodel (.pb format) of trained yolov3 into the quantized .tflite model using the code I attached above. For some reason, the conversion failed with this error:

Check failed: start_indices_size <= num_input_axes (2 vs. 1)StridedSlice op requires no more than 1 start indices
Fatal Python error: Aborted)

I was able to convert the official pretrained MobileNetv1 savedmodel file into the quantized .tflite model using the exact same code.

I am using this repo (https://github.com/YunYang1994/TensorFlow2.0-Examples/tree/master/4-Object_Detection/YOLOV3) for the YOLOv3 Tensorflow 2.0.0 implementation.

Do you know what is causing this failure of conversion? Thank you.

Any other info / logs

Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

YOLOv3’s implementation code => (https://github.com/YunYang1994/TensorFlow2.0-Examples/tree/master/4-Object_Detection/YOLOV3)

Thank you for your help.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (12 by maintainers)

Most upvoted comments

@srjoglekar246 @jianlijianli

While using latest tf-nightly build (tf-nightly-2.3.0.dev20200613), i noticed that it can convert a SavedModel generated by TF 2.2.0 to TFLite flatbuffer successfully. This verified the fix for ResizeNearestNeighbor with MLIR.

However, if I generate a SavedModel using this tf-nightly build, and convert again, it will fail and prompt something like 'tf.All' op is neither a custom op nor a flex op . And then keep prompting a bunch of hex values. This seems to be a regression.

It also happens to tf-nightly-2.3.0.dev20200614. Could you look into this to make sure it won’t fail in the coming TF 2.3.0? Or should I make a separate ticket?

This is because of the half_pixel_centers argument switched on my default in TF2. The old converter ignores it and converts the op to a ResizeNearestNeighbor with half_pixel_centers=false (which is likely to give inaccurate results). The new converter doesn’t recognize this, so fails.

Supporting all arguments in TFLite’s ResizeNearestNeighbor should fix this issue. @ghop02 I will work on this and ping back on this issue for you to switch on the new converter again.