Skip to content

Commit

Permalink
Merge branch 'release' of https://github.com/yihui-he/lowrank into re…
Browse files Browse the repository at this point in the history
…lease
  • Loading branch information
yihui-he committed Aug 21, 2017
0 parents commit 2c8db9e
Show file tree
Hide file tree
Showing 23 changed files with 9,325 additions and 0 deletions.
102 changes: 102 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#lib/cfgs.py
*.pickle
*.caffemodel
*.solverstate
*.prototxt
!temp/vgg.prototxt
!temp/solver.prototxt
cifar-10-batches-py
*.swp
.vscode/
core
*.tar*
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
# lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "caffe"]
path = caffe
url = https://github.com/yihui-he/caffe-pro
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Channel Pruning for Accelerating Very Deep Neural Networks
By [Yihui He](http://yihui-he.github.io/) (Xi'an Jiaotong University), Xiangyu Zhang and [Jian Sun](http://jiansun.org/) (Megvii)

In this repository, we illustrate channel pruning VGG-16 **4X** with our 3C method, after finetuning the Top-5 accuracy is **89.9%** (suffers no performance degradation).

![i2](http://yihui-he.github.io/assets_files/structure-1.png) | ![i1](http://yihui-he.github.io/assets_files/ill-1.png)
:-------------------------:|:-------------------------:
Structured simplification methods | Channel pruning (d)

### Citation
If you find the code useful in your research, please consider citing:

@article{he2017channel,
title={Channel Pruning for Accelerating Very Deep Neural Networks},
author={He, Yihui and Zhang, Xiangyu and Sun, Jian},
journal={arXiv preprint arXiv:1707.06168},
year={2017}
}

### Contents
1. [Requirements](#requirements)
2. [Installation](#installation-sufficient-for-the-demo)
3. [Channel Pruning and finetuning](#channel-pruning)

### requirements
1. Python3 packages you might not have: `scipy`, `sklearn`, `easydict`
2. For finetuning with 128 batch size, 4 GPUs (~11G of memory)

### Installation (sufficient for the demo)
1. Clone the repository
```Shell
# Make sure to clone with --recursive
git clone --recursive https://github.com/yihui-he/channel-pruning.git
```
2. Build my Caffe fork
```Shell
cd caffe
# If you're experienced with Caffe and have all of the requirements installed, then simply do:
make -j8 && make pycaffe
# Or follow the Caffe installation instructions here:
# http://caffe.berkeleyvision.org/installation.html
```
3. Download ImageNet classification dataset
http://www.image-net.org/download-images
Specify imagenet `source` path in `temp/vgg.prototxt` (line 12 and 36)

### Channel Pruning
1. Download the original VGG-16 model
http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel
move it to `temp/vgg.caffemodel` (or create a softlink instead)

2. Start Channel Pruning
```Shell
python3 train.py -action c3 -gpu GPU0
# or log it with ./run.sh python3 train.py -action c3 -gpu GPU0
```
3. Combine some factorized layers for further compression, and calculate the acceleration ratio
```Shell
./combine.sh | xargs ./calflop.sh
```

4. Finetuning
```Shell
./finetune.sh GPU0,GPU1,GPU2,GPU3
```

5. Testing
Though testing is done while finetuning, you can test anytime with:
```Shell
caffe test -model path/to/prototxt -weights path/to/caffemodel -iterations 5000 -gpu GPU0
```
1 change: 1 addition & 0 deletions caffe
Submodule caffe added at 3905e1
2 changes: 2 additions & 0 deletions calflop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python3 tools.py flop $@
#-model temp/cb_3c_3C4x_mem_bn_vgg.prototxt -weights ../caffe/models/vgg16/cb_3c_VGG16.v2.caffemodel
1 change: 1 addition & 0 deletions combine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 train.py -action combine -prototxt temp/3c_3C4x_mem_bn_vgg.prototxt -weights temp/3c_vgg.caffemodel
1 change: 1 addition & 0 deletions finetune.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
caffe train -solver temp/solver.prototxt -weights temp/3c_vgg.caffemodel -gpu $1
Empty file added lib/__init__.py
Empty file.
Loading

0 comments on commit 2c8db9e

Please sign in to comment.