c++ - 从 Eigen::Tensor 创建 tensorflow::Tensor

标签 c++ tensorflow eigen tensor

我应该如何从 Eigen::Tensor 创建一个 tensorflow::Tensor?我可以一个接一个地复制元素,但我希望有更好的方法。

最佳答案

没有公共(public) api 可以在不复制数据的情况下从 Eigen::Tensor 创建 tensorflow::Tensor。但是,您可以使用以下 API 创建一个 tensorflow::Tensor 并将其解释为 Eigen::TensorMap: tensorflow::Tensor tf_tensor(tensor_constructor_args); // For the general case: Eigen::TensorMap<type_params> eigen_tensor = tf_tensor.tensor<Type, NumDims>(); // shortcuts if you know the tensor is a matrix/vector/scalar Eigen::TensorMap<type_params> eigen_matrix = tf_tensor.matrix<Type>(); Eigen::TensorMap<type_params> eigen_vector = tf_tensor.vector<Type>(); Eigen::TensorMap<type_params> eigen_scalar = tf_tensor.scalar<Type>();

这将避免复制。此外, Eigen 张量和张量图共享相同的 API,因此您可以互换使用它们。

关于c++ - 从 Eigen::Tensor 创建 tensorflow::Tensor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50744193/

相关文章:

python - 为什么我在安装 pip 包时没有删除六个的权限?

c++ - 如何为CSR格式设置SparseMatrix.valuePtr()、SparseMatrix.outerIndexPtr()和SparseMatrix.innerIndexPtr()?

c++ - QtSerialPort 有不可用的数据,仅在 Windows 8 下出现段错误

c++ - 此信封实现是否正确使用 C++11 原子?

c++ - 按时间从视频中获取帧(openCV)

matlab - 为什么稀疏密集乘法比密集稀疏乘法快?

c++ - 如何根据传递给函数的变量定义特征矩阵大小

c++ - 一个数的最大除数与质因数的关系

python - tensorflow from_generator() 给出错误 - 'generator` 产生无法转换为预期类型的​​元素

python - tensorflow 中的参数化混合密度网络协方差