<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Running a Quantized UINT8 lstm model generates FlexTensor Error. in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Running-a-Quantized-UINT8-lstm-model-generates-FlexTensor-Error/m-p/1476026#M191605</link>
    <description>&lt;P&gt;i have Quantized lstm model by setting input and output inference type to uint8.&lt;BR /&gt;by following script :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import tensorflow as tf
import numpy as np
from tqdm import tqdm
import random

dat = np.load("data_train.npy")
len = dat.shape[0]

def representative_data_gen():
    for i in tqdm(range(10000)):
        p = random.choice(dat)
        da = np.expand_dims(p,axis=0)
        yield [np.float32(da)]

model = tf.saved_model.load("./model_dir")
concrete_func = model.signatures[
  tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
concrete_func.inputs[0].set_shape([1, ?, ?])
concrete_func.outputs[0].set_shape([1, ?, ?, ?])
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_data_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
converter._experimental_lower_tensor_list_ops = False
tflite_quant_model = converter.convert()

with open("./quant_model.tflite","wb") as f:
    f.write(tflite_quant_model)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when i am executing the &lt;STRONG&gt;quant_model.tflite&lt;/STRONG&gt; using the benchmark script&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;USE_GPU_INFERENCE=0 /usr/bin/tensorflow-lite-2.6.0/examples/benchmark_model --graph=quant_model.tflite --num_runs=50 --external_delegate_path=/usr/lib/libvx_delegate.so&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Facing error :&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----&lt;/P&gt;&lt;P&gt;-----&lt;/P&gt;&lt;P&gt;ERROR: Fallback unsupported op 32 to TfLite&lt;BR /&gt;Explicitly applied EXTERNAL delegate, and the model graph will be partially executed by the delegate w/ 13 delegate kernels.&lt;BR /&gt;ERROR: Regular TensorFlow ops are not supported by this interpreter. Make sure you apply/link the Flex delegate before inference.&lt;BR /&gt;&lt;STRONG&gt;ERROR: Node number 5 (FlexTensorListFromTensor) failed to prepare.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ERROR: Failed to apply the default TensorFlow Lite delegate indexed at 0.&lt;BR /&gt;Failed to allocate tensors!&lt;BR /&gt;Benchmarking failed.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jun 2022 12:43:00 GMT</pubDate>
    <dc:creator>kapil</dc:creator>
    <dc:date>2022-06-17T12:43:00Z</dc:date>
    <item>
      <title>Running a Quantized UINT8 lstm model generates FlexTensor Error.</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Running-a-Quantized-UINT8-lstm-model-generates-FlexTensor-Error/m-p/1476026#M191605</link>
      <description>&lt;P&gt;i have Quantized lstm model by setting input and output inference type to uint8.&lt;BR /&gt;by following script :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import tensorflow as tf
import numpy as np
from tqdm import tqdm
import random

dat = np.load("data_train.npy")
len = dat.shape[0]

def representative_data_gen():
    for i in tqdm(range(10000)):
        p = random.choice(dat)
        da = np.expand_dims(p,axis=0)
        yield [np.float32(da)]

model = tf.saved_model.load("./model_dir")
concrete_func = model.signatures[
  tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
concrete_func.inputs[0].set_shape([1, ?, ?])
concrete_func.outputs[0].set_shape([1, ?, ?, ?])
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_data_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
converter._experimental_lower_tensor_list_ops = False
tflite_quant_model = converter.convert()

with open("./quant_model.tflite","wb") as f:
    f.write(tflite_quant_model)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now when i am executing the &lt;STRONG&gt;quant_model.tflite&lt;/STRONG&gt; using the benchmark script&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;USE_GPU_INFERENCE=0 /usr/bin/tensorflow-lite-2.6.0/examples/benchmark_model --graph=quant_model.tflite --num_runs=50 --external_delegate_path=/usr/lib/libvx_delegate.so&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Facing error :&amp;nbsp;&lt;/P&gt;&lt;P&gt;-----&lt;/P&gt;&lt;P&gt;-----&lt;/P&gt;&lt;P&gt;ERROR: Fallback unsupported op 32 to TfLite&lt;BR /&gt;Explicitly applied EXTERNAL delegate, and the model graph will be partially executed by the delegate w/ 13 delegate kernels.&lt;BR /&gt;ERROR: Regular TensorFlow ops are not supported by this interpreter. Make sure you apply/link the Flex delegate before inference.&lt;BR /&gt;&lt;STRONG&gt;ERROR: Node number 5 (FlexTensorListFromTensor) failed to prepare.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ERROR: Failed to apply the default TensorFlow Lite delegate indexed at 0.&lt;BR /&gt;Failed to allocate tensors!&lt;BR /&gt;Benchmarking failed.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 12:43:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Running-a-Quantized-UINT8-lstm-model-generates-FlexTensor-Error/m-p/1476026#M191605</guid>
      <dc:creator>kapil</dc:creator>
      <dc:date>2022-06-17T12:43:00Z</dc:date>
    </item>
  </channel>
</rss>

