安装tensorRT之后,官网有很多小的sample,也就是使用的案例,可以按照教程运行一下这些案例来入门如何使用tensorRT。我再使用其自带的sample时,发现也有一些小问题,这里记录一下运行的过程和遇到的一些问题以及解决方法。
环境:
docker中的Ubuntu18.04(虽然是容器,但是这里使用的操作和普通机器也没有区别,使用普通机器的也可以参考)
conda 10.0.130.
tensorRT6.0.15-cuda10.0
tensorflow-gpu 1.14
1.首先是sample的介绍
https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-601/tensorrt-sample-support-guide/index.html
我安装的是tensorRT6.0.1.5,这里是官网6.0.1的sample介绍。官网介绍上说使用tnsorRT时 “网络可以直接从NVCaffe导入,也可以通过UFF或ONNX格式从其他框架导入。也可以通过实例化各个图层并直接设置参数和权重,使用C ++或Python API以编程方式创建它们。”
我的理解是,一般会将各种框架如tensorflow训练得到的模型存储处理后,转换为tensorRT规定的几种格式,然后将转换后的文件使用tensorRT解析推理。这些案例就是各种不同的导入文件,不同框架的使用的sample,可以用它来学习如何使用tensorRT。
这里我打算用tensorflow使用tensorrt,因此选择的sample是26,一个使用tensorflow训练的小网络,从训练模型到存储模型,到转换存储文件再使用tensorRT推理的sample。
“Hello World” For TensorRT Using TensorFlow And Python | end_to_end_tensorflow_mnist | An end-to-end sample that trains a model in TensorFlow and Keras, freezes the model and writes it to a protobuf file, converts it to UFF, and finally runs inference using TensorRT. |
点击跳转名字到介绍