Converting a Caffe* Model

A summary of the steps for optimizing and deploying a model that was trained with Caffe*:

  1. Configure the Model Optimizer for Caffe*.
  2. Convert a Caffe* Model to produce an optimized Intermediate Representation (IR) of the model based on the trained network topology, weights, and biases values
  3. Test the model in the Intermediate Representation format using the Inference Engine in the target environment via provided Inference Engine sample applications
  4. Integrate the Inference Engine in your application to deploy the model in the target environment

Supported Topologies

NOTE: It is necessary to specify mean and scale values for most of the Caffe* models to convert them with the Model Optimizer. The exact values should be determined separately for each model. For example, for Caffe* models trained on ImageNet, the mean values usually are 123.68, 116.779, 103.939 for blue, green and red channels respectively. The scale value is usually 127.5. Refer to Framework-agnostic parameters for the information on how to specify mean and scale values.

Convert a Caffe* Model

To convert a Caffe* model:

  1. Go to the <INSTALL_DIR>/deployment_tools/model_optimizer directory.
  2. Use the script to simply convert a model with the path to the input model .caffemodel file:
    python3 --input_model <INPUT_MODEL>.caffemodel

Two groups of parameters are available to convert your model:

Using Caffe*-Specific Conversion Parameters

The following list provides the Caffe*-specific parameters.

Caffe*-specific parameters:
--input_proto INPUT_PROTO, -d INPUT_PROTO
Deploy-ready prototxt file that contains a topology
structure and layer attributes
--caffe_parser_path CAFFE_PARSER_PATH
Path to python Caffe parser generated from caffe.proto
-k K Path to CustomLayersMapping.xml to register custom
--mean_file MEAN_FILE, -mf MEAN_FILE
Mean image to be used for the input. Should be a
binaryproto file
--mean_file_offsets MEAN_FILE_OFFSETS, -mo MEAN_FILE_OFFSETS
Mean image offsets to be used for the input
binaryproto file. When the mean image is bigger than
the expected input, it is cropped. By default, centers
of the input image and the mean image are the same and
the mean image is cropped by dimensions of the input
image. The format to pass this option is the
following: "-mo (x,y)". In this case, the mean file is
cropped by dimensions of the input image with offset
(x,y) from the upper left corner of the mean image
Disable omitting optional attributes to be used for
custom layers. Use this option if you want to transfer
all attributes of a custom layer to IR. Default
behavior is to transfer the attributes with default
values and the attributes defined by the user to IR.
Enable flattening optional params to be used for
custom layers. Use this option if you want to transfer
attributes of a custom layer to IR with flattened
nested parameters. Default behavior is to transfer the
attributes without flattening nested parameters.

Command-Line Interface (CLI) Examples Using Caffe*-Specific Parameters

Custom Layer Definition

Internally, when you run the Model Optimizer, it loads the model, goes through the topology, and tries to find each layer type in a list of known layers. Custom layers are layers that are not included in the list of known layers. If your topology contains any layers that are not in this list of known layers, the Model Optimizer classifies them as custom.

Supported Caffe* Layers

Refer to Supported Framework Layers for the list of supported standard layers.

Frequently Asked Questions (FAQ)

The Model Optimizer provides explanatory messages if it is unable to run to completion due to issues like typographical errors, incorrectly used options, or other issues. The message describes the potential cause of the problem and gives a link to the Model Optimizer FAQ. The FAQ has instructions on how to resolve most issues. The FAQ also includes links to relevant sections in the Model Optimizer Developer Guide to help you understand what went wrong.


In this document, you learned: