Skip to content

zhanghang1989/fb-caffe-exts

 
 

Repository files navigation

Torch to Caffe Model Converter

(forked from Cysu's branch, originally from fb-caffe-exts)

I have stopped maintaining this repo. If you still want to use the converter, please use the AWS option:

The easiest option is to launch an AWS EC2 g2.2xlarge instance I created. Choose N.California Sever and search for the instance name of FB-Torch2Caffe (ami-03542e63). [You can follow the AWS tutorial]

Get Started

  1. Please make sure Torch and Caffe (with pycaffe and python layer) are correctly installed.

  2. Download the code and install the dependencies (:x: If you still would like to set it up on you own workstation, please follow the steps here to install dependencies (fbcunn/install). Good luck!)

    git clone https://github.com/zhanghang1989/fb-caffe-exts.git
    sudo bash install-dep.sh
  3. Add Environment Variables (Change the path for your own machine)

    echo "export LD_PRELOAD=/path/to/libcaffe.so; export PYTHONPATH=$PYTHONPATH:/path/to/caffe/python/:/path/to/fb-caffe-exts/;" >>~/.bashrc && source ~/.bashrc
    source ~/.bashrc
  4. Convert your first model:

    th convert.lua torch_model.t7b
  5. Or custormize the conversion:

    th torch2caffe/torch2caffe.lua --input torch_model.t7b --preprocessing prepnv.lua --prototxt name.prototxt --caffemodel name.caffemodel --input_dims 1 3 224 224

The Layers We Added Support

  1. ELU
  2. SpatialDropout We scale the weights of previous layers by (1-p) to hide the difference between torch and caffe.
  3. SpatialMaxPooling It has slightly different behaviours in Torch and Caffe. Torch uses floor(n/s+1) and Caffe uses floor(n/s). Therefore, only the conversion of even featuremap size is supported.
  4. SpatialBatchNormalization Caffe BatchNorm doesn't have bias. We only support non-affine BN. Alternatively, you can convert it into a customized version of BN as in Cysu's branch.

Known Issues

  1. LD_PRELOAD crashes your gedit (If you know how to fix it, please update this wiki.)
  2. The opencv package that Caffe relies on may cause the error of "libdc1394" failed to initialize, just create a fake device:
sudo ln /dev/null /dev/raw1394

Releases

No releases published

Packages

No packages published

Languages

  • Lua 63.4%
  • Python 29.2%
  • Shell 7.4%