serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel

Home Page:https://serizba.github.io/cppflow/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

To print all the entries of output tensor using cppflow::print()

srilekha1993 opened this issue · comments

I have cppflow output tensor looking like this [[0.000991769251 0.00138346222 0.00149751361 ... 1.76803405e-05 -7.28769791e-08 -8.21208062e-07]]) of shape (1,16000).
I want to print all the entries of this tensor using cppflow. I have tried with cppflow::print() but it is defined similarly to the TensorFlow 1.x format where it takes the input graph and the data input, but in my case only one output tensor no graph is there. I wanted to use similar to the tf. print() in tensorflw2.x. So can someone help me out in this regard?

If you have a flat tensor one easy way to go is to call tensor::get_data<T>() to get a vector and then iterate over it and print the values.

Hi serizba,
As my tensor name is output
so for(auto i:output::get_data())
cout<<i;
I did like this. but got error like below

In function ‘int main()’:
first_exp.cpp:155:16: error: ‘output’ is not a class, namespace, or enumeration
155 | for(auto i:output::get_data())
| ^~~~~~
first_exp.cpp:155:33: error: expected primary-expression before ‘float’
155 | for(auto i:output::get_data())
| ^~~~~
first_exp.cpp:155:33: error: expected ‘)’ before ‘float’
155 | for(auto i:output::get_data())
| ~ ^~~~~
| )
first_exp.cpp:155:38: error: expected unqualified-id before ‘>’ token
155 | for(auto i:output::get_data())

You should try output.get_data<float>()

Thanks @serizba it worked now