小编dro*_*oid的帖子

无法使用Python在GPU(Jetson Nano)上运行tflite模型

我有一个量化的tflite模型,我想以此为基准来对Nvidia Jetson Nano进行推理。我使用tf.lite.Interpreter()方法进行推断。该过程似乎未在GPU上运行,因为CPU和GPU上的推理时间相同。

有什么方法可以使用Python在GPU上运行tflite模型吗?

我试图通过设置tf.device()方法来强制使用GPU,但仍然无法正常工作。官方文档中有一些所谓的用于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'])
Run Code Online (Sandbox Code Playgroud)

python tensorflow tensorflow-lite nvidia-jetson

5
推荐指数
1
解决办法
504
查看次数