【发布时间】:2017-09-14 13:47:02
【问题描述】:
TensorFlow 的 C++ 接口似乎没有 reshape 方法。有谁知道如何转换例如[A,B,C,D] 变成 [A*B,C,D]?看起来这样做的唯一方法是使用 Eigen?但是,那里的文档很薄,代码是模板地狱,不容易解析。
【问题讨论】:
标签: tensorflow eigen
TensorFlow 的 C++ 接口似乎没有 reshape 方法。有谁知道如何转换例如[A,B,C,D] 变成 [A*B,C,D]?看起来这样做的唯一方法是使用 Eigen?但是,那里的文档很薄,代码是模板地狱,不容易解析。
【问题讨论】:
标签: tensorflow eigen
检查重构张量是否与源张量具有相同数量的元素的解决方案:
// Extracted image features from MobileNet_224
tensorflow::Tensor image_features(tensorflow::DT_FLOAT,
tensorflow::TensorShape({1, 14, 14, 512}));
tensorflow::Tensor image_features_reshaped(tensorflow::DT_FLOAT,
tensorflow::TensorShape({1, 196, 512}));
// Reshape tensor from [1, 14, 14, 512] to [1, 196, 512]
if(!image_features_reshaped.CopyFrom(image_features, tensorflow::TensorShape({1, 196, 512})))
{
LOG(ERROR) << "Unsuccessfully reshaped image features tensor [" << image_features.DebugString() << "] to [1, 196, 512]";
return false;
}
LOG(INFO) << "Reshaped features tensor: " << image_features_reshaped.DebugString();
【讨论】:
这应该可行:
Tensor my_tensor; // [A, B, C, D]
Tensor reshaped_tensor = my_tensor.shaped<float, 3>({A*B, C, D}); //[A*B, C, D]
【讨论】: