<?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>i.MX ProcessorsのトピックIssue with TensorFlow Lite and NPU on iMX93 Module Board</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Issue-with-TensorFlow-Lite-and-NPU-on-iMX93-Module-Board/m-p/2020054#M232435</link>
    <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;I am using iMX93 with SDK &lt;EM&gt;Linux_6.1.55_2.2.0&lt;/EM&gt;. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;I am encountering an issue while running a TensorFlow Lite object detection model on a custom board with the iMX93 module. When I attempt to start inference with this model, iMX93 gets stuck.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Additionally, I have observed that the device consistently gets stuck whenever I access the NPU, even when using the &lt;EM&gt;inference_runner&lt;/EM&gt; and &lt;EM&gt;interpreter_runner&lt;/EM&gt; utilities provided by NXP.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Do you have any ideas or suggestions on what could be causing this problem?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Example usage:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;interpreter = tflite.Interpreter(model_path="model.tflite",
experimental_delegates=[tflite.load_delegate("/usr/lib/libethosu_delegate.so")])
interpreter.allocate_tensors()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;tflite.Interpreter works well, but allocate_tensors() makes the cpu gets stuck.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you in advance!&lt;/SPAN&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 27 Dec 2024 11:50:02 GMT</pubDate>
    <dc:creator>esmamirhan</dc:creator>
    <dc:date>2024-12-27T11:50:02Z</dc:date>
    <item>
      <title>Issue with TensorFlow Lite and NPU on iMX93 Module Board</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Issue-with-TensorFlow-Lite-and-NPU-on-iMX93-Module-Board/m-p/2020054#M232435</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;I am using iMX93 with SDK &lt;EM&gt;Linux_6.1.55_2.2.0&lt;/EM&gt;. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;I am encountering an issue while running a TensorFlow Lite object detection model on a custom board with the iMX93 module. When I attempt to start inference with this model, iMX93 gets stuck.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Additionally, I have observed that the device consistently gets stuck whenever I access the NPU, even when using the &lt;EM&gt;inference_runner&lt;/EM&gt; and &lt;EM&gt;interpreter_runner&lt;/EM&gt; utilities provided by NXP.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Do you have any ideas or suggestions on what could be causing this problem?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Example usage:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;interpreter = tflite.Interpreter(model_path="model.tflite",
experimental_delegates=[tflite.load_delegate("/usr/lib/libethosu_delegate.so")])
interpreter.allocate_tensors()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;tflite.Interpreter works well, but allocate_tensors() makes the cpu gets stuck.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you in advance!&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 27 Dec 2024 11:50:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Issue-with-TensorFlow-Lite-and-NPU-on-iMX93-Module-Board/m-p/2020054#M232435</guid>
      <dc:creator>esmamirhan</dc:creator>
      <dc:date>2024-12-27T11:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with TensorFlow Lite and NPU on iMX93 Module Board</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Issue-with-TensorFlow-Lite-and-NPU-on-iMX93-Module-Board/m-p/2021336#M232548</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Please send you test code to check it.&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 14:37:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Issue-with-TensorFlow-Lite-and-NPU-on-iMX93-Module-Board/m-p/2021336#M232548</guid>
      <dc:creator>Bio_TICFSL</dc:creator>
      <dc:date>2025-01-02T14:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with TensorFlow Lite and NPU on iMX93 Module Board</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Issue-with-TensorFlow-Lite-and-NPU-on-iMX93-Module-Board/m-p/2024852#M232832</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you for your reply! We have successfully resolved the model loading issue by fixing ethosu shared memory in Kernel, and the device is no longer crashing. However, we are now encountering a different issue with the NPU on our custom board, and we would appreciate your assistance.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;The NPU is unable to run inference correctly. For example, the following test code works as expected on the i.MX 93 EVK, producing the output:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Test code:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import tflite_runtime.interpreter as tflite
import numpy as np

def run_inference(interpreter, image):
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_scale, input_zero_point = input_details[0]["quantization"]
image = image / input_scale + input_zero_point
image = image.astype(np.int8)

interpreter.set_tensor(input_details[0]['index'], image)
interpreter.invoke()

output = interpreter.get_tensor(output_details[0]['index'])
return output

interpreter = tflite.Interpreter(model_path="TFLITE_MODEL_PATH",
experimental_delegates=[tflite.load_delegate("/usr/lib/libethosu_delegate.so")])

interpreter.allocate_tensors()

for i in range(10):
image = np.zeros((416, 416, 3), dtype="uint8")
image = np.expand_dims(image, axis=0)
print(f"Running for {i}'th time")
output = run_inference(interpreter, image)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;Output on i.MX EVK:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;root@imx93evk:/# python3 demo.py
INFO: Ethosu delegate: device_name set to /dev/ethosu0.
INFO: Ethosu delegate: cache_file_path set to .
INFO: Ethosu delegate: timeout set to 60000000000.
INFO: Ethosu delegate: enable_cycle_counter set to 0.
INFO: Ethosu delegate: enable_profiling set to 0.
INFO: Ethosu delegate: profiling_buffer_size set to 2048.
INFO: Ethosu delegate: pmu_event0 set to 0.
INFO: Ethosu delegate: pmu_event1 set to 0.
INFO: Ethosu delegate: pmu_event2 set to 0.
INFO: Ethosu delegate: pmu_event3 set to 0.
INFO: EthosuDelegate: 1 nodes delegated out of 3 nodes with 1 partitions.
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Running for 0'th time
Running for 1'th time
Running for 2'th time
Running for 3'th time
Running for 4'th time
Running for 5'th time
Running for 6'th time
Running for 7'th time
Running for 8'th time
Running for 9'th time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;However, on our custom board, it gets stuck during the second inference. Additionally, if we attempt to run the script again, the NPU does not perform any inference until the device is rebooted. The output is as follows:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;root@imx93-dtsis:/# python3 demo.py
INFO: Ethosu delegate: device_name set to /dev/ethosu0.
INFO: Ethosu delegate: cache_file_path set to .
INFO: Ethosu delegate: timeout set to 60000000000.
INFO: Ethosu delegate: enable_cycle_counter set to 0.
INFO: Ethosu delegate: enable_profiling set to 0.
INFO: Ethosu delegate: profiling_buffer_size set to 2048.
INFO: Ethosu delegate: pmu_event0 set to 0.
INFO: Ethosu delegate: pmu_event1 set to 0.
INFO: Ethosu delegate: pmu_event2 set to 0.
INFO: Ethosu delegate: pmu_event3 set to 0.
INFO: EthosuDelegate: 1 nodes delegated out of 3 nodes with 1 partitions.
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Running for 0'th time
Running for 1'th time
Traceback (most recent call last):
File "/demo.py", line 36, in &amp;lt;module&amp;gt;
main()
File "/demo.py", line 33, in main
output = run_inference(interpreter, image)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/demo.py", line 14, in run_inference
interpreter.invoke()
File "/usr/lib64/python3.11/site-packages/tflite_runtime/interpreter.py", line 917, in invoke
self._interpreter.Invoke()
RuntimeError: Ethos_u inference failed
Node number 3 (EthosuDelegate) failed to invoke.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;Since we are using 1GB LPDDR4, NPU shared memory size is aligned 128 MB according to the link below. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;A href="https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/Config-Tool-Introduction-and-Use/ta-p/1986035" target="_blank" rel="noopener"&gt;https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/Config-Tool-Introduction-and-Use/ta-p/1986035&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Note that we fixed ethosu region in kernel as it is described in your docs like the following:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image_2025_01_09T12_11_17_480Z.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/318811iDBA66394322867A3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image_2025_01_09T12_11_17_480Z.png" alt="image_2025_01_09T12_11_17_480Z.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Could this reduced allocation be the cause of the issue? If not, do you have any suggestions for resolving it?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you in advance!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Jan 2025 12:43:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Issue-with-TensorFlow-Lite-and-NPU-on-iMX93-Module-Board/m-p/2024852#M232832</guid>
      <dc:creator>esmamirhan</dc:creator>
      <dc:date>2025-01-09T12:43:23Z</dc:date>
    </item>
  </channel>
</rss>

