<?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 Not supported INT8 quantized TRANSPOSE_CONV on iMX8m plus in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1318033#M177875</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;We bought an evaluation board for “iMX8m plus” to run a custom post-training quantized (INT8 PTQ) TFLite model doing a semantic segmentation of RGB pictures.&lt;/P&gt;&lt;P&gt;Our custom model uses TF 2.4 with standard TRANSPOSE_CONV that seems to prevent execution…&lt;BR /&gt;For information, we use the provided TFLite delegates (i.e., NNAPI) which should be able to handle this kind of operation (&lt;A href="https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/neuralnetworks/1.2/types.hal#4344" target="_self"&gt;https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/neuralnetworks/1.2/types.hal#4344&lt;/A&gt;&amp;nbsp;).&lt;/P&gt;&lt;P&gt;The error message is explicit :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;WARNING: Operator TRANSPOSE_CONV (v3) refused by NNAPI delegate: OP Version different from 1&lt;/LI-CODE&gt;&lt;P&gt;Applied NNAPI delegate.&lt;BR /&gt;So, it seems our model generate a v3 TRANSPOSE_CONV rather than the v1 expected by the delegates…&lt;/P&gt;&lt;P&gt;We identified in TFLite source code the block responsible of the version number generation (&lt;A href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/versioning/op_version.cc#L286" target="_self"&gt;https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/versioning/op_version.cc#L286&lt;/A&gt;&amp;nbsp;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;case BuiltinOperator_TRANSPOSE_CONV: {
      if (op_sig.inputs.size() == 4 &amp;amp;&amp;amp;
          op_sig.inputs.at(3).type != kTfLiteNoType) {
        return 3;
      }
      // If the op takes int8 input, it is version 2.
      if (op_sig.inputs.at(1).type == kTfLiteInt8) {
        return 2;
      }
      return 1;
    }&lt;/LI-CODE&gt;&lt;P&gt;Our first question is pretty simple: “How to generate a valid operation?”&lt;BR /&gt;And if we can’t generate a v1 operation: “Is it possible to run a INT8 quantized TRANSPOSE_CONV on iMX8m plus?”&lt;/P&gt;&lt;P&gt;To help you reproduce our behavior, before posting this message, we tried to reduce our code to generate the simplest PTQ TFLite file using a TRANSPOSE_CONV:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import tensorflow as tf
import numpy as np

def representative_data_gen():
    for _ in range(16):
        yield [tf.convert_to_tensor(np.random.rand(1, 16, 16, 1), dtype="float32")]

def main():
    keras_model = tf.keras.models.Sequential([
            tf.keras.Input(name="model_input", shape=(16, 16, 1), dtype=tf.float32),
            tf.keras.layers.Conv2DTranspose(filters=2, kernel_size=3, strides=2, padding="SAME"),
            ])

    keras_model.input.set_shape((1,) + keras_model.input.shape[1:])

    converter: tf.lite.TFLiteConverter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
    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_types = [tf.int8]
    converter.inference_input_type = tf.uint8
    converter.inference_output_type = tf.uint8

    with open("model.tflite", "wb") as file:
        file.write(converter.convert())

if __name__ == '__main__':
    main()&lt;/LI-CODE&gt;&lt;P&gt;And to run the generated TFLite model, we use the following code on iMX8m plus:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import numpy as np
import tflite_runtime.interpreter as tflite

interpreter: tflite.Interpreter = tflite.Interpreter(model_path="model.tflite")
interpreter.allocate_tensors()

input0 = interpreter.get_input_details()[0]
get_input = interpreter.tensor(input0['index'])

get_input()[:, :, :] = np.zeros(shape=(16, 16, 1), dtype="uint8")
interpreter.invoke()&lt;/LI-CODE&gt;&lt;P&gt;And, when we run these scripts, we always obtain the following message:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# INFO: Created TensorFlow Lite delegate for NNAPI.
# WARNING: Operator TRANSPOSE_CONV (v3) refused by NNAPI delegate: OP Version different from 1
# Applied NNAPI delegate.&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;Guillaume SCHLOTTERBECK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Aug 2021 09:34:01 GMT</pubDate>
    <dc:creator>GuillaumeSchlo</dc:creator>
    <dc:date>2021-08-04T09:34:01Z</dc:date>
    <item>
      <title>Not supported INT8 quantized TRANSPOSE_CONV on iMX8m plus</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1318033#M177875</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;We bought an evaluation board for “iMX8m plus” to run a custom post-training quantized (INT8 PTQ) TFLite model doing a semantic segmentation of RGB pictures.&lt;/P&gt;&lt;P&gt;Our custom model uses TF 2.4 with standard TRANSPOSE_CONV that seems to prevent execution…&lt;BR /&gt;For information, we use the provided TFLite delegates (i.e., NNAPI) which should be able to handle this kind of operation (&lt;A href="https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/neuralnetworks/1.2/types.hal#4344" target="_self"&gt;https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/neuralnetworks/1.2/types.hal#4344&lt;/A&gt;&amp;nbsp;).&lt;/P&gt;&lt;P&gt;The error message is explicit :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;WARNING: Operator TRANSPOSE_CONV (v3) refused by NNAPI delegate: OP Version different from 1&lt;/LI-CODE&gt;&lt;P&gt;Applied NNAPI delegate.&lt;BR /&gt;So, it seems our model generate a v3 TRANSPOSE_CONV rather than the v1 expected by the delegates…&lt;/P&gt;&lt;P&gt;We identified in TFLite source code the block responsible of the version number generation (&lt;A href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/versioning/op_version.cc#L286" target="_self"&gt;https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/versioning/op_version.cc#L286&lt;/A&gt;&amp;nbsp;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;case BuiltinOperator_TRANSPOSE_CONV: {
      if (op_sig.inputs.size() == 4 &amp;amp;&amp;amp;
          op_sig.inputs.at(3).type != kTfLiteNoType) {
        return 3;
      }
      // If the op takes int8 input, it is version 2.
      if (op_sig.inputs.at(1).type == kTfLiteInt8) {
        return 2;
      }
      return 1;
    }&lt;/LI-CODE&gt;&lt;P&gt;Our first question is pretty simple: “How to generate a valid operation?”&lt;BR /&gt;And if we can’t generate a v1 operation: “Is it possible to run a INT8 quantized TRANSPOSE_CONV on iMX8m plus?”&lt;/P&gt;&lt;P&gt;To help you reproduce our behavior, before posting this message, we tried to reduce our code to generate the simplest PTQ TFLite file using a TRANSPOSE_CONV:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import tensorflow as tf
import numpy as np

def representative_data_gen():
    for _ in range(16):
        yield [tf.convert_to_tensor(np.random.rand(1, 16, 16, 1), dtype="float32")]

def main():
    keras_model = tf.keras.models.Sequential([
            tf.keras.Input(name="model_input", shape=(16, 16, 1), dtype=tf.float32),
            tf.keras.layers.Conv2DTranspose(filters=2, kernel_size=3, strides=2, padding="SAME"),
            ])

    keras_model.input.set_shape((1,) + keras_model.input.shape[1:])

    converter: tf.lite.TFLiteConverter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
    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_types = [tf.int8]
    converter.inference_input_type = tf.uint8
    converter.inference_output_type = tf.uint8

    with open("model.tflite", "wb") as file:
        file.write(converter.convert())

if __name__ == '__main__':
    main()&lt;/LI-CODE&gt;&lt;P&gt;And to run the generated TFLite model, we use the following code on iMX8m plus:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import numpy as np
import tflite_runtime.interpreter as tflite

interpreter: tflite.Interpreter = tflite.Interpreter(model_path="model.tflite")
interpreter.allocate_tensors()

input0 = interpreter.get_input_details()[0]
get_input = interpreter.tensor(input0['index'])

get_input()[:, :, :] = np.zeros(shape=(16, 16, 1), dtype="uint8")
interpreter.invoke()&lt;/LI-CODE&gt;&lt;P&gt;And, when we run these scripts, we always obtain the following message:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# INFO: Created TensorFlow Lite delegate for NNAPI.
# WARNING: Operator TRANSPOSE_CONV (v3) refused by NNAPI delegate: OP Version different from 1
# Applied NNAPI delegate.&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;Guillaume SCHLOTTERBECK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 09:34:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1318033#M177875</guid>
      <dc:creator>GuillaumeSchlo</dc:creator>
      <dc:date>2021-08-04T09:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Not supported INT8 quantized TRANSPOSE_CONV on iMX8m plus</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1319062#M177967</link>
      <description>&lt;P&gt;HelloGuillaumeSchlo,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems there are some attachments missing - please share the simplified model with&amp;nbsp;&lt;SPAN&gt;TRANSPOSE_CONV, the scripts you are mentioning and error message.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Also could you clarify if you are using the NXP yocto BSP and eIQ, if yes which version?&amp;nbsp; Although it sounds like you are trying to implement custom TFLite support; in this case, following the&amp;nbsp; eIQ tensorflow-imx implementation should help:&amp;nbsp;&lt;A href="https://source.codeaurora.org/external/imx/tensorflow-imx/tree/?h=lf-5.10.y_1.0.0" target="_blank" rel="noopener nofollow noreferrer"&gt;https://source.codeaurora.org/external/imx/tensorflow-imx/tree/?h=lf-5.10.y_1.0.0&lt;/A&gt;. The &lt;A href="https://www.nxp.com/docs/en/user-guide/IMX-MACHINE-LEARNING-UG.pdf" target="_self" rel="nofollow noopener noreferrer"&gt;ML User's guide&lt;/A&gt; mentions TRANSPOSE_CONV as being supported (Table 8).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 12:52:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1319062#M177967</guid>
      <dc:creator>Bio_TICFSL</dc:creator>
      <dc:date>2021-08-05T12:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Not supported INT8 quantized TRANSPOSE_CONV on iMX8m plus</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1320334#M178079</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;I am using the NXP Yocto BSP from 2021-07-19 by Karo (based on NXP5.10.9_1.0.0):&lt;BR /&gt;&lt;A href="https://karo-electronics.github.io/docs/yocto-guide/nxp/index.html&amp;nbsp;" target="_self"&gt;https://karo-electronics.github.io/docs/yocto-guide/nxp/index.html&amp;nbsp;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I installed a specific yocto for machine learning provided by Karo. There is tflite_runtime 2.4.0 (__git_version__ lf-5.10.y-1.0.0-rc3 according to the repo you sent to me).&lt;BR /&gt;Indeed, according to the documentation, TRANSPOSE_CONV should be supported, but my simple TF network (with only one TRANSPOSE_CONV) use the V3 of this op. The NNAPI accept only V1.&lt;/P&gt;&lt;P&gt;I joined scrpits you asked and the simple model.&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;A test with my own model (with FULLY_CONNECTED, CONV_2D and TRANSPOSE_CONV).&lt;/P&gt;&lt;P&gt;I had the warning about TRANSPOSE_CONV with one about FULLY_CONNECTED:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Operator FULLY_CONNECTED (v5) refused by NNAPI delegate: keep_num_dims == true not supported
Operator TRANSPOSE_CONV (v3) refused by NNAPI delegate: OP Version different from 1&lt;/LI-CODE&gt;&lt;P&gt;After profiling with /usr/bin/tensorflow-lite-2.4.0/examples/benchmark_model, I noticed that all FULLY_CONNECTED and TRANSPOSE_CONV are run on CPU instead NPU, that is coherent with warning I got.&lt;/P&gt;&lt;P&gt;I test to update tflite_runtime with pip according to the documentatin (&lt;A href="https://karo-electronics.github.io/docs/software-documentation/tx8/coral.html" target="_self"&gt;https://karo-electronics.github.io/docs/software-documentation/tx8/coral.html&lt;/A&gt;&amp;nbsp;).&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;pip3 install --extra-index-url https://google-coral.github.io/py-repo/ pycoral&lt;/LI-CODE&gt;&lt;P&gt;After update, inference with NPU are not possible anymore: inference time is longer, profiling shows that all operation are on CPU and warning disappeared.&lt;/P&gt;&lt;P&gt;King regards,&lt;BR /&gt;Guillaume SCHLOTTERBECK&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 12:35:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1320334#M178079</guid>
      <dc:creator>GuillaumeSchlo</dc:creator>
      <dc:date>2021-08-09T12:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Not supported INT8 quantized TRANSPOSE_CONV on iMX8m plus</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1338484#M179923</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;it is planned to add initial support for TRANSPOSE_CONV operator in LF5.10.52-2.1.0. &lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 14:33:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Not-supported-INT8-quantized-TRANSPOSE-CONV-on-iMX8m-plus/m-p/1338484#M179923</guid>
      <dc:creator>Bio_TICFSL</dc:creator>
      <dc:date>2021-09-10T14:33:43Z</dc:date>
    </item>
  </channel>
</rss>

