GithubHelp home page GithubHelp logo

lufeng22 / auto_pruning Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nhzlx/auto_pruning

0.0 1.0 0.0 109.92 MB

auto Iterative pruning based on caffe

License: Other

CMake 2.83% Makefile 0.67% Shell 0.41% C++ 80.17% Cuda 6.51% MATLAB 0.90% M 0.01% Python 8.53%

auto_pruning's Introduction

new add layer:

  • compress_conv_layer
  • compress_inner_product_layer

Usage:

#compress convolution layer
layer {
  name: "conv2"
  type: "CConvolution"  #compress convolution type
  bottom: "pool1"
  top: "conv2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 50
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
 cconvolution_param{
   upper_bound: 0.94 #最终达到的稀疏度
   iter_stop: 30000  #到达iter_stop后,不再进行压缩,一般为inter_iter的20倍
   inter_iter: 1500  #每inter_iter 进行一次稀疏变化,一般这个数为3个epoch包含的iter数
 }
}

# compress fc layer
layer {
  name: "ip2"
  type: "CInnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 10
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
 cinner_product_param{
   iter_stop: 30000
   upper_bound: 0.97
   inter_iter: 1500
 }
}

Process of sparsity changes

整个fine-tune过程为一个阶段,为每层设定一个upperbound稀疏度,稀疏度从0开始,整个过程稀疏变化次数为 iter_stop / inter_iter,每过inter_iter次iter 变化一次。 正如上图所示,变化过程为一个log曲线,训练后期, 参数比较少, 一次性prune掉较多参数会导致accuracy严重下降, 因而前期稀疏度上升比较大,越到后期上升幅度小。 训练结束的模型*.caffemodel,除了存储parameter还有mask, 所以比原始模型大一倍是正常的。后续须自行处理。

Examples

lenet

./examples/mnist/train_pruning.sh

Vgg-s

#模型太大,未上传,原始模型以及数据具体见 https://github.com/jimgoo/caffe-oxford102

Mobilenet

oxford flowers 102上 所有1*1 卷积压缩可达到71% 精度损失在0.05内

cd models/oxford
./train_mobilenet.sh  #train the mobilenet 
./train_pruning.sh    # pruning a pre-trained models

Note:
I did this work during my internship at Baidu IDL Paddle group.

auto_pruning's People

Contributors

nhzlx avatar

Watchers

 avatar

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.