-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pruning #14
Comments
之前没有打算放剪枝的代码,一方面是代码比较乱,另一反面觉得我的实现方式有点简单,RMNet剪枝应该有更好的表现,希望别人在我放出来的模型基础上能实现的更好。不过既然有需要,我还是把代码整理了出来: |
感谢您的工作! |
您好,我跑了剪枝训练的代码,发现不收敛。于是根据Network Slimming的思想做了一些改动 def update_mask(self,sr,threshold):
for m in self.modules():
if isinstance(m,nn.Conv2d):
if m.kernel_size==(1,1) and m.groups!=1:
m.weight.grad.data.add_(sr * torch.sign(m.weight.data))
# m1 = m.weight.data.abs()>threshold
# m.weight.grad.data*=m1
# m.weight.data*=m1 def prune(self,use_bn=True,threshold=0.1):
features=[]
in_mask=torch.ones(3)>0
blocks=self.deploy()
for i,m in enumerate(blocks):
if isinstance(m,nn.BatchNorm2d):
mask=m.weight.data.abs().reshape(-1)>threshold
... 从头稀疏训练res18,lr=0.1,sr=1e-4,cifar10上的效果如下:
|
如果不收敛,说明sr和threshold设置的太大了,建议调整一下这两个值再试试。另外也鼓励尝试更多剪枝方案,只需要注意,新增的通道也需要进行裁剪。 |
The sparsity factor is selected from 1e-4 to 1e-3, and the threshold is selected from 5e-4 to 5e-3. |
谢谢大佬,我对模型训练和减枝训练存在一些疑惑,以下训练过程中的参数设置是否正确?感谢! |
可以的,我当时调参的范围是: |
只要对比下变化之前和变化之后的值是不是相等就可以,注意需要在eval()模式下对比。 |
您好!我把代码修改了一下,在eval()模式下对比变化之前和变化之后的输出值不相等。我调试了一天不知道问题出在哪里,能帮我看看代码是哪里写错了吗? |
作者可否将剪枝部分的代码也放出,对论文剪枝部分的内容和目前的代码还存在一些疑惑,感谢。
The text was updated successfully, but these errors were encountered: