forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,4 @@ R-package/inst/* | |
|
||
# ipython notebook | ||
example/notebooks/.ipynb_checkpoints/* | ||
*_pb2.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# find protoc | ||
ifndef PROTOC | ||
DEPS_PROTOC=../../deps/bin/protoc | ||
ifneq ("$(wildcard $(DEPS_PROTOC))","") | ||
PROTOC = $(DEPS_PROTOC) | ||
else | ||
PROTOC = protoc | ||
endif | ||
endif | ||
|
||
all: caffe_parse/caffe_pb2.py | ||
|
||
clean: | ||
rm caffe_parse/caffe_pb2.py* | ||
|
||
caffe_parse/caffe_pb2.py: | ||
$(PROTOC) --python_out=./ ./caffe_parse/caffe.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
# Convert Caffe Model to Mxnet Format | ||
|
||
## Introduction | ||
This tool converts a caffe model into mxnet's format. | ||
|
||
This is an experimental tool for conversion of Caffe model into mxnet model. Caffe installation isn't a must. There are several limitations to note: | ||
* Please first make sure that there is corresponding operator in mxnet before conversion. | ||
* The tool only supports single input and single output network. | ||
* The tool can only work with the L2LayerParameter in Caffe. For older version, please use the ```upgrade_net_proto_binary``` and ```upgrade_net_proto_text``` in ```tools``` folder of Caffe to upgrate them. | ||
## Build | ||
If the Caffe python package is installed then no other step is required for | ||
using. Otherwise, it requires Google protobuf to compile Caffe's model | ||
format. One can either install protobuf by using package manager or build from | ||
the source. For the latter, one can set `USE_DIST_KVSTORE = 1` when compiling | ||
mxnet, namely | ||
|
||
``` | ||
make -C ../.. USE_DIST_KVSTORE = 1 | ||
``` | ||
|
||
We have verified the results of VGG_16 model and BVLC_googlenet results from Caffe model zoo. | ||
Once `protobuf` is available, then run `make` in the current directory. | ||
|
||
## Notes on Codes | ||
* The core function for converting symbol is in ```convert_symbols.py```. ```proto2script``` converts the prototxt to corresponding python script to generate the symbol. Therefore if you need to modify the auto-generated symbols, you can print out the return value. You can also find the supported layers/operators there. | ||
* The weights are converted in ```convert_model.py```. | ||
* ```caffe_parse/caffe_pb2.py``` will be generated by ```make tools``` in the root of this project. ```caffe_parse/caffe.proto``` is from caffe project. and ```caffe_parse/parse_from_protobuf.py``` loads caffemodel without caffe installation. | ||
* Make sure ```protobuf``` has been installed. Get [protobuf](https://github.com/google/protobuf) source code, follow the installation steps. | ||
## How to use | ||
|
||
## Usage | ||
Run ```make tools``` in the root of the project. (if caffe was not installed) | ||
Run ```python convert_model.py caffe_prototxt caffe_model save_model_name``` to convert the models. Run with ```-h``` for more details of parameters. | ||
|
||
|
||
Or use `./run.sh model_name` to download and convert a model. Sample usage: | ||
`./run.sh vgg19` | ||
|
||
## Note | ||
|
||
* We have verified the results of VGG_16 model and BVLC_googlenet results from Caffe model zoo. | ||
* The tool only supports single input and single output network. | ||
* The tool can only work with the L2LayerParameter in Caffe. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
if [[ $# -ne 1 ]]; then | ||
echo "usage: $0 model_name" | ||
echo " model_name: vgg19, ..." | ||
exit -1 | ||
fi | ||
|
||
if [[ $1 == "vgg19" ]]; then | ||
if [[ ! -f VGG_ILSVRC_19_layers_deploy.prototxt ]]; then | ||
wget -c https://gist.githubusercontent.com/ksimonyan/3785162f95cd2d5fee77/raw/bb2b4fe0a9bb0669211cf3d0bc949dfdda173e9e/VGG_ILSVRC_19_layers_deploy.prototxt | ||
fi | ||
|
||
if [[ ! -f VGG_ILSVRC_19_layers.caffemodel ]]; then | ||
wget -c http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_19_layers.caffemodel | ||
fi | ||
|
||
echo "converting" | ||
python `dirname $0`/convert_model.py VGG_ILSVRC_19_layers_deploy.prototxt VGG_ILSVRC_19_layers.caffemodel vgg19 | ||
else | ||
echo "unsupported model: $1" | ||
fi |