Code Monkey home page Code Monkey logo

batchnorm-pruning's Introduction

Tensorflow implementation from original author here.

A PyTorch implementation of this paper.

To do list:

  • Extend to MobileNet and VGG
  • Fix MAC op calculation for strided convolution
  • Include training scheme from paper

Usage

I haven't included any code for transfer learning/ using pretrained models, so everything here must be done from scratch. You will have to rewrite your models to use my extended version of batch normalization, so any occurences of nn.BatchNorm2d should be replaced with bn.BatchNorm2dEx. I have included a few examples in the models folder. Note that in the forward pass you need to provide the weight from the last convolution to the batchnorm (e.g. out = self.bn1(self.conv1(x), self.conv1.weight).

I will add command line support for hyperparameters soon, but for now they will have to be altered in the main script itself. Currently the default is set to train ResNet-18; this can easily be swapped out for another model.

python main.py

Results on CIFAR-10

Model Size MAC ops Inf. time Accuracy
ResNet-18
ResNet-18-Compressed
VGG-16
VGG-16-Compressed
MobileNet
MobileNet-Compressed

Citing

Now accepted to ICLR 2018, will update bibtex soon:

@article{ye2018rethinking,
  title={Rethinking the Smaller-Norm-Less-Informative Assumption in Channel Pruning of Convolution Layers},
  author={Ye, Jianbo and Lu, Xin and Lin, Zhe and Wang, James Z},
  journal={arXiv preprint arXiv:1802.00124},
  year={2018}
}

batchnorm-pruning's People

Contributors

jack-willturner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

batchnorm-pruning's Issues

finetune problem

When running to the sixth step of finetune, there will be inconsistencies in the tensor dimension. How can I solve this problem? I look forward to your reply.

RuntimeError: The expanded size of the tensor (64) must match the existing size (58) at non

Channel number mismatch

I replaced the resnet with the VGG and still had the same problem. In the sixth step, finetune's new model went wrong.The number of channels after pruning does not match the number of channels before pruning, is it because the pruning channel is not saved, and the original channel does not match?How do you solve this problem? Looking forward to your reply.Thank you.

RuntimeError: Given groups=1, weight of size [209, 128, 3, 3], expected input[64, 115, 12, 12] to have 128 channels, but got 115 channels instead

out of memory

I found that the function "expand_model" may cause "out of memory" for a network with huge parameters.

A doubt about sgd.py

in paper, the ista algorithm described as rl+1 = max{(rl-u▽l),0}*sgn(rl-u▽l) , but in sgd.py, the ista algorithm described as:
x = p.data.add(-group['lr'],d_p)
x = torch.clamp((torch.abs(x) - ista), min=0.)
p.data = x * torch.sign(x)
I think the true code should be:
x = p.data.add(-group['lr'],d_p)
y = torch.clamp((torch.abs(x) - ista), min=0.)
p.data = y * torch.sign(x)

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.