tensorflow "adding an op" 调试?

tensorflow "adding an op" debugging?

我尝试扩展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);

为什么这个函数不打印?但是当我启动该函数时,我得到了一个 return 值。我认为不可能打印一些东西,不是吗?


编辑:我如何在 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)

这应该打印出来。您在查看 stdout 和 stderr 吗?