Kevin Kevin - 8 months ago 61
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:



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++