我尝试扩展tensorflow库:https://www.tensorflow.org/extend/adding_an_op
REGISTER_OP("Test")
.Input("input: string")
.Attr("test: float")
.Output("output: string")
.Doc(R"doc("some douc")doc");
class Test : public OpKernel {
public:
explicit Test(OpKernelConstruction* context) : OpKernel(context)
{
std::cout << "Why is this not printing" << std::endl;
std::string input;
OP_REQUIRES_OK(context, context->GetAttr("test", &input));
std::cout << input << std::endl;
}
void Compute(OpKernelContext* context) override
{
std::cout << "Why is that not printing? " << std::endl;
Tensor input_tensor = context->input(0);
Tensor* output_tensor = nullptr;
OP_REQUIRES_OK(context, context->allocate_output("output",
input_tensor.shape(), &output_tensor));
auto output = output_tensor->flat<string>();
}
};
REGISTER_KERNEL_BUILDER(Name("Test") \
.Device(DEVICE_CPU), \
Test);
为什么这个功能不打印?但是当我启动函数时,我得到一个返回值。我认为打印不可能,不是吗?
编辑:我如何在main.py中调用它?
import tensorflow as tf
import tensorflow.contrib.icg as tficg
if __name__ == '__main__':
print('start')
print(tficg.stereo_matching('hello', 1))
输出:
start
Tensor("StereoMatching:0", dtype=string)
答案 0 :(得分:0)
这应该打印。你在看stdout和stderr吗?