Tensorflow: How does tensorflow connect python and C++ in details? -


what i'm trying do

i'm trying make modification conv_ops in tensorflow filters used convolution in consist of binary numbers.

what have done

following suggestion in this tensorflow issue, didn't create custom op. instead, copy code in conv_ops.cc , change names from

register_kernel_builder( name("conv2d").device(device_gpu).typeconstraint<eigen::half>("t"), conv2dop<gpudevice, eigen::half>); register_kernel_builder( name("conv2d").device(device_gpu).typeconstraint<float>("t"), conv2dop<gpudevice, float>); 

to

register_kernel_builder( name("binaryconv2d").device(device_gpu).typeconstraint<eigen::half>("t"), binaryconv2dop<gpudevice, eigen::half>); register_kernel_builder( name("binaryconv2d").device(device_gpu).typeconstraint<float>("t"), binaryconv2dop<gpudevice, float>); 

after modification, have make new op same conv_ops. in order bypass problem functor:sign in //tensorflow/core/kernels/cwise_ops.h not easy use simple functors functor:relu in //tensorflow/core/kernels/relu_op_functor.h. decide add input(binarized_filter) new op binaryconv2d. in way can use op tf.sign safely make binary filter.

what problem is

although have changed registration in nn_ops.cc as

register_op("binaryconv2d")     .input("input: t")     .input("filter: t")     .input("binarized_filter: t")     .output("output: t")     .attr("t: {half, float, double}")     .attr("strides: list(int)")     .attr("use_cudnn_on_gpu: bool = true")     .attr(getpaddingattrstring())     .attr(getconvnetdataformatattrstring()) 

and generated python code becomes:

result = _op_def_lib.apply_op("binaryconv2d", input=input, filter=filter,                                 binarized_filter=binarized_filter,                                 strides=strides, padding=padding,                                 use_cudnn_on_gpu=use_cudnn_on_gpu,                                 data_format=data_format, name=name) 

i use sign op inside binarized_filter:

  import tensorflow tf   binarized_filter = tf.sign(filter) 

i got error as:

w tensorflow/core/framework/op_kernel.cc:926] invalid argument: signature mismatch, have: float, float, float->float expected: float, float->float e tensorflow/core/common_runtime/executor.cc:334] executor failed create kernel. invalid argument: signature mismatch, have: float, float, float->float expected: float, float->float      [[node: conv1/binaryconv2d = binaryconv2d[t=dt_float, data_format="nhwc", padding="same", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch, conv1/weights/read, conv1/sign)]] e tensorflow/core/client/tensor_c_api.cc:485] signature mismatch, have: float, float, float->float expected: float, float->float      [[node: conv1/binaryconv2d = binaryconv2d[t=dt_float, data_format="nhwc", padding="same", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch, conv1/weights/read, conv1/sign)]] traceback (most recent call last): 

i have checked value of input types in graph in //tensorflow/python/framework/op_def_library.py. right. assume input number defined in c++ still not correct, can find no example or document except source code can provide information how c++ code , python code of tensorflow associated. want know if have missed part of building op in procedure of modification.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -