Skip to content

Model Convert Guide

Jintao Meng edited this page Aug 11, 2018 · 3 revisions

Model Convert Guide

FeatherCNN has its own model format, so it requires converting pre-trained models before use. Currently it only accepts Caffe models, we will add support to models train with other tools in the near future. This guide is only for Ubuntu, we demonstrate in a freshly installed Ubuntu 18.04.

Note

If your model is trained with early version of Caffe (like those models hosted in Model-Zoo), this tool is incapable to convert the layers. In this case, you should first upgrade prototxt and caffemodel with the official tools upgrade_net_proto_text and upgrade_net_proto_binary using the following commands, these two tools should come with caffe when install with apt-get.

upgrade_net_proto_text net_deploy_old.prototxt net_deploy_upgrade.prototxt
upgrade_net_proto_binary net_deploy_old.caffemodel net_deploy_upgrade.caffemodel

Building converting tools

  • Enter the tools folder.
  • Install protobuf (dependency for caffemodel), see Google's official installation guide. Our conversion tool also requires pkg-config to build. For Ubuntu users, we have collected all the installation steps in the install_protobuf.sh script. This script installs protobuf to /usr/local/.
./install_protobuf.sh

Tips: Building protobuf takes a long time. Use make -j4 in line 21 would invoke multiple threads to accelerate compilation, where 4 should be replaced by proper number of threads.

  • Run build.sh
./build.sh

The build script first invoke the protoc to generate caffe.pb.cc and caffe.pb.h, and then compiles our tool.

Convert Caffe models

Usage:

./caffe_model_convert $1(caffe_prototxt) $2(caffe_model_name) [$3(output_model_name_prefix)]

Example

./caffe_model_convert ./mobilenet.prototxt ./mobilenet.caffemodel ./mobilenet

And you should see mobilenet.feathermodel in this directory. If the 3rd parameter is skipped, the default output file is out.feathermodel.