serizba / cppflow

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

How to iterate through a tensor? #148

Closed B-Meg closed 1 year ago

B-Meg commented 3 years ago

Hey follwing example:

I have a tensor that looks like this: (tensor: shape=[1 200 304], dtype=TF_FLOAT, data=... Now how can iterate through the tensor? With.get_data() I only get the data without the indices. But I want to do something like this: for (int row=0; row<maxRows; row++){ for (int col=0; col<macCol; col++){ Foo.Bar(my_cpp_tensor[row,col], row, col);}} How would I do that?

dskkato commented 3 years ago

The following example will give you a good idea of how to use a tensor.

https://github.com/serizba/cppflow/blob/883eb4c526979dae56f921571b1ab93df85a0a0d/examples/tensor/main.cpp#L28-L36

serizba commented 2 years ago

It is not possible to use [row, col]. So you have to get the data from the tensor to a vector and index it flatten.

serizba commented 1 year ago

Closing due to inactivity.