最近需要用Jetson Nano实现Yolov4-tiny实时检测,这篇文章汇总记录下自己的环境配置过程。
本部分参考NVIDIA Jetson Nano官方教程
首先到NVIDIA官方下载Jetpack镜像文件,选择SD卡方式下载到本地:
之后格式化内存卡,本人使用的是SD Card Formatter
然后将下载的镜像烧写至内存卡,此处使用的是balenaEtcher
至此,就可以将SD卡插入Nano按照引导进行系统的设置了。
注意:
①Nano是Arm64架构,在源和软件的安装时需注意。
②也可以使用SDK manager方式进行系统安装。
③使用5V4A的DC接口时需用跳线帽将J48相连。
④为了远程连接的方便,建议设置为开机无需密码即可进入桌面(系统-首选项-桌面共享-勾选“允许其他人查看您的桌面”、取消“必须为本机器的每次访问进行确认”、勾选“要求远程用户输入此密码”并设置密码)
本部分参考Github中Pyrestone贡献的jetson-fan-ctl
Nano本身仅有一个散热鳍片进行被动散热,这在我们运行神经网络等应用时是不够的,可能造成死机,因此有必要添加一个散热风扇进行主动散热。
物理连接较为简单,即用螺丝将风扇固定在鳍片上的四个固定孔即可
接下来配置自动调速的程序:
①进行项目拷贝:
git clone https://github.com/Pyrestone/jetson-fan-ctl.git
②安装:
sudo ./install.sh
③调整参数:
sudo gedit /etc/automagic-fan/config.json
修改其中的:
{
"FAN_OFF_TEMP":20, #风扇关闭温度
"FAN_MAX_TEMP":50, #风扇全速温度
"UPDATE_INTERVAL":2, #转速更新间隔(秒)
"MAX_PERF":1 #大于零时通过最大化CPU和GPU时钟最大化性能
}
④部署设置:
sudo service automagic-fan restart
⑤查看状态:
sudo service automagic-fan status
注:查看风扇转速及系统温度可通过Jtop
本部分参考NVIDIA Jetson Nano官方教程
首先使用MicroUSB线将Nano与主机(我的为Win10系统)进行连接,打开Windows的Powershell,输入
ssh nano的用户名@192.168.55.1
即可在powershell界面打开终端控制Nano
本部分参考亚博科技Nano VNC配置(可能需要密码权限,侵删)及博客《笔记本通过网线连接并控制工控机》
使用【三】中的方法仅能实现对Nano的Terminal的使用,对于初学者进行部分配置不如图形界面来的方便,因此使用VNC进行远程控制,这在无显示屏给Nano用和进行外场试验时较为方便。
安装vnc(vino)
sudo apt install vino
Enable VNC
sudo ln -s ../vino-server.service /usr/lib/systemd/user/graphical-session.target.wants
配置VNC
gsettings set org.gnome.Vino prompt-enabled false
gsettings set org.gnome.Vino require-encryption false
打开文件
sudo gedit /usr/share/glib-2.0/schemas/org.gnome.Vino.gshema.xml
在最后前添加:
<key name='enabled' type='b'>
<summary>Enable remote access to the desktop</summary>
<description>
If ture, allows remote access to the desktop via the PFB
protocol. Users on remote machines may then connect to the
desktop using a VNC viewer.
</description>
<default>false</default>
</key>
设置为Gnome编译模式
sudo glib-compile-schemas /usr/share/glib-2.0/schemas
之后便可以进行手动启动:
/usr/lib/vino/vino-server
下面设置vino为开机自启:
gsettings set org.gnome.Vino enabled ture
mkdir -p ~/.config/autostart
sudo gedit ~/.config/autostart/vino-server.desktop
在文件中添加:
[Deskop Entry]
Type=Application
Name=Vino VNC server
Exec=/usr/lib/vino/vino-server
NoDisplay=true
至此,在处于同一局域网的Windows系统的电脑上使用VNC Viewer即可连接Nano,只需知道Nano的IP地址以及密码。
运行至此,已经可以通过交换机实现VNC远程连接,接下来通过配置IP实现通过网线直连笔记本-Nano控制。
在笔记本打开“通知-网络-网络和Internet设置-更改适配器设置-以太网(右键)-属性-IPv4-属性-使用下面的IP地址”,设置主机和DNS的IP地址
接下来进行Nano的设置,即新建一个以太网与笔记本相对应:
“网络-编辑连接-添加-以太网新建-IPv4设置-添加”
方式改为手动
地址处添加:地址为笔记本设置的DNS,网关为笔记本设置IP
之后将笔记本与Nano连接,Nano切换到新配置的模式,再打开VNC Viewer即可实现网线直连。
本部分参考亚博科技Nano SSH远程传文件(可能需要密码权限,侵删)
主机端使用的软件是WinSCP,打开后输入IP等信息即可进行跨系统文件传输。
本部分参考博客jetson nano安装jtop
首先配置支持环境:
sudo apt-get install git cmake
sudo apt-get install python3-dev
sudo aot-get install libhdf5-serial-dev hdf5-tools
sudo apt-get install libatlas-base-dev gfortran
然后安装jtop
pip3 install jetson-stats
运行jtop
jtop
注:安装时好像并没装完环境就可运行jtop,在此不细究
①检查CUDA
在镜像中CUDA是安装好了的,但并没有将路径写入环境变量。
所以打开文本
sudo gedit ~/.bashrc
在最后添加:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
之后生效:
source ~/.bashrc
此时执行:
nvcc -V
即可查看CUDA信息
②OpenCV
pkg-config opencv4 --modversion
可查看版本号
③cuDNN
cuDNN通过运行例子来实现。
cd /usr/src/cudnn_samples_v8/mnistCUDNN #例子路径
sudo make #编译
./mnisiCUDNN #执行
我在编译时报错:fatal error: FreeImage.h: No such file or directory
解决方法:
sudo apt-get install libfreeimage3 libfreeimage-dev
sudo make clean #删除编译好的
sudo make #编译
./mnistCUDNN #运行
首先检测是否连接:
ls /dev/video*
软件Camorama(或Cheese)可以将USB摄像头输出到屏幕。
sudo apt-get install camorama
camorama #运行
sudo apt-get install cheese
cheese #运行
注:我是用的是罗技的C270
nvgstcapture-1.0 #摄像头启动
nvgstcapture-1.0 --prev-res=3 #预览分辨率(2-12)
nvgstcapture-1.0 --cus-prev-res=1920*1080 #自定义分辨率
q #关闭摄像头
j #截图保存至当前目录
首先确保已安装CUDA、OpenCV和cuDNN
下载项目:
git clone https://github.com/AlexeyAB/darknet.git
配置项目:
cd darknet
sudo gedit Makefile
将Makefile中相应修改为:
GPU=1
CUDNN=1
OPENCV=1
编译:
make -j4
放置权重文件:
用WinSCP将yolov4(-tiny).weights放到darknet目录中
#1.图片检测
./darknet detect cfg/yolov4.cfg yolov4.weights data/dog.jpg
./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights data/dog.jpg
./darknet detect cfg/yolov4-tiny.cfg yolov4-tiny.weights data/dog.jpg
./darknet detector test cfg/coco.data cfg/yolov4-tiny-cfg yolov4-tiny.weights data/dog.jpg
#2. 视频检测
./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov44.weights data/test.mp4 #自己上传mp4
./darknet detector demo cfg/coco.data cfg/yolov4-tiny.cfg yolov4-tiny.weights data/test.mp4
#3. 摄像头实时检测
./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights /dev/video1 #注意摄像头编号
./darknet detector demo cfg/coco.data cfg/yolov4-tiny.cfg yolov4-tiny.weights /dev/video1
#4.更改显示阈值
./darknet detect cfg/yolov4-tiny.cfg yolov4-tiny.weights data/dog.jpg -thresh 0.1