1.安装环境
安装cuda和cudnn,笔者使用版本
cuda: cuda_11.6.0_511.23_windows.exe
cudnn: cudnn-windows-x86_64-8.5.0.96_cuda11-archive.zip
安装后测试
nvidia-smi
- C:\Users\#####>nvidia-smi
- Fri Aug 12 18:10:49 2022
- +-----------------------------------------------------------------------------+
- | NVIDIA-SMI 511.23 Driver Version: 511.23 CUDA Version: 11.6 |
- |-------------------------------+----------------------+----------------------+
- | GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
- | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
- | | | MIG M. |
- |===============================+======================+======================|
- | 0 NVIDIA GeForce ... WDDM | 00000000:01:00.0 Off | N/A |
- | N/A 44C P0 31W / N/A | 0MiB / 16384MiB | 0% Default |
- | | | N/A |
- +-------------------------------+----------------------+----------------------+
-
- +-----------------------------------------------------------------------------+
- | Processes: |
- | GPU GI CI PID Type Process name GPU Memory |
- | ID ID Usage |
- |=============================================================================|
- | No running processes found |
- +-----------------------------------------------------------------------------+
nvcc -V
- C:\Users\#########>nvcc -V
- nvcc: NVIDIA (R) Cuda compiler driver
- Copyright (c) 2005-2021 NVIDIA Corporation
- Built on Fri_Dec_17_18:28:54_Pacific_Standard_Time_2021
- Cuda compilation tools, release 11.6, V11.6.55
- Build cuda_11.6.r11.6/compiler.30794723_0
-
- C:\Users\xiaodong>
安装anaconda pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge
2.下载代码
git clone https://github.com/WongKinYiu/yolov7.git
安装环境
在yolov7路径下
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
下载权重文件,在yolov7路径下新建文件夹weights,并复制其中
下载路径在github上,点击蓝色部分即可下载
3.制作数据集
将标注好的图片和文件放在E:\yolov7\data\VOCdevkit\VOC2007\images下
文件夹放置图片和标注信息
制作数据配置文件data/daming.yaml,参考coco.yaml
如下daming.yaml
- # COCO 2017 dataset http://cocodataset.org
-
- # download command/URL (optional)
-
-
- # train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
- train: E:\yolov7\data\VOCdevkit\VOC2007\images\train\images\
- val: E:\yolov7\data\VOCdevkit\VOC2007\images\val\images\
- test: E:\yolov7\data\VOCdevkit\VOC2007\images\test\images\
-
- # number of classes
- nc: 3
-
- # class names
- names: [ 'jiajing', 'hairui', 'wanli', ]
4.训练数据集
可以复制train.py修改为train_daming.py
4.1修改权重和数据路径,其他参数酌情修改
4.2训练命令
(torch) E:\yolov7>python train_daming.py --workers 1 --device 0 --batch-size 8 --data data/daming.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights weights/yolov7.pt --name yolov7
5.测试训练出的模型
5.1 测试图片
(torch) E:\yolov7>python detect.py --weights E:\yolov7\runs\train\yolov715\weights\best.pt --conf 0.25 --img-size 640 --source 028.jpg
结果:E:\yolov7\runs\detect\exp19\028.jpg
5.2测试视频
(torch) E:\yolov7>python detect.py --weights E:\yolov7\runs\train\yolov715\weights\best.pt --conf 0.25 --img-size 640 --source daming.mp4
结果:E:\yolov7\runs\detect\exp20\daming.mp4
5.3测试摄像头
(torch) E:\yolov7>python detect.py --weights E:\yolov7\runs\train\yolov715\weights\best.pt --conf 0.25 --img-size 640 --source 0
结果:E:\yolov7\runs\detect\exp21\0.mp4