Closed powerpzt closed 3 years ago
import numpy as np import time import multiprocessing as mp import tflite_runtime.interpreter as tflite armnn_delegate = tflite.load_delegate( library="./libarmnnDelegate.so", options={"backends": "CpuAcc,CpuRef", "logging-severity":"DEBUG"}) def load_model(model_path, armnn_delegate): interpreter = tflite.Interpreter(model_path=model_path, experimental_delegates=[armnn_delegate]) interpreter.allocate_tensors() return interpreter model_path = "./ssdlite_mobilenet_v2_coco.tflite" interpreter = load_model(model_path, armnn_delegate) input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() input_shape = input_details[0]['shape'] input_index = input_details[0]['index'] input_data = np.array(np.ones(input_shape), dtype=np.float32) def execute(): print("CPU") interpreter.set_tensor(input_index, input_data) start_time=time.time() print(start_time) interpreter.invoke() print("CPU --- %s seconds ---" % ((time.time()-start_time)/100)) output_data = interpreter.get_tensor(output_details[0]['index']) print(output_data) p1 = mp.Process(target=execute) #p2 = mp.Process(target=execute) p1.start() #p2.start()
Hi, I used this code of tflite delegate with python binding. The result is this.
Info: ArmNN v25.0.0 Info: Initialization time: 6.17 ms INFO: TfLiteArmnnDelegate: Created TfLite ArmNN delegate. CPU 1624342939.6050785
When using multiprocessing, it waits after print(start_time) eternally. Maybe interpreter.invoke() does not reply.
If i use the code normally or with threading, it works well. In addition, the same code on desktop works well, too
import numpy as np import time import multiprocessing as mp import tensorflow.lite as tflite def load_model(model_path): interpreter = tflite.Interpreter(model_path=model_path) interpreter.allocate_tensors() return interpreter model_path = 'ssd_mobilenet_v2_coco.tflite' interpreter = load_model(model_path) input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() input_shape = input_details[0]['shape'] input_index = input_details[0]['index'] input_data = np.array(np.ones(input_shape), dtype=np.float32) def execute(): print("CPU") interpreter.set_tensor(input_index, input_data) start_time=time.time() print(start_time) interpreter.invoke() print("CPU --- %s seconds ---" % ((time.time()-start_time)/100)) output_data = interpreter.get_tensor(output_details[0]['index']) print(output_data) p1 = mp.Process(target=execute) p2 = mp.Process(target=execute) #p3 = mp.Process(target=execute) #p4 = mp.Process(target=execute) p1.start() p2.start() #p3.start() #p4.start()
CPU 1624342916.1923797CPU 1624342916.1952572 CPU --- 0.0010329008102416993 seconds --- CPU --- 0.0010196781158447266 seconds --- [[[-8.99108 -8.407066 -7.5616293 -9.077816 ] [-9.104538 -9.439804 -8.893764 -8.005322 ] [-8.853685 -8.000054 -9.184245 -8.621555 ] [-7.63076 -7.564349 -8.118874 -6.897669 ] [-8.256776 -7.657664 -7.289326 -9.266909 ] [-6.9567194 -9.266215 -9.2662115 -8.564189 ] [-9.266026 -6.9817686 -6.2814064 -8.547486 ] [-7.692247 -7.11787 -7.3582535 -8.933831 ] [-6.8463497 -8.767875 -9.676924 -6.9147243] [-9.266149 -6.541151 -7.3526998 -8.238716 ]]] [[[-8.99108 -8.407066 -7.5616293 -9.077816 ] [-9.104538 -9.439804 -8.893764 -8.005322 ] [-8.853685 -8.000054 -9.184245 -8.621555 ] [-7.63076 -7.564349 -8.118874 -6.897669 ] [-8.256776 -7.657664 -7.289326 -9.266909 ] [-6.9567194 -9.266215 -9.2662115 -8.564189 ] [-9.266026 -6.9817686 -6.2814064 -8.547486 ] [-7.692247 -7.11787 -7.3582535 -8.933831 ] [-6.8463497 -8.767875 -9.676924 -6.9147243] [-9.266149 -6.541151 -7.3526998 -8.238716 ]]]
Is there any way to using multiprocessing with tflite interpreter?
Hi @powerpzt
at the moment there's no way to use multiprocessing with the tflite delegate. It has been added to out backlog but there is no ETA.
Best regards, Mike
Hi, I used this code of tflite delegate with python binding. The result is this.
When using multiprocessing, it waits after print(start_time) eternally. Maybe interpreter.invoke() does not reply.
If i use the code normally or with threading, it works well. In addition, the same code on desktop works well, too
Is there any way to using multiprocessing with tflite interpreter?