How to print tensor in c++ custom OP?












0














I am trying to follow this answer or this one. But I can't find both these methods 1. t.DebugString() or t.vec() in the docs. Both for the version I'm using 1.8 and the newest one 1.12. I just tried the first answer using debug string like this:



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;


but I get a segfault running this. GDB first line looks like this:



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*) ()


and the whole stacktrace is:



(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


I am sure it is the print that segfaults, since it runs normally without it.
I don't really understand the output of gdb, but I'm also confused to what methods these answers are alluding to, since I can't find them in the docs.



How can I conveniently print tensors in a custom OP in tensorflow in c++?










share|improve this question





























    0














    I am trying to follow this answer or this one. But I can't find both these methods 1. t.DebugString() or t.vec() in the docs. Both for the version I'm using 1.8 and the newest one 1.12. I just tried the first answer using debug string like this:



    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;


    but I get a segfault running this. GDB first line looks like this:



    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*) ()


    and the whole stacktrace is:



    (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


    I am sure it is the print that segfaults, since it runs normally without it.
    I don't really understand the output of gdb, but I'm also confused to what methods these answers are alluding to, since I can't find them in the docs.



    How can I conveniently print tensors in a custom OP in tensorflow in c++?










    share|improve this question



























      0












      0








      0







      I am trying to follow this answer or this one. But I can't find both these methods 1. t.DebugString() or t.vec() in the docs. Both for the version I'm using 1.8 and the newest one 1.12. I just tried the first answer using debug string like this:



      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;


      but I get a segfault running this. GDB first line looks like this:



      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*) ()


      and the whole stacktrace is:



      (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


      I am sure it is the print that segfaults, since it runs normally without it.
      I don't really understand the output of gdb, but I'm also confused to what methods these answers are alluding to, since I can't find them in the docs.



      How can I conveniently print tensors in a custom OP in tensorflow in c++?










      share|improve this question















      I am trying to follow this answer or this one. But I can't find both these methods 1. t.DebugString() or t.vec() in the docs. Both for the version I'm using 1.8 and the newest one 1.12. I just tried the first answer using debug string like this:



      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;


      but I get a segfault running this. GDB first line looks like this:



      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*) ()


      and the whole stacktrace is:



      (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


      I am sure it is the print that segfaults, since it runs normally without it.
      I don't really understand the output of gdb, but I'm also confused to what methods these answers are alluding to, since I can't find them in the docs.



      How can I conveniently print tensors in a custom OP in tensorflow in c++?







      python c++ tensorflow






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 27 '18 at 16:16

























      asked Dec 20 '18 at 17:28









      Hakaishin

      4831520




      4831520





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53873465%2fhow-to-print-tensor-in-c-custom-op%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53873465%2fhow-to-print-tensor-in-c-custom-op%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas

          Can't read property showImagePicker of undefined in react native iOS