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

dro*_*oid 5 python tensorflow tensorflow-lite nvidia-jetson

我有一个量化的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)

小智 1

根据最近的帖子,它似乎可以在 jetson nano 上使用 \n但它看起来像是自定义构建,请尝试使用它而不是 tensorflow lite。

\n

如果您已经安装了它,可以询问 nvidia 开发人员该版本是否支持 GPU。

\n

或者您可以通过这种方式安装 nvidia 自定义张量流。

\n

Python 3.6+JetPack4.4

\n
sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran\nsudo apt-get install python3-pip\nsudo pip3 install -U pip\nsudo pip3 install -U pip testresources setuptools numpy==1.16.1 future==0.17.1 mock==3.0.5 h5py==2.9.0 keras_preprocessing==1.0.5 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11\n# TF-2.x\n$ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 tensorflow==2.2.0+nv20.8\n# TF-1.15\n$ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 \xe2\x80\x98tensorflow<2\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n

Python 3.6+JetPack4.3

\n
$ sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev\n$ sudo apt-get install python3-pip\n$ sudo pip3 install -U pip\n$ sudo pip3 install -U numpy grpcio absl-py py-cpuinfo psutil portpicker six mock requests gast h5py astor termcolor protobuf keras-applications keras-preprocessing wrapt google-pasta\n# TF-2.x\n$ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v43 tensorflow==2.1.0+nv20.3\n# TF-1.15\n$ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v43 tensorflow==1.15.2+nv20.3\n
Run Code Online (Sandbox Code Playgroud)\n