In the Tensorflow C ++ API, how to use Eigen Tensor to set the tensor tensor?

So let's say I have 4D Eigen :: Tensor T.

Similarly, I also have 4D Tensorflow :: Tensor X with the same shape as T

  int size = T.dimension(0);
  int rows = T.dimension(1);
  int cols = T.dimension(2);
  int channels = T.dimension(3);

  TensorShape TS;
  TS.AddDim(size);
  TS.AddDim(rows);
  TS.AddDim(cols);
  TS.AddDim(size);

  Tensor x( DT_FLOAT, TS);

Now I want to put the data in T at x.

So I try:

  x.matrix<float>()() = T;

But the compiler yells at me when I do thqt:

cannot convert 'Eigen :: Tensor' to 'Eigen :: TensorMap, 16> :: Scalar {aka float}' in assignment

When I try to convert T to TensorMap, I get even more errors.

What am I missing here?

+4
source share
1 answer

I think the problem is that you are using ".matrix", which only returns a 2d matrix.

template <typename T>
  typename TTypes<T>::Matrix matrix() {
    return tensor<T, 2>();
  }

".tensor", Nd-.

template <typename T, size_t NDIMS>
typename TTypes<T, NDIMS>::Tensor Tensor::tensor() {
  CheckTypeAndIsAligned(DataTypeToEnum<T>::v());
  return typename TTypes<T, NDIMS>::Tensor(base<T>(),
                                           shape().AsEigenDSizes<NDIMS>());
}
0

Source: https://habr.com/ru/post/1651592/


All Articles