A summary of the steps for optimizing and deploying a model that was trained with the TensorFlow* framework:
Supported Unfrozen Topologies with Links to the Associated Slim Model Classification Download Files
Detailed information on how to convert models from the TensorFlow*-Slim Image Classification Model Library is available in the Converting TensorFlow*-Slim Image Classification Model Library Models chapter. The table below contains list of supported TensorFlow*-Slim Image Classification Model Library models and required mean/scale values. The mean values are specified as if the input image is read in BGR channels order layout like Inference Engine classification sample does.
Model Name | Slim Model Checkpoint File | --mean_values | --scale |
---|---|---|---|
Inception v1 | inception_v1_2016_08_28.tar.gz | [127.5,127.5,127.5] | 127.5 |
Inception v2 | inception_v1_2016_08_28.tar.gz | [127.5,127.5,127.5] | 127.5 |
Inception v3 | inception_v3_2016_08_28.tar.gz | [127.5,127.5,127.5] | 127.5 |
Inception V4 | inception_v4_2016_09_09.tar.gz | [127.5,127.5,127.5] | 127.5 |
Inception ResNet v2 | inception_resnet_v2_2016_08_30.tar.gz | [127.5,127.5,127.5] | 127.5 |
MobileNet v1 128 | mobilenet_v1_0.25_128.tgz | [127.5,127.5,127.5] | 127.5 |
MobileNet v1 160 | mobilenet_v1_0.5_160.tgz | [127.5,127.5,127.5] | 127.5 |
MobileNet v1 224 | mobilenet_v1_1.0_224.tgz | [127.5,127.5,127.5] | 127.5 |
NasNet Large | nasnet-a_large_04_10_2017.tar.gz | [127.5,127.5,127.5] | 127.5 |
NasNet Mobile | nasnet-a_mobile_04_10_2017.tar.gz | [127.5,127.5,127.5] | 127.5 |
ResidualNet-50 v1 | resnet_v1_50_2016_08_28.tar.gz | [103.94,116.78,123.68] | 1 |
ResidualNet-50 v2 | resnet_v2_50_2017_04_14.tar.gz | [103.94,116.78,123.68] | 1 |
ResidualNet-101 v1 | resnet_v1_101_2016_08_28.tar.gz | [103.94,116.78,123.68] | 1 |
ResidualNet-101 v2 | resnet_v2_101_2017_04_14.tar.gz | [103.94,116.78,123.68] | 1 |
ResidualNet-152 v1 | resnet_v1_152_2016_08_28.tar.gz | [103.94,116.78,123.68] | 1 |
ResidualNet-152 v2 | resnet_v2_152_2017_04_14.tar.gz | [103.94,116.78,123.68] | 1 |
VGG-16 | vgg_16_2016_08_28.tar.gz | [103.94,116.78,123.68] | 1 |
VGG-19 | vgg_19_2016_08_28.tar.gz | [103.94,116.78,123.68] | 1 |
Supported Frozen Topologies from TensorFlow Object Detection Models Zoo
Detailed information on how to convert models from the Object Detection Models Zoo is available in the Converting TensorFlow Object Detection API Models chapter. The table below contains models from the Object Detection Models zoo that are supported.
Supported Frozen Quantized Topologies
The topologies hosted on the TensorFlow* Lite site. The frozen model file (.pb file) should be fed to the Model Optimizer.
It is necessary to specify the following command line parameters for the Model Optimizer to convert some of the models from the list above: --input input --input_shape [1,HEIGHT,WIDTH,3]
. Where HEIGHT
and WIDTH
are the input images height and width for which the model was trained.
Other supported topologies
Model Name | Repository |
---|---|
ResNext | Repo |
DenseNet | Repo |
CRNN | Repo |
NCF | Repo |
lm_1b | Repo |
DeepSpeech | Repo |
A3C | Repo |
VDCNN | Repo |
Unet | Repo |
There are three ways to store non-frozen TensorFlow models and load them to the Model Optimizer:
Checkpoint:
In this case, a model consists of two files:
inference_graph.pb
or inference_graph.pbtxt
checkpoint_file.ckpt
If you do not have an inference graph file, refer to Freezing Custom Models in Python.
To convert such TensorFlow model:
<INSTALL_DIR>/deployment_tools/model_optimizer
directorymo_tf.py
script with the path to the checkpoint file to convert a model:.pb
format:.pbtxt
format:MetaGraph:
In this case, a model consists of three or four files stored in the same directory:
model_name.meta
model_name.index
model_name.data-00000-of-00001
(digit part may vary)checkpoint
(optional)To convert such TensorFlow model:
<INSTALL_DIR>/deployment_tools/model_optimizer
directorymo_tf.py
script with a path to the MetaGraph .meta
file to convert a model:SavedModel:
In this case, a model consists of a special directory with a .pb
file and several subfolders: variables
, assets
, and assets.extra
. For more information about the SavedModel directory, refer to the README file in the TensorFlow repository.
To convert such TensorFlow model:
<INSTALL_DIR>/deployment_tools/model_optimizer
directorymo_tf.py
script with a path to the SavedModel directory to convert a model:When a network is defined in Python* code, you have to create an inference graph file. Usually graphs are built in a form that allows model training. That means that all trainable parameters are represented as variables in the graph. To be able to use such graph with Model Optimizer such graph should be frozen. The graph is frozen and dumped to a file with the following code:
Where:
sess
is the instance of the TensorFlow* Session object where the network topology is defined.["name_of_the_output_node"]
is the list of output node names in the graph; frozen
graph will include only those nodes from the original sess.graph_def
that are directly or indirectly used to compute given output nodes. 'name_of_the_output_node'
here is an example of possible output node name. You should derive the names based on your own graph../
is the directory where the inference graph file should be generated.inference_graph.pb
is the name of the generated inference graph file.as_text
specifies whether the generated file should be in human readable text format or binary.To convert a TensorFlow model:
<INSTALL_DIR>/deployment_tools/model_optimizer
directorymo_tf.py
script to simply convert a model with the path to the input model .pb
file: Two groups of parameters are available to convert your model:
NOTE: The Model Optimizer does not revert input channels from RGB to BGR by default, as it did in the 2017 R3 Beta release. Manually specify the command-line parameter to perform this reversion:
--reverse_input_channels
.
The following list provides the TensorFlow*-specific parameters.
NOTE: Models produces with TensorFlow* usually have not fully defined shapes (contain
-1
in some dimensions). It is necessary to pass explicit shape for the input using command line parameter--input_shape
or-b
to override just batch dimension. If the shape is fully defined, then there is no need to specify either-b
or--input_shape
options.
.xml
. For more information about this feature, refer to Offloading Sub-Graph Inference to TensorFlow. .\*InceptionV1/Conv2d_2b_1x1.\*
and .\*InceptionV1/Conv2d_2c_3x3.\*
. Model Optimizer saves part of the model GraphDef into the generated .xml
. For more information about this feature, refer to Offloading Sub-Graph Inference to TensorFlow. Relu,Softm.\*
. In this case, all operations of type Relu
and Softmax
are matched. Model Optimizer saves part of the model GraphDef into the generated XML. For more information about this feature, refer to Offloading Sub-Graph Inference to TensorFlow. transform.json
with information about input and output nodes of the matched sub-graph. For more information about this feature, refer to Sub-Graph Replacement in the Model Optimizer. transform.json
for model conversion. For more information about this feature, refer to Sub-Graph Replacement in the Model Optimizer. /tmp/log_dir
my_custom_op.so
. Model Optimizer falls back to TensorFlow to infer output shape of operations implemented in the library if a custom TensorFlow operation library is provided. If it is not provided, a custom operation with an inference function is needed. For more information about custom operations, refer to the Extending the Model Optimizer with New Primitives. 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.
See Custom Layers in the Model Optimizer for information about:
Refer to Supported Framework Layers for the list of supported standard layers.
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: