Skip to content

Add and Remove Ops

Philip Dow edited this page Jan 23, 2020 · 1 revision

Op Errors

When you load your saved model on device you may see errors indicating that some ops are unsupported, such as the following:

Unable to load saved model, status: Invalid argument: No OpKernel was registered to support Op {MissingOpName} ...

Adding Ops

In this case it is necessary to rebuild tensorflow with those ops enabled. This is usually as simple as searching for the op name in the tensorflow project, identifying the file that implements that op, and including the filename in tensorflow/contrib/makefile/tf_op_files.txt.

You're looking for the file that includes something like:

REGISTER_KERNEL_BUILDER(Name("{MissingOpName}") ...

The change will usually require the addition of a file in tensorflow/core/kernels and perhaps one in tensorflow/core/ops, and the process may be iterative with multiple builds and tests until you have identified all the ops your model requires.

For example, we recently added support for the TensorFlow Privacy library, which implements differentially private versions of common optimizers. To do so, we added the following lines to tf_op_files.txt and rebuilt tensorflow with the build_all_ios.sh script:

tensorflow/core/kernels/gather_op.cc
tensorflow/core/kernels/mutex_ops.cc

Replacing Tensorflow

When we do this we repackage our custom build of TensorFlow into this framework and update the Cocoapod. For local testing you'll find the generated library in the tensorflow/contrib/makefile/gen/lib folder. Rename the library to tensorflow, make it executable with chmod +x tensorflow, and replace the library in your local copy of this framework with the newly generated one.

Clone this wiki locally