How to add custom op in tensorflow serving ?
Using tensorflow serving r1.6, I tried adding my custom op in tensorflow_serving/model_servers/BUILD here
SUPPORTED_TENSORFLOW_OPS = [
"@org_tensorflow//tensorflow/contrib:contrib_kernels",
"@org_tensorflow//tensorflow/contrib:contrib_ops_op_lib",
"//tensorflow_serving/myop:myOp.so" #Added this line
]
And myOp/BUILD:
package(
default_visibility = [
"//tensorflow_serving:internal",
],
features = ["-layering_check"],
)
cc_library(
name = "myOp.so",
visibility = ["//visibility:public"],
srcs = [
"myOp.cc",
"myOp.h"
] ,
copts = ["-std=c++11"],
deps = ["@org_tensorflow//tensorflow/core:framework_headers_lib",
"@org_tensorflow//tensorflow/core/util/ctc",
"@org_tensorflow//third_party/eigen3",
],
)
But I get this error while launching tensorflow_model_server Loading servable: {name: myModel version: 1} failed: Not found: Op type not registered 'MyOp' in binary running on 43e23d7f1ad2. Make sure the Op and Kernel are registered in the binary running in this process.
myOp.cc has been implemented exactly like described in https://www.tensorflow.org/versions/r1.6/extend/adding_an_op with REGISTER_OP and REGISTER_KERNEL_BUILDER(Name("MyOp").Device(DEVICE_CPU), MyOpOp);
How can we add custom Op in tensorflow serving?
Be sure to specify alwayslink=1 in your myOp's cc_library rule. Otherwise the linker may be pruning it away.
By adding alwayslink=1 , it worked !!
Should we need to build TFServing from scratch to load/add Custom Op? any alternate way possible?
Should we need to build TFServing from scratch to load/add
Custom Op? any alternate way possible?
Nope, it seems bazel will do the cache, so only build the Custom Op
Should we need to build TFServing from scratch to load/add
Custom Op? any alternate way possible?Nope, it seems bazel will do the cache, so only build the
Custom Op
Once TFServing is built from source, I could run tensorflow-serving with,
bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server
How could I use that custom built Tensorflow Serving in another PC?