ETFLITE tensorflow build_error ai_generated true

ConverterError: TFLite conversion failed: quantization for model layer 'conv2d' failed

ID: tensorflow/tflite-conversion-quantization-failed

Also available as: JSON · Markdown · 中文
85%Fix Rate
84%Confidence
1Evidence
2023-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
tensorflow 2.10 active — — —
tensorflow 2.11 active — — —
tensorflow 2.12 active — — —
tflite 2.10 active — — —
tflite 2.11 active — — —

Root Cause

The model contains operations or data types that are not supported by TFLite's post-training quantization, such as unsupported activations or dynamic ranges.

generic

中文

模型包含 TFLite 后训练量化不支持的操作或数据类型,例如不支持的激活函数或动态范围。

Official Documentation

https://www.tensorflow.org/lite/performance/post_training_quantization

Workarounds

  1. 85% success Use selective quantization: converter.optimizations = [tf.lite.Optimize.DEFAULT]; converter.target_spec.supported_types = [tf.float16]; then convert.
    Use selective quantization: converter.optimizations = [tf.lite.Optimize.DEFAULT]; converter.target_spec.supported_types = [tf.float16]; then convert.
  2. 90% success Disable quantization for problematic layers: converter.optimizations = [] and convert without optimization.
    Disable quantization for problematic layers: converter.optimizations = [] and convert without optimization.
  3. 80% success Replace unsupported ops with TFLite-compatible alternatives, e.g., replace tf.nn.relu6 with tf.nn.relu.
    Replace unsupported ops with TFLite-compatible alternatives, e.g., replace tf.nn.relu6 with tf.nn.relu.

中文步骤

  1. Use selective quantization: converter.optimizations = [tf.lite.Optimize.DEFAULT]; converter.target_spec.supported_types = [tf.float16]; then convert.
  2. Disable quantization for problematic layers: converter.optimizations = [] and convert without optimization.
  3. Replace unsupported ops with TFLite-compatible alternatives, e.g., replace tf.nn.relu6 with tf.nn.relu.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The converter cannot handle the incompatible ops, leading to crashes.

  2. 80% fail

    The model structure may not support post-conversion quantization.