如何在C ++自定义OP中打印张量?

时间:2018-12-20 17:28:40

标签: python c++ tensorflow

我正在尝试遵循此answer或此one。但是我找不到这两种方法1. docs中的t.DebugString()或t.vec()。我使用的版本均为1.8,最新版本为1.12。我只是使用如下调试字符串尝试了第一个答案:

void Compute(OpKernelContext* context) override 
  {
    // Grab the input tensor
    const Tensor& bottom_prediction = context->input(0);
    const Tensor& bottom_target = context->input(1);
    const Tensor& bottom_weight = context->input(2);
    const Tensor& bottom_point = context->input(3);
    const Tensor& bottom_symmetry = context->input(4);
    std::cout << bottom_prediction.DebugString() << ", " << bottom_weight.DebugString() << ", " << bottom_weight.DebugString() << ", " << bottom_point.DebugString()
     << ", " << bottom_symmetry.DebugString() << std::endl;

但是运行此程序时出现段错误。 GDB第一行看起来像这样:

0x00007ffec42be4e4 in void tensorflow::(anonymous namespace)::PrintOneDim<float>(int, tensorflow::gtl::InlinedVector<long long, 4> const&, long long, int, float const*, long long*, std::string*) ()

整个堆栈跟踪为:

(gdb) where
#0  0x00007ffec42be4e4 in void tensorflow::(anonymous namespace)::PrintOneDim<float>(int, tensorflow::gtl::InlinedVector<long long, 4> const&, long long, int, float const*, long long*, std::string*) ()
   from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#1  0x00007ffec42c99a4 in tensorflow::Tensor::SummarizeValue(long long) const ()
   from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#2  0x00007ffec42c9e09 in tensorflow::Tensor::DebugString() const ()
   from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#3  0x00007fffc2b51a9d in AveragedistanceOp<Eigen::GpuDevice, float>::Compute(tensorflow::OpKernelContext*) ()
   from /mnt/drive_c/datasets/<username>/PoseCNN/tools/../lib/average_distance_loss/average_distance_loss.so
#4  0x00007ffec471ec26 in tensorflow::BaseGPUDevice::ComputeHelper(tensorflow::OpKernel*, tensorflow::OpKernelContext*) ()
   from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#5  0x00007ffec471ef70 in tensorflow::BaseGPUDevice::Compute(tensorflow::OpKernel*, tensorflow::OpKernelContext*) ()
   from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#6  0x00007ffec476897d in tensorflow::(anonymous namespace)::ExecutorState::Process(tensorflow::(anonymous namespace)::ExecutorState::TaggedNode, long long) () from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#7  0x00007ffec476919a in std::_Function_handler<void (), tensorflow::(anonymous namespace)::ExecutorState::ScheduleReady(tensorflow::gtl::InlinedVector<tensorflow::(anonymous namespace)::ExecutorState::TaggedNode, 8> const&, tensorflow::(anonymous namespace)::ExecutorState::TaggedNodeReadyQueue*)::{lambda()#1}>::_M_invoke(std::_Any_data const&) ()
   from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#8  0x00007ffec43ce66a in Eigen::NonBlockingThreadPoolTempl<tensorflow::thread::EigenEnvironment>::WorkerLoop(int) ()
   from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#9  0x00007ffec43cd712 in std::_Function_handler<void (), tensorflow::thread::EigenEnvironment::CreateThread(std::function<void ()>)::{lambda()#1}>::_M_invoke(std::_Any_data const&) () from /home/<username>/envs/python2.7/lib/python2.7/site-packages/tensorflow/python/../libtensorflow_framework.so
#10 0x00007ffff676b8f0 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#11 0x00007ffff79506ba in start_thread (arg=0x7ffe77f97700) at pthread_create.c:333
#12 0x00007ffff768641d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

我确信是段错误的打印内容,因为没有它就可以正常运行。 我不太了解gdb的输出,但是我也对这些答案所暗示的方法感到困惑,因为我无法在文档中找到它们。

如何在c ++中的tensorflow中的自定义OP中方便地打印张量?

0 个答案:

没有答案