Eric-mingjie / network-slimming

Network Slimming (Pytorch) (ICCV 2017)
MIT License
907 stars 214 forks source link

关于channel selection layer的问题请教 #50

Open YuQi9797 opened 4 years ago

YuQi9797 commented 4 years ago

您好,请问为什么我们需要channel selection layer来辅助ResNet和DenseNet的剪枝呀?

我看代码,自己的理解是对于ResNet和DenseNet在BN层后面添加了channel selection layer,然后进行训练。在模型裁剪的时候,channel selection layer的值全置0,然后将需要保留的赋值为1.

    # We need to set the channel selection layer.
    m2 = new_modules[layer_id + 1]
    m2.indexes.data.zero_()
    m2.indexes.data[idx1.tolist()] = 1.0

感觉这里也是对于我们增加的channel selection layer中需要裁剪的给裁剪了,保留未裁剪的。但我感觉如果我不加这个通道选择层。一样的如同vgg的裁剪方式,好像也没什么问题。

可能我对代码理解得不够透彻,希望作者您能指点一二,谢谢,期待您的回复!

Eric-mingjie commented 4 years ago

这样是为了保证主干道的channel数不变,如果没有channel selection layer, 主干道的channel数没法保证一致。

YuQi9797 commented 4 years ago

如果没有channel selection layer,主干道channel数无法保证一致,主要是体现在哪里呢? 从reprune.py中,我只理解到,BN层后面若是channel selection layer,则它本身BN层没有进行裁剪,而是对对应的channel selection layer进行设置,需要保留的设为1,需裁剪的为0。相当于为0的没有进行反向传播学习,只有为1的保留下来。 但我不知道这样做,为什么能保证主干道的channel数不变,不知道具体体现在哪里? 希望能帮忙解答,谢谢! 期待您的回复。

------------------ 原始邮件 ------------------ 发件人: "Eric-mingjie"<notifications@github.com>; 发送时间: 2020年7月7日(星期二) 凌晨1:09 收件人: "Eric-mingjie/network-slimming"<network-slimming@noreply.github.com>; 抄送: "919664295"<919664295@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [Eric-mingjie/network-slimming] 关于channel selection layer的问题请教 (#50)

这样是为了保证主干道的channel数不变,如果没有channel selection layer, 主干道的channel数没法保证一致。

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

Eric-mingjie commented 4 years ago

residual layer有两个通道,一个通道有卷积和bn,另一个通道一般都是identity mapping,我说的主干道就是identity mapping这个通道。这样做之所以能保证主干道channel数不变,是因为我们保证了卷积通道的input 和output的channel数和原来保持一致,这样才能和identity 通道出来的output相同维度,从而相加。之所以这样实现就是主干道channel数不变的体现。建议可以仔细去看下resnet的结构。

YuQi9797 commented 4 years ago

好的,明白了!  谢谢您的帮助!

------------------ 原始邮件 ------------------ 发件人: "Eric-mingjie"<notifications@github.com>; 发送时间: 2020年7月7日(星期二) 晚上11:44 收件人: "Eric-mingjie/network-slimming"<network-slimming@noreply.github.com>; 抄送: "919664295"<919664295@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [Eric-mingjie/network-slimming] 关于channel selection layer的问题请教 (#50)

residual layer有两个通道,一个通道有卷积和bn,另一个通道一般都是identity mapping,我说的主干道就是identity mapping这个通道。这样做之所以能保证主干道channel数不变,是因为我们保证了卷积通道的input 和output的channel数和原来保持一致,这样才能和identity 通道出来的output想同维度,从而相加。之所以这样实现就是主干道channel数不变的体现。建议可以仔细去看下resnet的结构。

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