i learn best way modify tensorflow built-in operator kernels. example, want modify value of static const double a
in tensorflow/core/kernels/resize_bicubic_op.cc
. have come 2 possible ways:
modify directly , recompile whole tensorflow library. problems of solution are: a. influences functions use bicubic interpolation. b. requires me recompile entire library , not work when installing binary.
define custom op. problem in source code, there no
register_op()
inside. don't know how writeregister_op()
bicubic function , whether other modification needs made.
are there other better ways?
thanks.
the best way approach problem build custom op. see this tutorial more details how add custom ops in general. register_op
call tf.image.resize_bicubic()
op in tensorflow/core/ops/image_ops.cc
.
another alternative re-use same op registration, , register new kernel alternative implementation. enable use (experimental) graph.kernel_label_map()
api select alternative implementation "resizebicubic"
op. example, following in python program:
_ = tf.load_op_library(...) # load .so containing implementation. tf.get_default_graph().kernel_label_map({"resizebicubic": "my_impl"}): images = tf.image.resize_bicubic(...) # use implementation.
...and add kernel registration specifies label "my_impl"
c++ code:
template <typename device, typename t> class myresizebicubicop<device, t> : public opkernel { // custom implementation goes here... } #define register_kernel(t) \ register_kernel_builder(name("resizebicubic") \ .device(device_cpu) \ .label("my_impl") \ .typeconstraint<t>("t") \ .hostmemory("size"), \ myresizebicubicop<cpudevice, t>); tf_call_real_number_types(register_kernel);
Comments
Post a Comment