tensorflow / tensorflow/model-optimization
loc("model/FPN/FPN/FPN//Concatenate_p_1/concat"): error: 'tfl.concatenation' op quantization parameters violate the same scale constraint: !quant.uniform<i8:f32, 9.9999999999999995E-7> vs. !quant.uniform<i8:f32, 4.9130543629871681E-5:-128>
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 349
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 1
Description
1. System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
- TensorFlow installation (pip package or built from source): pip
- TensorFlow library (version, if pip package or github SHA, if built from source): 2.5.1
2. Code and initial problem
I am trying to quantize a model of which I do not want to show the code, however, I can share a non-quantized TFLite model. The node where the error happens is node 89.
import tensorflow as tf
model = create_model(...)
model.compile()
def representative_dataset_generator():
for _ in range(20):
yield [tf.random.uniform(shape=(1, IMAGE_SIZE, IMAGE_SIZE, 3), minval=-1, maxval=1,
dtype=tf.float32)]
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
# If I comment these 5 lines, i.e. if I do not quantize the conversion goes through and this is the shared model
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.target_spec.supported_types = [tf.int8]
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
converter.representative_dataset = representative_dataset_generator
tflite_quant_model = converter.convert()
with open('model.tflite', 'wb') as file:
file.write(tflite_quant_model)
3. Using the old converter and failure after conversion
If I use the old converter and old quantizer by using the additional lines below, the conversion goes through and I get
this TFLite model.
converter.experimental_new_converter = False
converter.experimental_new_quantizer = False
But when I run the TFLite profiler on a phone with a DSP using the --use-nnapi=true, I get:
ERROR: NN API returned error ANEURALNETWORKS_OP_FAILED at line 4453 while running computation.
ERROR: Node number 177 (TfLiteNnapiDelegate) failed to invoke.
I tried to share as much relevant information as I could but don't hesitate to ask for additional information. Looking forward hearing from you.
Thanks in advance!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TFLiteConverter configuration shown in the issue and investigate the failure at node 89 during INT8 conversion, comparing the new converter and quantizer with the old settings. Use the shared non-quantized and old-converter models to reproduce the quantization error, then verify that conversion succeeds and NNAPI profiling on the phone no longer reports an operation failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100