<?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 Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1809216#M219995</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/151788"&gt;@Zhiming_Liu&lt;/a&gt;&amp;nbsp;, I already have this layer but I don't have /usr/lib/libvx_delegate.so in my compiled system. Should I edit my recipe?&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2024 15:44:10 GMT</pubDate>
    <dc:creator>FSet89</dc:creator>
    <dc:date>2024-02-15T15:44:10Z</dc:date>
    <item>
      <title>tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1649438#M205799</link>
      <description>&lt;P&gt;I am working on a script that is deployed on a IMX8MP with NPU and NNAPI. The script makes inferences using the tflite_runtime library. If a thread is started producing a high cpu usage, tflite stops working, producing always the same result regardless of the input. I provided a minimum working example on &lt;A href="https://github.com/tensorflow/tensorflow/issues/60563" target="_self"&gt;github&lt;/A&gt;. The problem is not encountered on my PC. Is it related to NNAPI?&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 12:55:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1649438#M205799</guid>
      <dc:creator>FSet89</dc:creator>
      <dc:date>2023-05-12T12:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650672#M205901</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/187288"&gt;@FSet89&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you share your test script ,model and steps?&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 02:16:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650672#M205901</guid>
      <dc:creator>Zhiming_Liu</dc:creator>
      <dc:date>2023-05-16T02:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650843#M205912</link>
      <description>&lt;P&gt;Hi, here is the code. I cannot share the model but you can try with any quantized tflite model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import multiprocessing
from multiprocessing import Queue, Process
import numpy as np
from threading import Thread
from random import random, randint
import tflite_runtime.interpreter as tflite
import &lt;SPAN class=""&gt;time&lt;/SPAN&gt;
import cv2 
import os
import sys
import psutil

class ClassificationModel(object):
	def __init__(self, path, mask_path=None):
		self.interpreter = tflite.Interpreter(model_path=path)
		&lt;SPAN class=""&gt;self.interpreter.allocate_tensors&lt;/SPAN&gt;()
		self.input_details = &lt;SPAN class=""&gt;self.interpreter.get_input_details&lt;/SPAN&gt;()
		self.output_details = &lt;SPAN class=""&gt;self.interpreter.get_output_details&lt;/SPAN&gt;()
		self.input_shape = self.input_details[0][&lt;SPAN class=""&gt;'shape'&lt;/SPAN&gt;]



	def predict(self, img, resize=True):

		&lt;SPAN class=""&gt;if&lt;/SPAN&gt; resize:
			img = cv2.resize(img, (self.input_shape[2], self.input_shape[1]))		

		img = (img/255.0).astype(np.float32)
		img = np.expand_dims(img, 0)
		self.interpreter.set_tensor(self.input_details[0][&lt;SPAN class=""&gt;'index'&lt;/SPAN&gt;], img)				
		&lt;SPAN class=""&gt;self.interpreter.invoke&lt;/SPAN&gt;()			
		output = self.interpreter.get_tensor(self.output_details[0][&lt;SPAN class=""&gt;'index'&lt;/SPAN&gt;])
		output = np.squeeze(output)
		
		&lt;SPAN class=""&gt;return&lt;/SPAN&gt; output



def &lt;SPAN class=""&gt;my_thread_1&lt;/SPAN&gt;():
	print(&lt;SPAN class=""&gt;"Start threaded task 1"&lt;/SPAN&gt;)
	&lt;SPAN class=""&gt;simulate_cpu_load&lt;/SPAN&gt;()

	print(&lt;SPAN class=""&gt;"Task 1 completed"&lt;/SPAN&gt;)


def &lt;SPAN class=""&gt;worker&lt;/SPAN&gt;():
	&lt;SPAN class=""&gt;while&lt;/SPAN&gt; True:
		pass

def &lt;SPAN class=""&gt;simulate_cpu_load&lt;/SPAN&gt;():
	num_cores = &lt;SPAN class=""&gt;multiprocessing.cpu_count&lt;/SPAN&gt;()
	processes = []

	&lt;SPAN class=""&gt;for&lt;/SPAN&gt; &lt;SPAN class=""&gt;_&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; range(num_cores):
		p = multiprocessing.Process(target=worker)
		&lt;SPAN class=""&gt;p.start&lt;/SPAN&gt;()
		processes.append(p)

	time.sleep(3) 

	&lt;SPAN class=""&gt;for&lt;/SPAN&gt; &lt;SPAN class=""&gt;p&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; processes:
		&lt;SPAN class=""&gt;p.terminate&lt;/SPAN&gt;()




&lt;SPAN class=""&gt;if&lt;/SPAN&gt; __name__ == &lt;SPAN class=""&gt;'__main__'&lt;/SPAN&gt;:
	classifier_1 = ClassificationModel(&lt;SPAN class=""&gt;'mymodel.tflite)&lt;/SPAN&gt;	
	
&lt;SPAN class=""&gt;	cap = cv2.VideoCapture()&lt;/SPAN&gt;
&lt;SPAN class=""&gt;	for i in range(5):&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		cap.open(i)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		if cap.isOpened():&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			break&lt;/SPAN&gt;

&lt;SPAN class=""&gt;	if not cap.isOpened():&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		print("Could not open camera")&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		exit()&lt;/SPAN&gt;


&lt;SPAN class=""&gt;	try:&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		while True:		&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			# get image			&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			ret, img = cap.read()&lt;/SPAN&gt;

&lt;SPAN class=""&gt;			# predict			&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			p1 = classifier_1.predict(img)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			print(p1)			&lt;/SPAN&gt;

&lt;SPAN class=""&gt;			# threaded task&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			if random() &amp;lt; 0.1:&lt;/SPAN&gt;
&lt;SPAN class=""&gt;				t = Thread(target=my_thread_1)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;				t.start()&lt;/SPAN&gt;
			
&lt;SPAN class=""&gt;	except(KeyboardInterrupt):&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		exit()&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2023 06:36:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650843#M205912</guid>
      <dc:creator>FSet89</dc:creator>
      <dc:date>2023-05-16T06:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650879#M205916</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/151788"&gt;@Zhiming_Liu&lt;/a&gt;&amp;nbsp;, here is the code. I cannot share the model but you can try with any quantized tflite model:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import multiprocessing
from multiprocessing import Queue, Process
import numpy as np
from threading import Thread
from random import random, randint
import tflite_runtime.interpreter as tflite
import &lt;SPAN class=""&gt;time&lt;/SPAN&gt;
import cv2 
import os
import sys
import psutil

class ClassificationModel(object):
	def __init__(self, path, mask_path=None):
		self.interpreter = tflite.Interpreter(model_path=path)
		&lt;SPAN class=""&gt;self.interpreter.allocate_tensors&lt;/SPAN&gt;()
		self.input_details = &lt;SPAN class=""&gt;self.interpreter.get_input_details&lt;/SPAN&gt;()
		self.output_details = &lt;SPAN class=""&gt;self.interpreter.get_output_details&lt;/SPAN&gt;()
		self.input_shape = self.input_details[0][&lt;SPAN class=""&gt;'shape'&lt;/SPAN&gt;]



	def predict(self, img, resize=True):

		&lt;SPAN class=""&gt;if&lt;/SPAN&gt; resize:
			img = cv2.resize(img, (self.input_shape[2], self.input_shape[1]))		

		img = (img/255.0).astype(np.float32)
		img = np.expand_dims(img, 0)
		self.interpreter.set_tensor(self.input_details[0][&lt;SPAN class=""&gt;'index'&lt;/SPAN&gt;], img)				
		&lt;SPAN class=""&gt;self.interpreter.invoke&lt;/SPAN&gt;()			
		output = self.interpreter.get_tensor(self.output_details[0][&lt;SPAN class=""&gt;'index'&lt;/SPAN&gt;])
		output = np.squeeze(output)
		
		&lt;SPAN class=""&gt;return&lt;/SPAN&gt; output



def &lt;SPAN class=""&gt;my_thread_1&lt;/SPAN&gt;():
	print(&lt;SPAN class=""&gt;"Start threaded task 1"&lt;/SPAN&gt;)
	&lt;SPAN class=""&gt;simulate_cpu_load&lt;/SPAN&gt;()

	print(&lt;SPAN class=""&gt;"Task 1 completed"&lt;/SPAN&gt;)


def &lt;SPAN class=""&gt;worker&lt;/SPAN&gt;():
	&lt;SPAN class=""&gt;while&lt;/SPAN&gt; True:
		pass

def &lt;SPAN class=""&gt;simulate_cpu_load&lt;/SPAN&gt;():
	num_cores = &lt;SPAN class=""&gt;multiprocessing.cpu_count&lt;/SPAN&gt;()
	processes = []

	&lt;SPAN class=""&gt;for&lt;/SPAN&gt; &lt;SPAN class=""&gt;_&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; range(num_cores):
		p = multiprocessing.Process(target=worker)
		&lt;SPAN class=""&gt;p.start&lt;/SPAN&gt;()
		processes.append(p)

	time.sleep(3) 

	&lt;SPAN class=""&gt;for&lt;/SPAN&gt; &lt;SPAN class=""&gt;p&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; processes:
		&lt;SPAN class=""&gt;p.terminate&lt;/SPAN&gt;()




&lt;SPAN class=""&gt;if&lt;/SPAN&gt; __name__ == &lt;SPAN class=""&gt;'__main__'&lt;/SPAN&gt;:
	classifier_1 = ClassificationModel(&lt;SPAN class=""&gt;'mymodel.tflite)&lt;/SPAN&gt;	
	
&lt;SPAN class=""&gt;	cap = cv2.VideoCapture()&lt;/SPAN&gt;
&lt;SPAN class=""&gt;	for i in range(5):&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		cap.open(i)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		if cap.isOpened():&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			break&lt;/SPAN&gt;

&lt;SPAN class=""&gt;	if not cap.isOpened():&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		print("Could not open camera")&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		exit()&lt;/SPAN&gt;


&lt;SPAN class=""&gt;	try:&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		while True:		&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			# get image			&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			ret, img = cap.read()&lt;/SPAN&gt;

&lt;SPAN class=""&gt;			# predict			&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			p1 = classifier_1.predict(img)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			print(p1)			&lt;/SPAN&gt;

&lt;SPAN class=""&gt;			# threaded task&lt;/SPAN&gt;
&lt;SPAN class=""&gt;			if random() &amp;lt; 0.1:&lt;/SPAN&gt;
&lt;SPAN class=""&gt;				t = Thread(target=my_thread_1)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;				t.start()&lt;/SPAN&gt;
			
&lt;SPAN class=""&gt;	except(KeyboardInterrupt):&lt;/SPAN&gt;
&lt;SPAN class=""&gt;		exit()&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 14:26:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650879#M205916</guid>
      <dc:creator>FSet89</dc:creator>
      <dc:date>2023-05-17T14:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650934#M205925</link>
      <description>&lt;P&gt;Hi, I tried to share the code but my reply keeps getting deleted. However you can find the code in the linked github issue. I cannot share the model but you can try with any quantized tflite model.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 11:41:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1650934#M205925</guid>
      <dc:creator>FSet89</dc:creator>
      <dc:date>2023-05-16T11:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1656210#M206402</link>
      <description>&lt;P&gt;Please try the vx_delegate not NNAPI. The NNAPI is not maintained by NXP&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt; delegate = tflite.load_delegate('/usr/lib/libvx_delegate.so')
 self.interpreter = tflite.Interpreter(model_path=path, experimental_delegates=[delegate])
&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 May 2023 03:57:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1656210#M206402</guid>
      <dc:creator>Zhiming_Liu</dc:creator>
      <dc:date>2023-05-24T03:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1656316#M206417</link>
      <description>&lt;P&gt;Thank you for your suggestion. I don't have the vx_delegate in my Yocto system. Can you provide me some reference about how to add it to Yocto?&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 06:16:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1656316#M206417</guid>
      <dc:creator>FSet89</dc:creator>
      <dc:date>2023-05-24T06:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1657217#M206516</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/187288"&gt;@FSet89&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can refer the&amp;nbsp;i.MX Yocto Project User’s Guide​ to dowlnad i.MX yocto project from this website &lt;A href="https://www.nxp.com/design/software/embedded-software/i-mx-software/embedded-linux-for-i-mx-applications-processors:IMXLINUX" target="_blank"&gt;https://www.nxp.com/design/software/embedded-software/i-mx-software/embedded-linux-for-i-mx-applications-processors:IMXLINUX&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then copy the layer&amp;nbsp;/sources/meta-imx/meta-ml/ to your Yocto project.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 02:51:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1657217#M206516</guid>
      <dc:creator>Zhiming_Liu</dc:creator>
      <dc:date>2023-05-25T02:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: tflite_runtime + NNAPI stops working when a computational heavy thread is started</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1809216#M219995</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/151788"&gt;@Zhiming_Liu&lt;/a&gt;&amp;nbsp;, I already have this layer but I don't have /usr/lib/libvx_delegate.so in my compiled system. Should I edit my recipe?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 15:44:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/tflite-runtime-NNAPI-stops-working-when-a-computational-heavy/m-p/1809216#M219995</guid>
      <dc:creator>FSet89</dc:creator>
      <dc:date>2024-02-15T15:44:10Z</dc:date>
    </item>
  </channel>
</rss>

