实现过程参考:
环境安装
- 创建并激活一个conda环境
conda create -n yolov6 python=3.8
conda activate yolov6
- 安装pytorch
conda
# CUDA 10.2(我用的这个)
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch
# CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cpuonly -c pytorch
wheel
# CUDA 11.1
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 10.2(我用的这个)
pip install torch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0
# CPU only
pip install torch==1.8.0+cpu torchvision==0.9.0+cpu torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
安装YOLOv6
git clone https://github.com/meituan/YOLOv6
cd YOLOv6
pip install -r requirements.txt
验证安装
- 下载权重文件
-
- 从官方 YOLOv6 Github 仓库中下载最新的模型权重;
- 使用 wget 下载(注意下载链接需要更新到最新的版本号,确认是最近发布的模型)
pip install wget
# 注意确认以下链接中的版本号是否为最新(这点很重要,官网教程是0.3.0,但我用的时候已经是0.4.0,改了就没有报错!)
#wget https://github.com/meituan/YOLOv6/releases/download/0.3.0/yolov6n.pt(官网教程的)
wget https://github.com/meituan/YOLOv6/releases/download/0.4.0/yolov6n.pt
mkdir weights
mv yolov6n.pt weights/yolov6n.pt
我安装的时候是4.0,从这里看:Releases · meituan/YOLOv6 · GitHub
- 推理验证
python tools/infer.py --weights weights/yolov6n.pt --source data/images/
# 可选参数
# --device 0 *使用的计算资源,包括cuda, cpu等,默认为0
# --name exp *用于指定source图像推理结果可视化的保存文件夹
# --view-img *使用该参数表示在屏幕上显示检测结果,默认为False
# --conf_thres 0.4 *置信度阈值,默认为0.4
就实现啦!