一、环境描述:
1、pytorche版本: 19+cpu
2、python版本:3.8
3、操作系统 win10
4、显卡,主板集成显卡
二、配置运行环境
1、代码地址:GitHub:https://github.com/argusswift/YOLOv4-pytorch
2、权重文件下载
3、数据集下载
Pascal VOC数据集:http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar 、
http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
将三个压缩包解压后放到代码目录的data文件夹下
|——data
| |——VOCtest-2007
| |——VOCdevkit
| |——VOC2007
| |——Annotations
| |——ImageSets
| |——JPEGImages
| |——SegmentationClass
| |——SegmentationObjct
| |——VOCtrainval-2007
| |——VOCdevkit
| |——VOC2007
| |——Annotations
| |——ImageSets
| |——JPEGImages
| |——SegmentationClass
| |——SegmentationObjct
| |——VOCtrainval-2012
| |——VOCdevkit
| |——VOC2012
| |——Annotations
| |——ImageSets
| |——JPEGImages
| |——SegmentationClass
| |——SegmentationObjct
| |—— CBAM.png
| |—— det-result.jpg
| |—— heatmap.jpg
| |—— modelsize.jpg
| |—— results.jpg
| |—— SEnet.jpg
4、安装依赖库
1)pip install -r requirements.txt
2)安装apex
git clone https://github.com/NVIDIA/apex
cd apex
python setup.py install
这里有个问题。我的机器是windows系统,没有n显卡,安装的时候会报一个错误。
Warning: Torch did not find available GPUs on this system.
If your intention is to cross-compile, this is not an error.
By default, Apex will cross-compile for Pascal (compute capabilities 6.0, 6.1, 6.2),
Volta (compute capability 7.0), Turing (compute capability 7.5),
and, if the CUDA version is >= 11.0, Ampere (compute capability 8.0).
If you wish to cross-compile for a single specific architecture,
export TORCH_CUDA_ARCH_LIST="compute capability" before running setup.py.
这里说明,需要运行export TORCH_CUDA_ARCH_LIST="compute capability"即可
由于是在windows下,只需要在环境变量中增加
TORCH_CUDA_ARCH_LIST="compute capability" 就可以搞定
三、处理数据集
使用utils/voc.py(在pycharm中找到voc.py这个文件,右键选择Run ‘voc’)转换pascal voc *.xml格式到.txt格式(img_path xmin0 ymin0 xmax0 ymax0 class0, xmin1 ymin1 xmax1 ymax1 class1,……)
运行后data目录下多了两个文件test_annotation.txt和train_annotation.txt。
四、修改配置文件:
查看config/yolov4_config.py中“DATA_TYPE”参数 = VOC。
模型原先设置的是CoordAttention-YOLOv4,因为下载了yolov4的权重,所以把模型改成了YOLOv4,即MODEL_TYPE={"TYPE": "YOLOv4"}。
注:参考Pytorch版YOLOv4训练步骤(一)_夏至扬光的博客-CSDN博客