我有一个量化后的tflite模型,希望在Nvidia Jetson Nano上进行推理基准测试。我使用tf.lite.Interpreter()方法进行推理。由于CPU和GPU的推理时间相同,该过程似乎没有在GPU上运行。
有没有办法在Python中使用GPU运行tflite模型?
我尝试通过设置tf.device()方法来强制使用GPU,但仍然无效。官方文档中提到了委托(delegates)以加速GPU计算,但我似乎找不到任何与Python相关的信息。
with tf.device('/device:GPU:0'):
interpreter = tf.lite.Interpreter(model_path="model.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.uint8)
interpreter.set_tensor(input_details[0]['index'], input_data)
start_time = time.time()
interpreter.invoke()
elapsed_time = time.time() - start_time
print(elapsed_time)
output_data = interpreter.get_tensor(output_details[0]['index'])