Comments (13)
做模型压缩来提升fps
from yolov5_prune.
Is that too broad of a question? You can reframe that.
from yolov5_prune.
为什么剪枝后,模型的FPS基本没变
from yolov5_prune.
制约推理速度的不仅是模型大小,和硬件也有关系的,比如网络很深,速度瓶颈在cpu和gpu数据交换上。
像yolov5s在台式2060上剪枝,推理速度就没什么提升,瓶颈在数据复制粘贴上。
from yolov5_prune.
谢谢你热心回答,请问楼主有试过层剪枝的效果吗?
from yolov5_prune.
只实现过代码,yolov5s没几个层,再剪就没了,还不如砍掉一个head
from yolov5_prune.
哈哈,是的,
对于BCSP块,你是怎么剪枝的,如下:
`class BottleneckCSP(nn.Module):
# CSP Bottleneck https://github.com/WongKinYiu/CrossStagePartialNetworks
def init(self, c1, c2, n=1, shortcut=True, g=1, e=0.5): # ch_in, ch_out, number, shortcut, groups, expansion
super(BottleneckCSP, self).init()
c_ = int(c2 * e) # hidden channels
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = nn.Conv2d(c1, c_, 1, 1, bias=False)
self.cv3 = nn.Conv2d(c_, c_, 1, 1, bias=False)
self.cv4 = Conv(2 * c_, c2, 1, 1)
self.bn = nn.BatchNorm2d(2 * c_) # applied to cat(cv2, cv3)
self.act = nn.LeakyReLU(0.1, inplace=True)
self.m = nn.Sequential(*[Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)])
def forward(self, x):
y1 = self.cv3(self.m(self.cv1(x)))
y2 = self.cv2(x)
return self.cv4(self.act(self.bn(torch.cat((y1, y2), dim=1))))`
对于self.bn有必要加入prune_idx里吗?其实这一块我们有点懵逼的,
yolov5s网络结构是BottleneckCSP非C3,主要是因为C3在我们数据集下训练的精度较低,模型收敛慢。
from yolov5_prune.
bn劈成两半,一半是cv2,一半是cv3,一个很自然的想法
channels = weight_copy.shape[0]
channels_half=int(channels/2)
weight_copy1=weight_copy[:channels_half]
weight_copy2 = weight_copy[channels_half:]
min_channel_num = int(channels_half * opt.layer_keep) if int(channels_half * opt.layer_keep) > 0 else 1
mask1 = weight_copy1.gt(thresh).float()
mask2 = weight_copy2.gt(thresh).float()
from yolov5_prune.
如果考虑self.bn,在稀疏化训练时会遇到错误:
出现错误的代码
if sr_flag: # s = s if epoch <= opt.epochs * 0.5 else s * 0.01 for idx in prune_idx: # Squential(Conv, BN, Lrelu) bn_module = module_list[idx][1] bn_module.weight.grad.data.add_(s * torch.sign(bn_module.weight.data)) # L1
原因可能是:
idx=11时
Sequential(
(BatchNorm2d): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
(activation): LeakyReLU(negative_slope=0.1, inplace=True)
)
from yolov5_prune.
大佬可以加个微信请教下吗!!
from yolov5_prune.
大致看了下,
single_bn = [11,28,45,63,75,87,101,115]
这几个BN层好像有点问题,不知道你当时遇到这个问题没
from yolov5_prune.
yolov5第二版的s模型跑过了,没碰到这问题
yolov5-v2-prune
from yolov5_prune.
主干是v4,分支里有v3和v2
from yolov5_prune.
Related Issues (20)
- 模型剪枝后的结构打印问题 HOT 2
- 您好,请问YOLOv5-v5.0的是哪个版本呢? HOT 12
- 不同的backbone
- 请问剪枝后生成的.cfg怎么转成.yaml
- 请问这个项目怎么导出成.torchscript转pnnx阿 剪枝完想部署在android上
- 为什么剪枝之后在nx开发板上运行速度也没有提升
- 这里脚本的参数和说明对不上啊,是否应该改为 --prune 0
- coco128上剪枝后mAP值为0
- prune_yolov5s.py文件第152行代码的疑问 HOT 1
- 模型通过剪枝后与原yolov5s.pt的模型里的参数名称不一致吗
- how to get the yolov5.cfg ?
- STEP3的通道剪枝策略一和通道剪枝策略二得到的模型在step4都无法进行蒸馏?(策略三和八倍通道剪枝还未测试) HOT 7
- 感谢大佬为开源作出的贡献。 HOT 2
- prune的data問題
- 微调后得到的pt转onnx失败
- 關於yolov5的新tag版本 HOT 1
- 关于yolov7
- 增加CBAM,C3STR后如何剪枝 HOT 1
- 博主请问train.py训练的时候怎么tensorboard中画出bn_weights/hist直方图
- 剪枝在v7.0版本能用吗?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yolov5_prune.