GithubHelp home page GithubHelp logo

jack-willturner / deep-compression Goto Github PK

View Code? Open in Web Editor NEW
173.0 4.0 41.0 2.46 MB

Learning both Weights and Connections for Efficient Neural Networks https://arxiv.org/abs/1506.02626

License: MIT License

Python 14.54% Jupyter Notebook 84.19% Shell 1.28%
deep-learning pruning pytorch sparsity

deep-compression's Introduction

Total alerts Language grade: Python GitHub

A PyTorch implementation of this paper.

To run, try:

python train.py --model='resnet34' --checkpoint='resnet34'
python prune.py --model='resnet34' --checkpoint='resnet34'

Usage

The core principle behind the training/pruning/finetuning algorithms is as follows:

from models import get_model
from pruners import get_pruner 

model = get_model("resnet18")
pruner = get_pruner("L1Pruner", "unstructured")

for prune_rate in [10, 40, 60, 80]:
    pruner.prune(model, prune_rate)

We can choose between structured/unstructured pruning, as well as the pruning methods which are in pruners (at the time of writing we have support only for magnitude-based pruning and Fisher pruning).

Bring your own models

In order to add a new model family to the repository you basically just need to do two things:

  1. Swap out the convolutional layers to use the ConvBNReLU class
  2. Define a get_prunable_layers method which returns all the instances of ConvBNReLU which you want to be prunable

Summary

Given a family of ResNets, we can construct a Pareto frontier of the tradeoff between accuracy and number of parameters:

alt text

Han et al. posit that we can beat this Pareto frontier by leaving network structures fixed, but removing individual parameters:

alt text

deep-compression'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  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

deep-compression's Issues

I have a question about parameter number.

after pruning, I count the parameter of the network resnet34.
well... I found the number of parameters to be 4.2 * 10e7
I know parameter number of resnet34 is about 2 * 10e7
I think it's because of the mask of layer that the difference is about double, right?
then how to remove the mask layer after prunning?
Thanks you.

Transposed Convolution

can I use your proposed algorithm for pruning weights in Transposed Convolution layers, e.g. in DCGAN?

A question for channel pruning on mobilenet

Thank you,your code enlightens me.I have trained mobilenet on CIFAR10,and then I got 87% acurracy rate.Then I use deep_compress function,after i use sparsify function,I have found the weights of kernel in some layer are all zero,it means when I use channel prue,I will loss all the following layer? Have i done something wrong?Thank you for your time!

Error in structured pruning

Hi, when I prune resnet in structured type, I got error like this:

Traceback (most recent call last):
File "prune.py", line 131, in
pruner.prune(model, prune_rate)
File "/content/deep-compression-master/pruners/l1_pruner.py", line 70, in prune
self.structured_prune(model, prune_rate)
File "/content/deep-compression-master/pruners/l1_pruner.py", line 30, in structured_prune
threshold = np.percentile(channel_norms, prune_rate)
File "<array_function internals>", line 6, in percentile
File "/usr/local/lib/python3.7/dist-packages/numpy/lib/function_base.py", line 3868, in percentile
a, q, axis, out, overwrite_input, interpolation, keepdims)
File "/usr/local/lib/python3.7/dist-packages/numpy/lib/function_base.py", line 3988, in _quantile_unchecked
interpolation=interpolation)
File "/usr/local/lib/python3.7/dist-packages/numpy/lib/function_base.py", line 3564, in _ureduce
r = func(a, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/numpy/lib/function_base.py", line 4103, in _quantile_ureduce_func
)), axis=0)
ValueError: operands could not be broadcast together with shapes (128,) (64,)

It seems because some element's lenth in channel_norms list are different. What should I do?

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.