Skip to content

Commit

Permalink
caffe_converter: fixed bug parsing caffemodel files on windows (file …
Browse files Browse the repository at this point in the history
…should be opened in binary mode) (apache#2504)

caffe_converter: added instructions and build script for usage on windows.
  • Loading branch information
alex-weaver authored and tqchen committed Jun 22, 2016
1 parent 1934de5 commit bf7798d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
20 changes: 18 additions & 2 deletions tools/caffe_converter/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Convert Caffe Model to Mxnet Format

### Build
### Build (Linux)

Either [Caffe's python package](http://caffe.berkeleyvision.org/installation.html) or [Google protobuf](https://developers.google.com/protocol-buffers/?hl=en) is required. The latter is often much easier to install:

Expand All @@ -10,9 +10,25 @@ Either [Caffe's python package](http://caffe.berkeleyvision.org/installation.htm

Now we can build the tool by running `make` in the current directory.

### Build (Windows)

Note: this tool currently only works on python 2.

We must make sure that the installed python binding and protobuf compiler are using the same version of protobuf,
so we install the bindings first, and then install the corresponding compiler.

1. Install the protobuf bindings. At time of writing, the conda package manager has the most up to date version. Either run `conda install -c conda-forge protobuf` or `pip install protobuf`
2. Download the win32 build of protoc from [Protocol Buffers Releases](https://github.com/google/protobuf/releases). Make sure to download the version that corresponds to the version of the bindings. Extract to any location then add that location to your `PATH`
3. Run `make_win32.bat` to build the package


### How to use

Use `./run.sh model_name` to download and convert a model. E.g. `./run.sh vgg19`
Linux: Use `./run.sh model_name` to download and convert a model. E.g. `./run.sh vgg19`

Windows: Use `python convert_model.py prototxt caffemodel outputprefix`
For example: `python convert_model.py VGG_ILSVRC_16_layers_deploy.prototxt VGG_ILSVRC_16_layers.caffemodel vgg16`


### Note

Expand Down
2 changes: 1 addition & 1 deletion tools/caffe_converter/caffe_parse/parse_from_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def parse_caffemodel(filepath):
returns: layers
'''
f = open(filepath)
f = open(filepath, 'rb')
contents = f.read()

netparam = caffe_pb2.NetParameter()
Expand Down
3 changes: 3 additions & 0 deletions tools/caffe_converter/make_win32.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@protoc --python_out=./ ./caffe_parse/caffe.proto
@echo done.
@pause

0 comments on commit bf7798d

Please sign in to comment.