一、软硬件环境
1.1 Jetson环境
Jetson Nano 4G B01
Jetpack版本 5.1
DeepStream 5.1
Jetpack到官网下载,下载后在x86主机安装BanlaEcher烧录软件,注意不要用win32,烧录Jetpack会出问题 ! ! !
1.2 x86深度学习环境
操作系统:Ubuntu 20.04 桌面版
CUDA版本:CUDA-10.2
Pytorch版本:1.7
YOLOv5版本:YOLOv5-v5.0
1.3 Jetson软件环境
- 查看Jetpack版本:
cat /etc/nv_tegra_release
- 更新镜像源
sudo apt update
sudo apt upgrade --fix-missing
备份原始来源:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
打开编辑和替换:
sudo gedit /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
最后一次更新:
sudo apt-get update
二. TensorRT配置
1.下载YOLOv5 v5.0:
git clone -b v5.0 https://github.com/ultralytics/yolov5.git
2.下载与YOLOv5 v5.0对应的TensorRT版本:
git clone -b yolov5-v5.0 https://github.com/wang-xinyu/tensorrtx.git
3.下载YOLOv5 v5.0的yolov5s.pt模型:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
4.将tensorrtx中的gen_wts.py文件复制到yolov5目录下:
cp {tensorrtx}/yolov5/gen_wts.py {ultralytics}/yolov5
5.进入yolov5目录下:
cd {ultralytics}/yolov5
// a file ‘yolov5s.wts’ will be generated.
6.生成wts文件:
python gen_wts.py -w yolov5s.pt -o yolov5s.wts
运行时发现错误:
ModuleNotFoundError: No module named numpy.testing.nosetester
安装numpy新版、scipy新版、以及pandas新版,sklearn最新版
pip3 install --user --upgrade XXX
下一个安装:
'''这个对我有用(3步)'''
sudo apt-get install gfortran
sudo apt-get update
sudo apt-get install -y build-essential libatlas-base-dev
'''这个对我没用'''
sudo apt-get install python3-scipy
进入到tensorrtx的yolov5目录下:
cd {tensorrtx}/yolov5/
如果模型是自定义数据集训练的,需要更改CLASS_NUM:
// update CLASS_NUM in yololayer.h if your model is trained on custom dataset
在 tensorrtx/yolov5/ 目录下建立build文件准备编译
mkdir build && cd build
把前面生成的.wts权重文件放入自己建立的build目录下:
cp {ultralytics}/yolov5/yolov5s.wts {tensorrtx}/yolov5/build
生成makefile配置文件:
cmake ..
开始编译:
make
三. TensorRT模型生成
3.1 engine文件生成说明
以下为统一申报规范:
生成engine文件:
sudo ./yolov5 -s [.wts] [.engine] [n/s/m/l/x/n6/s6/m6/l6/x6 or c/c6 gd gw] // serialize model to plan file
加载engine文件并进行推理:
sudo ./yolov5 -d [.engine] [image folder] // deserialize and run inference, the images in [image folder] will be processed.
3.2 YOLOv5生成engine模型
生成yolov5s对应类型的engine文件
// For example yolov5s
sudo ./yolov5 -s yolov5s.wts yolov5s.engine s
加载…/samples下面的示例图片进行预测:
sudo ./yolov5 -d yolov5s.engine ../samples
自定义数据集还可以对yolov5.yaml设置模型尺度(深度和宽度):
// For example Custom model with depth_multiple=0.17, width_multiple=0.25 in yolov5.yaml
对yolov5s设置engine文件模型宽度和深度:
sudo ./yolov5 -s yolov5_custom.wts yolov5.engine c 0.17 0.25
加载…/samples进行预测:
sudo ./yolov5 -d yolov5.engine ../samples
文章出处登录后可见!
已经登录?立即刷新