Kevin Kevin - 1 year ago 123
C++ Question

How to print or cout a tensor?

I have a tensor that I would like to print for debugging

tensorflow::Tensor image_tensor;

I tried

std::cout << &image_tensor;

But I get something like this:


Answer Source

you have to use the .vec or .flat methods. let’s say the tensor is a int8

// for i in image_tensor.size …
cout << i << “ “ << image_tensor.vec<int8>()(i)

see also this answer How to fill a tensor in C++

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download