簡體   English   中英

從Eigen :: Tensor創建tensorflow :: Tensor

[英]Creating tensorflow::Tensor from Eigen::Tensor

我應該如何從Eigen :: Tensor創建一個tensorflow :: Tensor? 我可以一一復制這些元素,但我希望有更好的方法。

沒有公共api從Eigen :: Tensor創建tensorflow :: Tensor,而不復制數據。 但是,您可以創建tensorflow :: Tensor並使用以下API將其解釋為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>(); 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>();

這樣可以避免復制。 此外,本征張量和張量圖共享相同的api,因此您可以互換使用它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM