Giter Club home page Giter Club logo

thinet_code's Introduction

Caffe Implementation of ThiNet

Requirements

Python 2.6 & Caffe environment:

  • Python2.6
  • Caffe & Caffe's Python interface

Usage

  1. Clone the ThiNet repository.
  2. select ThiNet_ICCV or ThiNet_TPAMI subfolder:
    cd ThiNet_ICCV
    
  3. modify your configuration path:
    • modify the caffe path (caffe_root) at the beginning of net_generator.py and compress_model.py
    • modify ImageNet lmdb file path in line 212 and line 217 of net_generator.py
    • modify ImageNet dataset path in line 54, 55, 60 of compress_model.py
    • modify line 2 and 4 in run_this.sh with correct file path.
  4. Run the pruning demo:
    ./run_this.sh
    

Other Toolkits

  • Image Resize:

    • Note that there are two different strategies to organize ImageNet dataset:
      1. fixed size: each image is firstly resized to 256ร—256, then center-cropped to obtain a 224ร—224 regin;
      2. keep aspect ratio: each image is firstly resized with shorter side=256, then center-cropped;
    • The default caffe create_lmdb.sh file will convert images into 256x256. If you want to keep the original ratio:
      1. replace caffe/src/caffe/util/io.cpp with toolkit/caffe_lmdb_keep_ratio/io.cpp
      2. rebuild caffe
      3. use the provided script toolkit/caffe_lmdb_keep_ratio/create_lmdb.sh to create the lmdb file
      4. and, do not forget to modify the configuration path of this script.
  • FLOPs Calculation:

    cd toolkit
    modify the caffe_root at the beginning of FLOPs_and_size.py file.
    python FLOPs_and_size.py [the path of *.prototxt file]
    

    NOTE: we regard the vector multiplication as TWO float-point operations (multiplication and addition). In some paper, it is calculated as ONE operation. Do not be confused if the result is twice larger.

Results

We prune the VGG_ILSVRC_16_layers model on ImageNet dataset with ratio=0.5:

Method Top-1 Acc. Top-5 Acc. #Param. #FLOPs
original VGG16 71.50% 90.01% 138.24M 30.94B
ThiNet_ICCV 69.80% 89.53% 131.44M 9.58B
ThiNet_TPAMI 69.74% 89.41% 131.44M 9.58B

There are no difference on VGG16, but ThiNet_TPAMI is much better on ResNet50:

Method Top-1 Acc. Top-5 Acc. #Param. #FLOPs
original ResNet50 75.30% 92.20% 25.56M 7.72B
ThiNet_ICCV 72.04% 90.67% 16.94M 4.88B
ThiNet_TPAMI 74.03% 92.11% 16.94M 4.88B

Citation

If you find this work is useful for your research, please cite:

@CONFERENCE{ThiNet_ICCV17,
  author={Jian-Hao Luo, Jianxin Wu, and Weiyao Lin},
  title={ThiNet: A Filter Level Pruning Method for Deep Neural Network Compression},
  booktitle={ICCV},
  year = {2017},
  pages={5058-5066},
}
@article{ThiNet_TPAMI,
  author = {Jian-Hao Luo, Hao Zhang, Hong-Yu Zhou, Chen-Wei Xie, Jianxin Wu, and Weiyao Lin},
  title = {ThiNet: Pruning CNN Filters for a Thinner Net},
  journal = {IEEE Trans. on Pattern Analysis and Machine Intelligence},
  year = {2008},
}

Contact

Feel free to contact me if you have any question (Jian-Hao Luo [email protected] or [email protected]).

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.