Code Monkey home page Code Monkey logo

Comments (13)

ZJU-lishuang avatar ZJU-lishuang commented on July 17, 2024

做模型压缩来提升fps

from yolov5_prune.

ZJU-lishuang avatar ZJU-lishuang commented on July 17, 2024

Is that too broad of a question? You can reframe that.

from yolov5_prune.

sbbug avatar sbbug commented on July 17, 2024

为什么剪枝后,模型的FPS基本没变

from yolov5_prune.

ZJU-lishuang avatar ZJU-lishuang commented on July 17, 2024

制约推理速度的不仅是模型大小,和硬件也有关系的,比如网络很深,速度瓶颈在cpu和gpu数据交换上。
像yolov5s在台式2060上剪枝,推理速度就没什么提升,瓶颈在数据复制粘贴上。

from yolov5_prune.

sbbug avatar sbbug commented on July 17, 2024

谢谢你热心回答,请问楼主有试过层剪枝的效果吗?

from yolov5_prune.

ZJU-lishuang avatar ZJU-lishuang commented on July 17, 2024

只实现过代码,yolov5s没几个层,再剪就没了,还不如砍掉一个head

from yolov5_prune.

sbbug avatar sbbug commented on July 17, 2024

哈哈,是的,
对于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.

ZJU-lishuang avatar ZJU-lishuang commented on July 17, 2024

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.

sbbug avatar sbbug commented on July 17, 2024

如果考虑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.

sbbug avatar sbbug commented on July 17, 2024

大佬可以加个微信请教下吗!!

from yolov5_prune.

sbbug avatar sbbug commented on July 17, 2024

大致看了下,
single_bn = [11,28,45,63,75,87,101,115]
这几个BN层好像有点问题,不知道你当时遇到这个问题没

from yolov5_prune.

ZJU-lishuang avatar ZJU-lishuang commented on July 17, 2024

yolov5第二版的s模型跑过了,没碰到这问题
yolov5-v2-prune

from yolov5_prune.

ZJU-lishuang avatar ZJU-lishuang commented on July 17, 2024

主干是v4,分支里有v3和v2

from yolov5_prune.

Related Issues (20)

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.