TensorRT
使用TensorRT
Jetson Nano的官方文档中给我们推荐了二个例子,其中一个使用Tensor RT做物品识别的例子。具体的可以参考英伟达jetson-inference例子。跑通这个例子需要的模型就大概1G以上,所以这个例子的大部分并没有放到SD卡上(SD卡上只有运行这个模型所需要的TensorRT)。悲剧的是存放这些模型的服务器被墙了,所以只能将之前下载好的包远程传输到对应的下载目录下。
首先如果您没有安装git和cmake,先安装它们
sudo apt-get install git cmake
接着从git上克隆jetson-inference 库
git clone https://github.com/dusty-nv/jetson-inference
进入文件夹jetson-inference
cd jetson-inference
当使用git clone下来的工程中带有submodule时,初始的时候,submodule的内容并不会自动下载下来的,此时,只需执行如下命令:git submodule update --init --recursive
,即可将子模块内容下载下来后工程才不会缺少相应的文件。
git submodule update --init
配置cmake,cmake的介绍可以参考我的博文。这里我没有用科学上网的方式下载模型,我直接把模型用FileZilla远程传入nano。操作如下:
1)编辑jetson-inference/CMakePrebuild.sh。把./download-models.sh注释掉,(前面加个#注释)
2)把模型远程传输到data/networks目录。
新建build文件夹,用来存放编译文件
mkdir build #创建build文件夹
进入
cd build #进入build
运行cmake
cmake ../ #运行cmake,它会自动执行上一级目录下面的 CMakePrebuild.sh
然后在此目录执行解压:
for tar in *.tar.gz; do tar xvf $tar; done
cmake成功后,就需要编译了
进入build文件夹
cd jetson-inference/build
开始编译
make (或者make -j4) //注意:(在build目录下)
// 这里的 make 不用 sudo
// 后面 -j4 使用 4 个 CPU 核同时编译,缩短时间
如果编译成功,会生成下列文件夹结构
|-build
\aarch64 (64-bit)
\bin where the sample binaries are built to
\include where the headers reside
\lib where the libraries are build to
\armhf (32-bit)
\bin where the sample binaries are built to
\include where the headers reside
\lib where the libraries are build to
测试
cd jetson-inference/build/aarch64/bin
./imagenet-console ./images/bird_0.jpg output_wyk.jpg
执行等待许久后出现如下(第一次需要很长时间,后面执行就会很快):
识别结果
当然nano中的文件也可以传到pc上查看
更多学习请看官方文档:
官方Demo
官方TensorRT教程