1. 源由
YOLO(You Only Look Once)是一种实时目标检测算法,由 Joseph Redmon 等人提出。它是一种基于深度学习的检测方法,可以在图像和视频中快速识别和定位多个目标。YOLO 的设计理念和实现方法使其具备极高的速度和精度,广泛应用于安全监控、自动驾驶、医疗影像分析等领域。
2. 特点&原理
YOLO 算法的主要特点和工作原理:
-
单次检测:YOLO 与传统的目标检测方法不同,它将目标检测问题视为一个回归问题,直接从图像生成边界框和类别概率。整个过程只需在图像上通过一次卷积神经网络(CNN),这极大地提高了检测速度。
-
网格划分:YOLO 将图像划分成 SxS 的网格,每个网格负责检测一个目标的存在,并预测该目标的边界框和类别。这样就可以避免候选区域生成的复杂步骤。
-
边界框预测:每个网格预测一定数量的边界框及其置信度分数,置信度分数结合了边界框与实际目标的重合度以及类别的概率。这使得模型能够在预测结果中自动筛选出高置信度的检测结果。
-
高速处理:由于 YOLO 只需进行一次卷积操作,因此在硬件支持良好的情况下,可以实现实时检测(例如,每秒检测几十甚至上百帧)。这对于实时应用非常重要。
-
改进的 YOLO 版本:YOLO 系列模型从最初的 YOLO 到 YOLOv8,不断提升了检测精度和速度。每个版本在网络结构和损失函数等方面进行了改进,以提高检测的准确率,减少误报和漏报。
目前,YOLO 是一种具有高效检测性能的深度学习目标检测算法,非常适合需要实时检测的应用场景。
3. 性能参数
-
交并比(Intersection over Union,IoU):IoU 是一种度量,用于量化预测的边界框和真实边界框之间的重叠。它在评估目标定位的准确性中起着至关重要的作用。
-
平均精度(Average Precision,AP):AP 计算的是精确率-召回率曲线下的面积,为模型的精确率和召回率性能提供了一个单一的值。
-
平均平均精度(Mean Average Precision,mAP):mAP 扩展了 AP 的概念,通过计算多个类别的平均 AP 值,适用于多类别目标检测场景,提供对模型性能的全面评估。
-
精确率和召回率( Precision and Recall):精确率衡量在所有正预测中,真实正例所占的比例,评估模型避免假阳性的能力。召回率则衡量在所有实际正例中,模型正确检测到的比例,反映模型检测所有类别实例的能力。
-
F1 分数:F1 分数是精确率和召回率的调和平均值,提供了一个平衡的模型性能评估,兼顾假阳性和假阴性。
Model | YAML | Size (pixels) | mAPval 50-95 | Speed CPU ONNX (ms) | Speed A100 TensorRT (ms) | Params (M) | FLOPs (B) |
---|---|---|---|---|---|---|---|
yolov5nu.pt | yolov5n.yaml | 640 | 34.3 | 73.6 | 1.06 | 2.6 | 7.7 |
yolov5su.pt | yolov5s.yaml | 640 | 43.0 | 120.7 | 1.27 | 9.1 | 24.0 |
yolov5mu.pt | yolov5m.yaml | 640 | 49.0 | 233.9 | 1.86 | 25.1 | 64.2 |
yolov5lu.pt | yolov5l.yaml | 640 | 52.2 | 408.4 | 2.50 | 53.2 | 135.0 |
yolov5xu.pt | yolov5x.yaml | 640 | 53.2 | 763.2 | 3.81 | 97.2 | 246.4 |
yolov5n6u.pt | yolov5n6.yaml | 1280 | 42.1 | 211.0 | 1.83 | 4.3 | 7.8 |
yolov5s6u.pt | yolov5s6.yaml | 1280 | 48.6 | 422.6 | 2.34 | 15.3 | 24.6 |
yolov5m6u.pt | yolov5m6.yaml | 1280 | 53.6 | 810.9 | 4.36 | 41.2 | 65.7 |
yolov5l6u.pt | yolov5l6.yaml | 1280 | 55.7 | 1470.9 | 5.47 | 86.1 | 137.4 |
yolov5x6u.pt | yolov5x6.yaml | 1280 | 56.8 | 2436.5 | 8.98 | 155.4 | 250.7 |
4. 对比视频
- Extreme Mountain Biking FPV Drone Chasing | detectnet | ssd-mobilenet-v2
Extreme Mountain Biking FPV Drone Chasing | detectnet | ssd-mobilenet-v2
- Extreme Mountain Biking FPV Drone Chasing | yolo | v5nu/v8n/v8s/11n
Extreme Mountain Biking FPV Drone Chasing | yolo | v5nu/v8n/v8s/11n
5. 安装
Step 01:r35.6 JetPack 5.1.4安装
略,请参考《Linux 36.3@Jetson Orin Nano之系统安装》。
Step 02:基本工具
- jtop性能
$ sudo apt install python3-pip
$ sudo pip3 install -U jetson-stats
$ sudo systemctl restart jtop.service
- 1
- 2
- 3
- 简单工具
$ sudo apt-get install aptitude tree mpv
- 1
Step 03:共享文件
安装软件
$ sudo apt-get install samba
- 1
修改配置
$ sudo vi /etc/samba/smb.conf
- 1
主要修改内容如下:
# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
[homes]
comment = Home Directories
browseable = no
# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
create mask = 0700
# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
directory mask = 0700
# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
valid users = %S
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
新增用户&密码
$ sudo smbpasswd -a daniel
- 1
Step 04:安装NVIDIA软件
$ wget https://developer.download.nvidia.cn/compute/redist/jp/v512/pytorch/torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl
$ sudo pip3 install torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl
$ wget https://nvidia.box.com/shared/static/zostg6agm00fb6t5uisw51qi6kpcuwzd.whl -O onnxruntime_gpu-1.17.0-cp38-cp38-linux_aarch64.whl
$ sudo pip install onnxruntime_gpu-1.17.0-cp38-cp38-linux_aarch64.whl
- 1
- 2
- 3
- 4
Step 05:编译安装torchvision
$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libopenblas-dev libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python3-pip libopenblas-base libopenmpi-dev libomp-dev
$ git clone --branch v0.16.1 [email protected]:pytorch/vision.git torchvision
$ cd torchvision/
$ export BUILD_VERSION=0.16.1
$ sudo python3 setup.py install --user
$ cd ..
- 1
- 2
- 3
- 4
- 5
- 6
- 7
Step 06:安装yolo
$ sudo pip3 install ultralytics
- 1
Step 07:下载模型
$ wget https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt
- 1
- 转换到各种格式(NVIDIA TensorRT用engine格式)
$ yolo export model=yolo11n.pt format=engine
or
$ yolo export model=yolov11n.pt format=onnx
- 1
- 2
- 3
注:如果存在网络问题,尤其是大陆用户,请使用代理export https_proxy=http://192.168.1.10:808
。
Step 08:运行yolo
$ sudo python3 -m pip install --upgrade certifi
$ sudo pip3 install --no-cache-dir onnx>=1.12.0
$ sudo pip3 install --no-cache-dir onnxslim
$ sudo pip3 install --no-cache-dir onnxruntime
$ sudo pip install numpy==1.23.5
- 1
- 2
- 3
- 4
- 5
Step 09:yolo指南示例
参考:YOLO - Convert Model to TensorRT and Run Inference
$ yolo predict model=yolo11n.engine source='https://ultralytics.com/images/bus.jpg'
- 1
若网络环境不好,请使用下面命令分解执行:
$ wget https://ultralytics.com/images/bus.jpg -O bus.jpg
$ yolo predict model=yolo11n.engine source='bus.jpg'
- 1
- 2
Step 10:视频应用示例
$ yolo predict model=yolo11n.engine source='video.mp4' show=True
- 1
注:video.mp4
文件可以根据各自应用来进行安排。另外,相关预测文件可以在当前目录run
下找到。
6. 参考资料
【1】Linux 36.3@Jetson Orin Nano之系统安装
【2】Linux 36.2@Jetson Orin Nano之基础环境构建
【3】ubuntu22.04@Jetson Orin Nano安装&配置VNC服务端
评论记录:
回复评论: