ofsoundof / group_sparsity Goto Github PK
View Code? Open in Web Editor NEWGroup Sparsity: The Hinge Between Filter Pruning and Decomposition for Network Compression. CVPR2020.
License: MIT License
Group Sparsity: The Hinge Between Filter Pruning and Decomposition for Network Compression. CVPR2020.
License: MIT License
Hi, How can we resume training in the converging stage?
I know there are 200 epochs in the searching stage and 300 epochs in the converging stage by default.
Suppose we already get the model_converging_best.pt under the "model" directory.
I tried to load the pre-trained model using --save, --load and --pretrain, but all not working.
Thanks
Hi, I find a bug in hinge_densenet_svd.py inthis line
loss_proj.append(torch.sum(torch.sum(projection.squeeze().t() ** 2, dim=1) ** (q / 2)) ** (1 / q))
When the remaining filter number equals one, it will give the following error.
The code should be changed to the following to squeeze the last two dimensions
loss_proj.append(torch.sum(torch.sum(projection.squeeze(3).squeeze(2).t() ** 2, dim=1) ** (q / 2)) ** (1 / q))
Hi, thanks for your work and sharing of the code!
However, I have a problem downloading the pretrained models
(1) I tried to use VPN to directly download the model_zoo.zip but filed (Which I can download other google drive file successfully.)
(2) I follow this tutorial and use wget to download the model, but still not working.
Can you share the directory of the file? Since I saw the download link
"...view?usp=sharing" flash for one second and disappear and redirect to "...view"
Thanks for your time and looking forward to your reply.
Hi,
@ofsoundof The scripts for CIFAR-10 and CIFAR-100 are here
For examples what sparsity (compression ratio) did you use for ResNet-50, hyper parameters etc.
Can you please point me to scripts to reproduce the ImageNet results ?
Thanks in advance!
Hi, I want to test your method on DenseNet with bottleneck structure on CIFAR100 (conv1x1 --> conv3x3)
I follow the code of densenet_svd.py and hinge_resnet_bottleneck.py,
mainly changing the following function
def compress_module_param(module, percentage, threshold):
# Bias in None. So things becomes easier.
# get the body
'''
# transition
(0): BatchNorm2d(168, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(1): ReLU()
(2): Conv2d(168, 84, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): Conv2d(84, 84, kernel_size=(1, 1), stride=(1, 1), bias=False)
(4): AvgPool2d(kernel_size=2, stride=2, padding=0)
'''
if isinstance(module, Transition):
body = module
conv1 = body._modules['2']
conv2 = body._modules['3']
ws1 = conv1.weight.data.shape
weight1 = conv1.weight.data.squeeze().t()
ws2 = conv2.weight.data.shape
weight2 = conv2.weight.data.squeeze().t()
# calculate pindex
_, pindex = get_nonzero_index(weight1, dim='output', counter=1, percentage=percentage, threshold=threshold)
pl = pindex.shape[0]
weight1 = torch.index_select(weight1, dim=1, index=pindex)
conv1.weight = nn.Parameter(weight1.t().view(pl, ws1[1], ws1[2], ws1[3]))
conv1.out_channels = pl
# compress conv2
conv2.weight = nn.Parameter(torch.index_select(weight2, dim=0, index=pindex).t().view(ws2[0], pl, ws2[2], ws2[3]))
conv2.in_channels = pl
elif isinstance(module, BottleNeck):
# with torchsnooper.snoop():
body = module._modules['body']
# conv1x1
conv1 = body._modules['2']
batchnorm1 = body._modules['3'] # conv1-output 对应的 batchnorm
conv2 = body._modules['5']
# get conv weights
ws1 = conv1.weight.data.shape
weight1 = conv1.weight.data.squeeze().t()
bn_weight1 = batchnorm1.weight.data
bn_bias1 = batchnorm1.bias.data
bn_mean1 = batchnorm1.running_mean.data
bn_var1 = batchnorm1.running_var.data
ws2 = conv2.weight.data.shape
weight2 = conv2.weight.data.view(ws2[0], ws2[1] * ws2[2] * ws2[3]).t()
# selection compressed channels
_, pindex1 = get_nonzero_index(weight1, dim='output', counter=1, percentage=percentage, threshold=threshold)
pl1 = len(pindex1)
conv1.weight = nn.Parameter(torch.index_select(weight1, dim=1, index=pindex1).t().view(pl1, -1, 1, 1))
conv1.out_channels = pl1
# batchnorm1
batchnorm1.weight = nn.Parameter(torch.index_select(bn_weight1, dim=0, index=pindex1))
batchnorm1.bias = nn.Parameter(torch.index_select(bn_bias1, dim=0, index=pindex1))
batchnorm1.running_mean = torch.index_select(bn_mean1, dim=0, index=pindex1)
batchnorm1.running_var = torch.index_select(bn_var1, dim=0, index=pindex1)
batchnorm1.num_features = pl1
# conv2
index = torch.repeat_interleave(pindex1, ws2[2] * ws2[3]) * ws2[2] * ws2[3] + \
torch.tensor(range(0, ws2[2] * ws2[3])).repeat(pindex1.shape[0]).cuda()
weight2 = torch.index_select(weight2, dim=0, index=index)
# weight2 = torch.index_select(weight2, dim=1, index=pindex3)
conv2.weight = nn.Parameter(weight2.view(ws2[0], pl1, 3, 3))
conv2.in_channels = pl1
# exit(0)
else:
raise NotImplementedError('Do not need to compress the layer ' + module.__class__.__name__)
while testing the model using default parameters, the top-1 test error change as follows:
Did you test your model on DenseNet-bottleck during experiment?
I was wondering is there something wrong with my code, if not, why the testing loss behavior like this?
Thanks for your time and looking forward to your reply.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.