I have a C++ tensorflow::Tensor
whose contents I am trying to access in Python.
I have looked through the Tensorflow C++ Documentation in search of a function that can convert a tensorflow::Tensor
to any sensible PyObject
(it does not matter for now wether this is a tf.Tensor
or a numpy.nd_array
).
After looking around though the Tensorflow Code, I have found the following clues:
There is a method TF_Tensor_to_PyObject(TF_Tensor* Tensor, PyObject** out_array)
defined in tensorflow/python/client/tf_session_helper.cc
. However, this is defined in a hidden Bazel package, moreover in an anonymous C++ namespace. It seems unintuitive to modify Tensorflow itself (I would have to modify the Bazel BUILD file, the .h and .cc files), and compile my own Tensorflow to use this Approach.
Another issue with this Approach is that TF_Tensor
!= tensorflow::Tensor
. The TF_Tensor
is defined in the C-Api for Tensorflow, and there, the conversion also not intended for public use (as in: outside of this package).
Does anybody know of a better way to do this? Is there an existing implementation for a tensorflow::Tensor
to a PyObject
which I did not find while searching?