当前位置:   article > 正文

pytorch_yolov4代码训练数据集_yolov4原始代码下载

yolov4原始代码下载

环境
windows10+python3.7 + pytorch(cuda10)

1.准备工作

1.pytorch_YOLOv4代码下载:pytorch_YOLOv4
导入相应的模块:

  • numpy==1.18.2
    pip install numpy==1.18.2 -i https://pypi.douban.com/simple/
    下面类推。
  • torch==1.4.0
  • tensorboardX==2.0
  • scikit_image==0.16.2`
  • matplotlib==2.2.3
  • tqdm==4.43.0
  • easydict==1.9
  • Pillow==7.1.2
  • opencv_python
  • pycocotools

2.权重文件下载
yolov4.conv.137.pth
或者百度云下载 提取码 kcel

将权重文件放到/data下
在这里插入图片描述

2.数据集处理

coco数据集下载
coco2017数据集
http://images.cocodataset.org/zips/train2017.zip
http://images.cocodataset.org/annotations/annotations_trainval2017.zip

http://images.cocodataset.org/zips/val2017.zip
http://images.cocodataset.org/annotations/stuff_annotations_trainval2017.zip

http://images.cocodataset.org/zips/test2017.zip
http://images.cocodataset.org/annotations/image_info_test2017.zip

For coco dataset,you can use tool/coco_annotatin.py.
要修改一下代码,数据集的文件位置
在这里插入图片描述
最好要用绝对路径,你放在liunx上面跑代码你就知道了
在这里插入图片描述
处理对应的instances_train2017.json

运行coco_annotatin.py
在这里插入图片描述
会在data目录下生成train.txt文件

格式如下

# train.txt
image_path1 x1,y1,x2,y2,id x1,y1,x2,y2,id x1,y1,x2,y2,id ...
image_path2 x1,y1,x2,y2,id x1,y1,x2,y2,id x1,y1,x2,y2,id ...
...
...
  • 1
  • 2
  • 3
  • 4
  • 5

在运行一下coco_annotatain.py 生成val.txt

额外加的模块 在这边重点说明一下

在这里插入图片描述
将coco数据集的三个文件下载下来解压 成以下三个文件夹
在这里插入图片描述
修改coco_annotatain.py文件中的代码 第一次生成train.txt文件 修改如下

json_file_path = 'F:/car/dataset/annotations/instances_train2017.json'
images_dir_path = 'F:/car/dataset/train2017'
output_path = './data/train.txt'
  • 1
  • 2
  • 3

第二次生成val.txt文件,修改如下

json_file_path = 'F:/car/dataset/annotations/instances_val2017.json'
images_dir_path = 'F:/car/dataset/val2017'
output_path = './data/val.txt'
  • 1
  • 2
  • 3

运行两次coco_annotatain.py就可以生成train.txt和val.txt文件了。
在这里插入图片描述
如果遇到这个ModuleNotFoundError: No module named ‘pycocotools‘错误
https://blog.csdn.net/canpian7/article/details/115370766?spm=1001.2014.3001.5501

3.训练

需要在cfg.py中修改几个地方

Cfg.gpu = '0'
Cfg.pretrained = 'path to yolov4.conv.137.pth'
Cfg.dataset_dir = ' '
  • 1
  • 2
  • 3
Cfg.batch = 16  修改为合适的值
  • 1
Cfg.classes = 80 修改为实际值
  • 1

修改为第二步数据集处理生成的文件路径

Cfg.train_label = 'data/train.txt'
Cfg.val_label = 'data/val.txt'
  • 1
  • 2

修改中间结果路径,checkpoints和log的路径

Cfg.checkpoints = 'checkpoints'
Cfg.TRAIN_TENSORBOARD_DIR = 'log'
  • 1
  • 2

开始训练

因为修改了cfg.py所以这边就可以直接运行train.py了

python train.py
  • 1

在这里插入图片描述
总算是跑起来了

预测
python demo.py -cfgfile cfg/yolov4.cfg -weightfile weights/yolov4.weights -imgfile data/dog.jpg
  • 1

常见错误汇总

  1. ModuleNotFoundError: No module named ‘pycocotools‘
  2. FileNotFoundError: [Errno 2] No such file or directory: ‘train.txt’
  3. TypeError: expected str, bytes or os.PathLike object, not NoneType
  4. DefaultCPUAllocator: not enough memory: you tried to allocate 94633984 bytes. Buy new RAM!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/874994
推荐阅读
相关标签
  

闽ICP备14008679号