pytorch-yolov4

这篇博客介绍了如何在Ubuntu系统中修改软件源为清华源,然后在conda环境中创建虚拟环境并安装PyTorch及相关依赖。接着详细展示了如何克隆YOLOv4项目,进行模型训练和预测,并给出了训练参数和预测命令。最后,博主分享了训练结果和评估指标。
摘要由CSDN通过智能技术生成

Ubuntu修改清华源、conda修改清华源、更改pip源

https://blog.csdn.net/ly59782/article/details/89604663

https://www.cnblogs.com/lvchengda/p/12533040.html

git clone https://github.com/Tianxiaomo/pytorch-YOLOv4

conda create -n env_36 python=3.6.10
pip install -r requirements.txt
#去掉requirements.txt里的 skimage
pip install torchvision==0.5.0  # 与pytorch1.4.0配套

#python models.py <num_classes> <weightfile> <imgfile> <IN_IMAGE_H> <IN_IMAGE_W> <namefile(optional)>

python models.py  80 weight/yolov4.pth data/giraffe.jpg 416 416

pip install tensorboard    #安装tensorboard
pip install tensorboardx   #安装tensorboardx

硬币数据:https://pan.baidu.com/s/1y701NRKSdpj6UKDIH-GpqA 提取码:j09s

数据data 内部为图片、coins.name、train.txt、val.txt

由于类别比较少,修改cfg.py

Cfg.use_darknet_cfg = False
Cfg.cfgfile = os.path.join(_BASE_DIR, 'cfg', 'yolov4.cfg')

#Cfg.batch = 64
#Cfg.subdivisions = 16
Cfg.batch = 4
Cfg.subdivisions = 1

 修改cfg.py使得train.py中的darknet不被使用

if cfg.use_darknet_cfg:
        model = Darknet(cfg.cfgfile)
    else:
        model = Yolov4(cfg.pretrained, n_classes=cfg.classes)

为了不报错,修改了这里

def get_image_id(filename:str) -> int:   
    #aise NotImplementedError("Create your own 'get_image_id' function")
    #lv, no = os.path.splitext(os.path.basename(filename))[0].split("_")
    #lv = lv.replace("level", "")
    #no = f"{int(no):04d}"
    #return int(lv+no)

    parts = filename.split('-')
    id = int(parts[-1][0:-4])
    return id

 


#训练
python train.py -l 0.001 -g 0 -pretrained weight/yolov4.conv.137.pth -classes 3 -dir /home/shilinzhe/dataset/coins/data -train_label_path /home/shilinzhe/dataset/coins/data/train.txt

-l 学习率
-g gpu id
-pretrained 预训练的主干网络,从AlexeyAB给的darknet的yolov4.conv.137转换过来的
-classes 类别种类
-dir 图片所在文件夹
-train_label_path标签所在目录

#预测
python models.py 3 checkpoints/Yolov4_epoch299.pth data/P00524-151911.jpg 418 418
#tensor board
tensorboard --logdir log --host 192.168.212.75 --port 6008
#浏览器打开上面的域名

Epoch 300/300:  96%|\u2589| 24/25 [00:12<00:00,  2.63imin function convert_to_coco_api...
creating index...
index created!
Accumulating evaluation results...
DONE (t=0.06s).
IoU metric: bbox
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.489
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.727
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.609
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.489
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.244
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.715
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.764
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.764
2020-09-24 21:03:44,287 train.py[line:446] INFO: Created checkpoint directory
2020-09-24 21:03:44,572 train.py[line:451] INFO: Checkpoint 300 saved !
Epoch 300/300:  96%|\u2589| 24/25 [00:29<00:01,  1.22s/

 

-----------------------------------
           Preprocess : 0.025719
      Model Inference : 0.110292
-----------------------------------
-----------------------------------
       max and argmax : 0.001573
                  nms : 0.000841
Post processing total : 0.002414
-----------------------------------
-----------------------------------
           Preprocess : 0.012659
      Model Inference : 0.051989
-----------------------------------
-----------------------------------
       max and argmax : 0.001905
                  nms : 0.000938
Post processing total : 0.002843
-----------------------------------
1yuan: 0.994108
1yuan: 0.992459
1yuan: 0.978318
1yuan: 0.977262
1yuan: 0.944226
1yuan: 0.766804
5jiao: 0.977799
5jiao: 0.658348
1jiao: 0.891799
1jiao: 0.581562
save plot results to predictions.jpg

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值