Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
gradle/wrapper
scripts
src/main
README.md
build.gradle
build_from_source.md
faq.md
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

Caffe Translator

Caffe Translator is a migration tool that helps developers migrate their existing Caffe code to MXNet and continue further development using MXNet. Note that this is different from the Caffe to MXNet model converter which is available here.

Caffe Translator takes the training/validation prototxt (example) and solver prototxt (example) as input and produces MXNet Python code (example) as output. The translated Python code uses MXNet Symbol and Module API to build the network, reads data from LMDB files (example), runs training and saves the trained model using the MXNet Module API (example).

How to use

Get the translator:

Download the Caffe Translator from maven repository or build from source. Java Runtime Environment (JRE) is required to run the translator.

Translate code:

To translate train_val.prototxt and solver.prototxt to MXNet Python code, run the following command:

java -jar caffe-translator-<version>.jar --training-prototxt <train_val_prototxt_path> \
    --solver <solver_prototxt_path> \
    --output-file <output_file_path>

Example:

java -jar caffe-translator-0.9.1.jar --training-prototxt lenet_train_test.prototxt \
    --solver lenet_solver.prototxt \
    --output-file translated_code.py

Here is the list of command line parameters accepted by the Caffe Translator:

  • training-prototxt: specifies the path to the training/validation prototxt to be translated.
  • solver-prototxt: specifies the path to the solver prototxt to be translated.
  • output-file: specifies the file to write the translated output into.
  • params-file (optional): specifies the .caffemodel file to initialize parameters from.
  • custom-data-layers (optional): Specifies a comma-separated list of types of the custom data layers used in the prototxt. The translator will use CaffeDataIter to translate these layers to MXNet.

Note: Translated code uses CaffeDataIter to read from LMDB files. CaffeDataIter requires the number of examples in LMDB file to be specified as a parameter. You can provide this information before translation using a #CaffeToMXNet directive like shown below:

  data_param {
    source: "data/mnist/mnist_train_lmdb"
    #CaffeToMXNet num_examples: 60000
    batch_size: 64
    backend: LMDB
  }

Run the translated code:

Following prerequisites are required to run the translated code:

  1. Caffe with MXNet interface (Why? How to build?)
  2. MXNet with Caffe plugin (How to build?)
  3. The dataset in LMDB format.

Once prerequisites are installed, the translated Python code can be run like any other Python code:

Example:

python translated_code.py

What layers are supported?

Caffe Translator can currently translate the following layers:

  • Accuracy and Top-k
  • Batch Normalization
  • Concat
  • Convolution
  • Data*
  • Deconvolution
  • Eltwise
  • Inner Product (Fully Connected layer)
  • Flatten
  • Permute
  • Pooling
  • Power
  • Relu
  • Scale*
  • SoftmaxOutput

* Uses CaffePlugin

If you want Caffe Translator to translate a layer that is not in the above list, please create an issue.

You can’t perform that action at this time.