ZJU-lishuang / yolov5_prune

yolov5 prune,Support V2, V3, V4 and V6 versions of yolov5
Apache License 2.0
560 stars 137 forks source link

稀疏训练 #2

Closed OyamingO closed 3 years ago

OyamingO commented 3 years ago

加载自己预训练的yolov5s的best.pt进行稀疏训练报错?请问大佬是因为模型结构不一样吗?

ZJU-lishuang commented 3 years ago

这套工程的稀疏训练是yolov3的,我没有折腾这套代码,而是直接在原版yolov5上改代码进行稀疏训练。 稀疏训练在yolov5第二版yolov5第三版里面都改好了,只是还没有写教程 :sweat_smile:

OyamingO commented 3 years ago

好的,非常感谢,我跑一下您的yolov5-v3试试,哈哈

ZJU-lishuang commented 3 years ago

yolov5第二版里面,train_pytorch1.4_noprune.py是原始训练,train_pytorch1.4.py是稀疏训练,prune_finetune.py是剪枝后微调。 yolov5第三版里面,train.py是原始训练,train_sparsity.py是稀疏训练,剪枝后微调的还没单独写出来。 注意一下类别个数,这个参数需要自己调一下。

OyamingO commented 3 years ago

好的,太感谢了!敢问大神在哪高就啊,有时间来武汉请你吃饭,哈哈

------------------ 原始邮件 ------------------ 发件人: "ZJU-lishuang/yolov5_prune" <notifications@github.com>; 发送时间: 2020年11月24日(星期二) 上午9:58 收件人: "ZJU-lishuang/yolov5_prune"<yolov5_prune@noreply.github.com>; 抄送: "O亚明O"<1964533558@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [ZJU-lishuang/yolov5_prune] 稀疏训练 (#2)

yolov5第二版里面,train_pytorch1.4_noprune.py是原始训练,train_pytorch1.4.py是稀疏训练,prune_finetune.py是剪枝后微调。 yolov5第三版里面,train.py是原始训练,train_sparsity.py是稀疏训练,剪枝后微调的还没单独写出来。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

OyamingO commented 3 years ago

你好,这个yolov5-v3这个版本中有个hyp参数:parser.add_argument('--hyp', type=str, default='data/hyp.scratch.yaml', hyphelp='hyperparameters path',默认的这个文件在data文件夹中没有找到,然后设置为空值的时候也会报错No such file or directory: '',您看这块代码应该怎么处理呢?

ZJU-lishuang commented 3 years ago

上传了对应的文件,yolov5本身的.gitignore文件有坑,把data这个文件夹忽略了

OyamingO commented 3 years ago

看到啦,拜谢😄

---原始邮件--- 发件人: "ZJU-lishuang"<notifications@github.com> 发送时间: 2020年11月24日(周二) 下午3:21 收件人: "ZJU-lishuang/yolov5_prune"<yolov5_prune@noreply.github.com>; 抄送: "OyamingO"<1964533558@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [ZJU-lishuang/yolov5_prune] 稀疏训练 (#2)

上传了对应的文件,yolov5本身的.gitignore文件有坑,把data这个文件夹忽略了

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

OyamingO commented 3 years ago

你好,我在进行稀疏训练的时候,显示索引错误,出错代码为copy_weight部分: def copy_weight(modelyolov5,model): focus = list(modelyolov5.model.children())[0] print('----------------focus.structure-----------------\n', focus) print('----------------model.module_list-----------------\n', model.module_list) model.module_list[1][0] = focus.conv.conv model.module_list[1][1] = focus.conv.bn model.module_list[1][2] = focus.conv.act

我打印了一下相关信息,发现是因为yolov5s_v3.cfg那个文件里边没有激活函数层: ----------------focus.structure----------------- Focus( (conv): Conv( (conv): Conv2d(12, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True) (act): Hardswish() ) ) ----------------model.module_list----------------- ModuleList( (0): Sequential() (1): Sequential( (Conv2d): Conv2d(12, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (BatchNorm2d): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) )

想请教一下需要如何修改?

ZJU-lishuang commented 3 years ago

更新同步了,原来的yolov5忘了加了

OyamingO commented 3 years ago

好的,谢谢

---原始邮件--- 发件人: "ZJU-lishuang"<notifications@github.com> 发送时间: 2020年11月26日(周四) 晚上6:14 收件人: "ZJU-lishuang/yolov5_prune"<yolov5_prune@noreply.github.com>; 抄送: "OyamingO"<1964533558@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [ZJU-lishuang/yolov5_prune] 稀疏训练 (#2)

更新同步了,原来的yolov5忘了加了

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

seeyouagain111 commented 3 years ago

好的,谢谢 ---原始邮件--- 发件人: "ZJU-lishuang"<notifications@github.com> 发送时间: 2020年11月26日(周四) 晚上6:14 收件人: "ZJU-lishuang/yolov5_prune"<yolov5_prune@noreply.github.com>; 抄送: "OyamingO"<1964533558@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [ZJU-lishuang/yolov5_prune] 稀疏训练 (#2) 更新同步了,原来的yolov5忘了加了 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

你好,请问你在yolov5上剪枝成功了吗,有遇到mAP为0的情况吗

OyamingO commented 3 years ago

好的,谢谢 ---原始邮件--- 发件人: "ZJU-lishuang"[notifications@github.com](mailto:notifications@github.com) 发送时间: 2020年11月26日(周四) 晚上6:14 收件人: "ZJU-lishuang/yolov5_prune"[yolov5_prune@noreply.github.com](mailto:yolov5_prune@noreply.github.com); 抄送: "OyamingO"[1964533558@qq.com](mailto:1964533558@qq.com);"Author"[author@noreply.github.com](mailto:author@noreply.github.com); 主题: Re: [ZJU-lishuang/yolov5_prune] 稀疏训练 (#2) 更新同步了,原来的yolov5忘了加了 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

你好,请问你在yolov5上剪枝成功了吗,有遇到mAP为0的情况吗

你好,我在第三版代码的基础上进行的测试,剪枝之后发现跟原始模型大小一样,我也不太懂这个代码,后边就放弃了

ZJU-lishuang commented 3 years ago

更新了readme,剪枝代码中没有对模型多余的参数进行删除和float32转float16的操作,所以模型大小没怎么变。 使用微调后,剪枝率0.8的模型大小从14.1mb降低为1.3mb

EricHuiK commented 3 years ago

第三版的微调代码呢

ZJU-lishuang commented 3 years ago

@EricHuiK prune_finetune.py