[Jetson Nano] Jetson-inference(Hello AI World) 爬坑指南

最近入手了Nvidia的Jetson Nano Developer Kit,在学习Jetson-inference项目时,遇到了不少问题,在这里整理一下作为记录。

项目地址:https://github.com/dusty-nv/jetson-inference

1. 从源码构建项目

获取源码和构建项目需要用到Git和CMake,官方提供的系统镜像已经预置了Git,CMake需要手动安装。

安装之前需要先更新一下,否则可能会安装不上。

$ sudo apt update
$ sudo apt upgrade
$ sudo apt-get install cmake

安装jetson-inference

$ git clone https://github.com/dusty-nv/jetson-inference
$ cd jetson-inference
$ git submodule update --init

配置并编译

$ mkdir build
$ cd build
$ cmake ../

配置过程中,可能会报网络连接失败之类的错误,暂不理会,等待cmake完成后既可以编译和安装了。

$ make
$ sudo make install

编译完成后会生成如下目录结构

|-build 
    \aarch64 
       \bin        二进制文件(示例程序和图像就在此路径下)
       \include    头文件
       \lib        库文件

2. 使用ImageNet对图像进行分类

首先进入bin目录下,运行控制台程序 imagenet-console

$ cd jetson-inference/build/aarch64/bin
$ ./imagenet-console orange_0.jpg output_0.jpg

首次运行应该会报一个段错误,具体内容如下:

[TRT] attempting to open engine cache file networks/bvlc_googlenet.caffemodel.2.1.GPU.FP16.engine
[TRT] cache file not found, profiling network model on device GPU
[TRT] device GPU, loading networks/googlenet.prototxt networks/bvlc_googlenet.caffemodel
[TRT] failed to retrieve tensor for Output "prob"
[TRT] device GPU, configuring CUDA engine
[TRT] device GPU, building FP16: ON
[TRT] device GPU, building INT8: OFF
[TRT] device GPU, building CUDA engine (this may take a few minutes the first time a network is loaded)
Segmentation fault

这个错误在ISSUES中有解答https://github.com/dusty-nv/jetson-inference/issues/308

错误原因是bvlc_googlenet.caffemodel 或googlenet.prototxt可能已损坏,需要手动下载替换。

$ cd jetson-inference/data/networks
$ wget https://raw.githubusercontent.com/BVLC/caffe/master/models/bvlc_googlenet/deploy.prototxt -O googlenet.prototxt
$ wget http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel -O bvlc_googlenet.caffemodel

然后重新配置并编译项目,这里官方给出的方案是删除build文件夹并重新配置编译。

经过测试这种方案并不能解决问题,估计是CMake时又下载了之前损坏的模型文件,把我们的修改给重置了。

所以,我们完成替换后直接进入build文件夹下重新配置编译。

$ cd jetson-inference/build
$ cmake ../
$ make 

然后再运行项目

$ cd jetson-inference/build/aarch64/bin
$ ./imagenet-console orange_0.jpg output_0.jpg

第一次运行时加载模型时间较长,耐心等待一会儿,程序运行完成后,使用如下命令,打开生成的图像文件。

$ display output_0.jpg 

output_0.jpg

为了测试方便,编写一个脚本文件用于运行程序并显示图像

$ vi run.sh

内容如下:

#!/bin/sh

./imagenet-console $1 output_$1

display output_$1

添加可执行权限,并运行脚本

$ chmod a+x ./run.sh
$ ./run.sh orange_0.jpg

脚本内容比较简单,后续在修改脚本,添加对其他几个例程的支持。

3. 运行实时摄像头识别演示

我使用的是CSI接口的树莓派V2摄像头,官方文档中提到CSI接口仅支持IMX219方案的摄像头,如果是几十块钱的CSI摄像头,就不要白费功夫了。而USB摄像头基本都是可用的。

加载不同模型来测试摄像头识别程序

$ ./imagenet-camera googlenet          
$ ./imagenet-camera alexnet

如果使用USB摄像头,需要修改imagenet-camera.cpp中的宏定义DEFAULT_CAMERA,然后重新编译。

4. 使用DetectNet定位对象坐标

这个例程注重第二个深度学习功能-检测对象,找到图像中的对象所在的位置,即提取边框。

从命令行中检测图像:

$ ./detectnet-console dog_1.jpg output_1.jpg coco-dog

运行报错如下:

[TRT] CaffeParser: Could not open file
[TRT] CaffeParser: Could not parse model file
[TRT] device GPU, failed to parse caffe network
device GPU, failed to load
detectNet -- failed to initialize.
detectnet-console: failed to initialize detectNet

根据消息内容可以确定,多半又是模型文件的问题,在Issues中也找到了类似的问题。

官方给出的解决方案是手动下载模型文件,并导入到data/networks目录下。

由于官方给出的是谷歌云盘的地址,一共1.3G左右,我把下载好的文件打包上传到百度云了,有需要的可以自行下载。

网盘链接:https://pan.baidu.com/s/1oBcCdGR-8s3wZX9fU-0iDg 
提取码:utyh 

下载完成后,把networks下的所有压缩包全部解压后,导入到jetson-inference/data/networks目录下。

重新运行实例程序,应该可以成功执行了。

 

 

 

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值