Code Monkey home page Code Monkey logo

yolov5_prune's People

Contributors

zju-lishuang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yolov5_prune's Issues

map before prune?

command:
python prune_yolov5s.py --cfg cfg/yolov5s.cfg --data data/fangweisui.data --weights weights/yolov5s_prune0.pt --percent 0.8
code used:
[https://github.com/ZJU-lishuang/yolov5]

question:
+------------+----------+----------+
| Metric | Before | After |
+------------+----------+----------+
| mAP | 0.025648 | 0.000000 |
| Parameters | 7263185 | 1790052 |
| Inference | 0.0165 | 0.0172 |
+------------+----------+----------+
so when eval the ori model,what is the format of annos ?like normalized [classid,x_center,y_center,w,h] or coco format?

剪枝后map显示nan

屏幕截图 2021-06-28 153924

您好,我使用 slim_prune_yolov5s.py对稀疏后的模型剪枝,得到剪枝后的cfg和pt文件了,但是map显示为nan,无论剪枝率设置多少都是这样,请问这边是出现什么问题了吗?

剪枝后模型仅参数量减少,但推理速度没有变快,甚至还比没剪枝的模型要慢一点点

@ZJU-lishuang 你好,请教一个问题
我在step3进行剪枝的时候,除了readme里的剪枝策略一,其他剪枝方法都有使用过,我最开始使用八倍通道剪枝,运行slim_prune_yolov5s_8x.py,进行微调之后,模型的大小减少了,但推理时间并没有减少,甚至比没有剪枝的模型还要慢上一点点。之后我尝试了除了策略一的所有剪枝方案对稀疏化训练后得到的模型进行剪枝,但剪枝后的模型只是参数量有减少,而推理时间几乎没变化,想请教一下是什么原因。
是我稀疏化训练有问题?还是剪枝策略有问题?

下面是step2稀疏化训练的可视化结果

map
bn

下面是我尝试的每一种剪枝策略的运行结果和参数设置

剪枝策略三,八倍通道剪枝,运行slim_prune_yolov5s_8x.py

slim_8x_opt
slim_8x

剪枝策略三,运行slim_prune_yolov5s.py

slim_opt
slim

剪枝策略四,层剪枝,运行layer_prune_yolov5s.py

layer_opt
layer

剪枝策略二,对shortcut层也进行剪枝,运行shortcut_prune_yolov5s.py

shortut_opt
shortut

减枝后的model无法在yolov5上运行

你好,我用自己的数据在这个项目里剪枝后,打算在原yolov5的项目中test,但是报错; 然后我用你在tutorial 里给的8倍通道剪枝的model去跑,结果还是一样。报错如下:
Traceback (most recent call last):
File "test.py", line 309, in
test(opt.data,
File "test.py", line 55, in test
model = attempt_load(weights, map_location=device) # load FP32 model
File "/home/bai/Desktop/yolov5-v3-test/models/experimental.py", line 118, in attempt_load
model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model
AttributeError: 'collections.OrderedDict' object has no attribute 'float'
请问是model 需要再转换一下格式么? 但是我看它已经是.pt格式了,实在不知道咋整。

请教关于剪枝后map为0的问题

当我使用自己的数据集进行训练时,基础训练过程和稀疏训练过程均正常,但是进行到剪枝的时候,P,R,map,F1的值均变成0;
我想请教您这个问题需要如何解决?
我的数据集一共2059张图片,做火灾识别,classes=1
image

您好,请教一下微调时map接近于0的问题

您好,我按照您给出的教程完成了剪枝操作,剪枝前后map分别为0.74,0.72;接下来按照您给出的步骤,用ZJU-lishuang/yolov5-v4中的prune_finetune.py代码进行微调,但是微调训练过程中map值基本保持为0,您知道原因可能有哪些吗?

请教稀疏训练BN权重的问题

QQ图片20210603192426
QQ图片20210603192431
您好,我稀疏训练后得到的BN权重如图所示,和tanluren/yolov3-channel-and-layer-pruning上的完全不同,请问造成这个问题的原因是什么?是我稀疏训练的不够吗?还是我稀疏训练过程的参数设置有问题?我稀疏训练和基础训练都是100epoch,稀疏训练中s=0.001,prune=1

how do u get yolov5s_v3.cfg?

thanks for your works, it is wonderful,but May i know how do u get yolov5s.cfg from yaml and .pt? if i want prune yolov5x.pt,what should i do? forward your reply

infer time and map (yolov5l prune vs yolov5s)?

在精度和耗时方面yolov5做了一个权衡,https://github.com/ultralytics/yolov5/issues/304,这里Glenn Jocher并不是特别建议自己作剪枝,如果追求更改的精度,可以选用大模型,如果追求更快的速度,用yolov5_s,如果用大模型去做剪枝和yolov5_s作对比的话,速度和精度会有优势吗?有相关实验结论吗?(yolov3元模型比较大的,200M以上,才有了剪枝的必要,yolov5同样适用剪枝吗?另一个问题还没有关闭,https://github.com/ZJU-lishuang/yolov5_prune/issues/4,发现用yolov5_v2得到的模型还没有直接用yolov5s_v3得到的模型精度高,所以有此疑惑,望不嫌麻烦,给点建议,不胜感激)

'Model' object has no attribute 'module_list' 稀疏训练报错

按照作者的readme操作,下载的是官方v5的第四个版本的yolov5s,配置文件yolov5s.yaml是作者提供的,数据集yaml已修改。
在稀疏训练结束查看bn权重时候报错

Traceback (most recent call last):
File "train_sparsity.py", line 663, in
train(hyp, opt, device, tb_writer, wandb)
File "train_sparsity.py", line 530, in train
bn_weights = gather_bn_weights(model.module_list, [idx])
File "H:\Anaconda3\envs\yolov5-ss\lib\site-packages\torch\nn\modules\module.py", line 778, in getattr
raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'Model' object has no attribute 'module_list'

我的本地版本是

python 3.8.5 torch 1.7.1

我将模型打印输出,发现确实缺少了该部分,我参考了v3剪枝中的issue,但是没有解决。希望得到回复~
这个问题似乎不会对训练产生影响,但是想知道问题出在哪儿,

WARNING: smart bias initialization failure.

在yolov5_prune/modelsori.py下测试DarkNet,
if name =='main':
img_size = 608
cfg = 'cfg/yolov5s_v4_hand.cfg'
arc = 'default'
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# 创建Darknet模型
model = Darknet(cfg, (img_size, img_size), arc=arc).to(device)

有警告:
WARNING: smart bias initialization failure.
WARNING: smart bias initialization failure.
WARNING: smart bias initialization failure.

pytorch版本:1.8.1
python版本:3.7

剪枝過後的testing script

打擾了
想問一下你有寫剪枝過後的testing script嗎
我在yolov5-v4那個repo只有看到detect script
run 你的testing script好像有bug
不確定是不是你沒寫這部分呢

fuse操作对导出为onnx的影响

执行export_prune_onnx.py 导出onnx时报错,在于attempt_load函数中fuse操作,去掉fuse操作可正常导出,这个fuse操作也将bn层的eps也fuse到卷积中了

稀疏训练

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

剪枝后map为零

稀疏训练后map大概掉了一个点(最后0.5左右)
但是使用这个里面的剪枝策略,无论哪个都显示剪枝前剪枝后的map为0
各种p,r指标也全都为0
我训练了5个类别,配置文件都没有问题
请问有什么解决方法吗?

gather_bn_weights函数不支持SyncBatchNorm

我稀疏训练用的多卡分布式训练的, 在运行脚本slim_prune_yolov5s对模型进行裁剪时,报错在utils/prune_utils.py中gather_bn_weights函数
image
是SyncBatchNorm

在使用自定义数据集训练时遇到的问题

你好,感谢您的开源工作。
我在使用你的repo代码对开源数据集NWPUVHR数据集进行剪枝时遇到一些问题,想请教一下您。step1跟step2稀疏训练都没什么问题。
请问第三步中自定义的数据例如fangweisui.data 要怎么生成?我根据coco.data尝试改了一个,但是遇到以下问题:
image
请教您我这里的训练命令有没有什么错误。yolov5s_v4.cfg是您提供的,yolov5s_sparsity.pt 是第二步稀疏训练得到的,NWPUVHR.data如下:
image

'Conv2d' object has no attribute 'conv'

你好
我尝试使用自己的数据集训练模型,按照readme的流程,在使用8倍通道剪枝的时候出现了问题。
Traceback (most recent call last):
File "slim_prune_yolov5s_8x.py", line 342, in
copy_weight_v4(modelyolov5, model)
File "slim_prune_yolov5s_8x.py", line 23, in copy_weight_v4
copy_conv(cspnet1.cv2, model.module_list[3])
File "slim_prune_yolov5s_8x.py", line 13, in copy_conv
conv_dst[0] = conv_src.conv
File "/home/cwy/.conda/envs/yolo/lib/python3.8/site-packages/torch/nn/modules/module.py", line 778, in getattr
raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'Conv2d' object has no attribute 'conv'

其中,cfg文件我是复制yolov5s_hand.cfg,修改了class,filters和anchors三个参数
data文件的内容如下:
classes= 10
train = /data/cwy/CardNumber/yolov5_random/train.txt
valid = /data/cwy/CardNumber/yolov5_random/test.txt
names = data/CardNumber.names
backup = /data/cwy/CardNumber/yolov5_random/

改了很久也没能改对,请问这个问题该如何解决

yaml to cfg

Hello,is there a yaml to cfg script?I'd like to try your yolov5s pruning operation, I'm sorry I didn't find the corresponding cfg file.

你好,我在 STEP3:通道剪枝 遇上问题,想请你帮忙看看

python prune_yolov5s.py --cfg cfg/yolov5s_v4.cfg --data data/myvoc.data --weights best.pt --percent 0.8
后出现以下错误:
Traceback (most recent call last):
File "prune_yolov5s.py", line 361, in
origin_model_metric = eval_model(model)
File "prune_yolov5s.py", line 348, in
eval_model = lambda model:test(opt.cfg, opt.data,
File "D:\Gitee\yolov5_prune-4\test.py", line 181, in test
inf_out, train_out = model(imgs) # inference and training outputs
File "C:\Users\TXY\anaconda3\envs\yolo_v5\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "D:\Gitee\yolov5_prune-4\modelsori.py", line 293, in forward
x = module(x, img_size)
File "C:\Users\TXY\anaconda3\envs\yolo_v5\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "D:\Gitee\yolov5_prune-4\modelsori.py", line 178, in forward
p = p.view(bs, self.na, self.nc + 5, self.ny, self.nx).permute(0, 1, 3, 4, 2).contiguous() # prediction
RuntimeError: shape '[16, 3, 85, 28, 52]' is invalid for input of size 489216
你是否遇到过该错误呢?
还有请问通道剪枝命令命令
python prune_yolov5s.py --cfg cfg/yolov5s.cfg --data data/fangweisui.data --weights weights/yolov5s_prune0.pt --percent 0.8
中,yolov5s.cfg和fangweisui.data文件是否做了修改呢?是否可以上传一下呢?

yolov5s_hand.yaml内容与原版yolov5s.yaml不一致

yolov5s_hand.yaml的内容是对模型结构的重新定义,是分拆的吧,与原版yolov5内容不一致,这样就得以你定义的yaml重新训练模型,在稀疏训练,再剪枝和微调。
能不能直接用原版yolov5.yaml预训练的模型,直接稀疏训练,再剪枝和微调呢?

数据集

你好,请问一下这个基础训练中的 data/coco_hand.yaml在哪里呢?我下载了这个数据集发现并不是coco格式的标注格式,想跑起来整个流程还是挺麻烦的,谢谢

剪枝后的模型如何做加速呢?

请教一下作者,现在剪枝有结构化剪枝和非结构化剪枝,应该只有结构化剪枝才能实现加速,非结构化剪枝需要硬件的支持,你这里使用的是结构化剪枝吗?结构化剪枝后的模型有把权重为0的filter删除掉吗? 谢谢

如何参考yolov5s.cfg得到yolov5x.cfg

@ZJU-lishuang 你好,yolov5s.yaml和yolov5x.yaml只有width_multiple和depth_multiple两个参数不一样
如果要得到yolov5x.cfg对yolov5x进行剪枝,在yolov5s.cfg的基础上如何修改可以得到yolov5x.cfg?
刚接触这方面的大小不知道该如何入手

在剪枝的时候报错

你好,我基于u版的yolo v5s训练出了自己的模型,用你的代码进行了稀疏训练。在使用剪枝策略1时代码报错了,信息如下:

(pytorch) D:\CNN\yolov5\zju_prune\yolov5_prune-4>python prune_yolov5s.py --cfg D:\CNN\yolov5\yolov5\models\yolov5s.yaml --data D:\CNN\yolov5\zju_prune\yolov5_prune-4\datasets_3_aug_yolo\data.yaml --weights D:\CNN\yolov5\zju_prune\yolov5-v4-main\runs\train\s_sparsity\weights\best.pt --percent 0.8 Namespace(cfg='D:\\CNN\\yolov5\\yolov5\\models\\yolov5s.yaml', data='D:\\CNN\\yolov5\\zju_prune\\yolov5_prune-4\\datasets_3_aug_yolo\\data.yaml', img_size=416, percent=0.8, weights='D:\\CNN\\yolov5\\zju_prune\\yolov5-v4-main\\runs\\train\\s_sparsity\\weights\\best.pt') Traceback (most recent call last): File "prune_yolov5s.py", line 338, in <module> model = Darknet(opt.cfg, (img_size, img_size)).to(device) File "D:\CNN\yolov5\zju_prune\yolov5_prune-4\modelsori.py", line 254, in __init__ self.module_defs = parse_model_cfg(cfg) File "D:\CNN\yolov5\zju_prune\yolov5_prune-4\utils\parse_config.py", line 18, in parse_model_cfg key, val = line.split("=") ValueError: not enough values to unpack (expected 2, got 1)

我看你使用了data data/fangweisui.data这个文件作为训练数据设置,我不知道你的.data文件格式是怎样的。我使用的是yaml文件,会不会是这里有影响呢?

稀疏训练的问题

我在自己的数据集上进行yolov5s的稀疏训练,s=0.001,然而map下降很多,差不多10个点,200个epoch之后精度也没返回到原来的水平,请问是s的选取不合适吗

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.