Generate an optimized 32-bit model

This step primarily removes unnecessary nodes and ensures that the operations that are used are available in the TensorFlow distributions on mobile devices. One way it does this is by removing training-specific operations in the model's computational graph.

To generate your model, enter the following on the command line:

bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=resnet_v2_50.pb \
--out_graph=optimized_resnet_v2_50_fp32.pb \
--inputs='Placeholder' \
--outputs='resnet_v2_50/predictions/Reshape_1' \
--transforms='strip_unused_nodes(type=float, shape="1,224,224,3")

The input and output names depend on your model. The shape is also included here as part of the strip_unused_nodes command.

If you encounter any problems, the TensorFlow documentation covers this step in more detail.

The transformed model does not differ greatly in size or speed from the training model. The difference is that it is capable of being loaded by the TensorFlow distribution for mobile devices, which may not implement all training operators.

It is a good idea to verify that this inference-ready model runs with the same accuracy as your trained one. How you do this depends on your training/test workflow and datasets.

You can now distribute this model and deploy it with TensorFlow on both mobile and embedded or low-power Linux devices.

Previous Next