serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
774 stars 177 forks source link

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

Closed srilekha1993 closed 1 year ago

srilekha1993 commented 1 year ago

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?

serizba commented 1 year ago

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.

srilekha1993 commented 1 year ago

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

serizba commented 1 year ago

You should try output.get_data<float>()

srilekha1993 commented 1 year ago

Thanks @serizba it worked now