Peterson Yuhala
Peterson Yuhala

Reputation: 36

How can I obtain the data from a tensorflow Variable in C++

I will love to know how I could obtain the data from a tensorflow Variabe object using the C++ API. For example, with a pure Tensor object with reference obj for example, doing obj->flat<Type>().data() returns all the tensor data. Is there a similar way to extract data from a Variable object ?

Upvotes: 0

Views: 260

Answers (1)

Peterson Yuhala
Peterson Yuhala

Reputation: 36

Just got a hint on how to do it. I run the variable in a session and send the results to an output Tensor vector. I then extract the values from the corresponding Tensor object as described in the question.

std::vector<Output> outputs;
auto my_var = Variable (...);
TF_CHECK_OK(session.Run({my_var},&outputs));
print(output[0]);

Upvotes: 1

Related Questions