You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/01 00:24:01 UTC

[GitHub] indhub commented on a change in pull request #8782: Caffe to MXNet code translator

indhub commented on a change in pull request #8782: Caffe to MXNet code translator
URL: https://github.com/apache/incubator-mxnet/pull/8782#discussion_r154240149
 
 

 ##########
 File path: tools/caffe_translator/README.md
 ##########
 @@ -0,0 +1,78 @@
+# Caffe Translator
+Caffe Translator is a source code translator that translates Caffe code into MXNet Python code. Note that this is different from the Caffe to MXNet model converted which is available [here](https://github.com/apache/incubator-mxnet/tree/master/tools/caffe_converter).
+
+Caffe Translator takes the training/validation prototxt ([example](https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet_train_test.prototxt)) and solver prototxt ([example](https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet_solver.prototxt)) as input and produces MXNet Python code as output. The translated Python code uses MXNet Symbol and Module API to build the network, reads data from LMDB files, runs training and saves the trained model using the MXNet Module API.
+
+### How to use
+
+#### Get the translator:
+Download the Caffe Translator from maven [repository](https://mvnrepository.com/artifact/org.caffetranslator/caffe-translator) or [build](build_from_source.md) 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`](https://mxnet.incubator.apache.org/how_to/caffe.html#use-io-caffedataiter) to translate these layers to MXNet.
+
+**Note:** Translated code uses [`CaffeDataIter`](https://mxnet.incubator.apache.org/how_to/caffe.html#use-io-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 `#caffe2mxnet` directive like shown below:
+
+```
+  data_param {
+    source: "data/mnist/mnist_train_lmdb"
+    #caffe2mxnet 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?](faq.md#why_caffe) [How to build?](https://github.com/apache/incubator-mxnet/tree/master/plugin/caffe#install-caffe-with-mxnet-interface))
+2. MXNet with Caffe plugin ([How to build?](https://github.com/apache/incubator-mxnet/tree/master/plugin/caffe#compile-with-caffe))
+
+Once prerequisites are installed, the translated Python code can be run like any other Python code:
+
+Example:
+```
 
 Review comment:
   Here is an example:
   
   Input:
   https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet_train_test.prototxt
   https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet_solver.prototxt
   
   Output:
   https://gist.github.com/indhub/85d8b82728f986a809b8cc99ab440792
   
   I'll try to add this to the repo too. Only problem is I'll have to add apache license to the output if I have to put it in the repo and that could confuse users (make them wonder if Apache license applies to the generated code). Any suggestion to avoid that confusion (apart from explaining it in readme)?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services