TensorFlow的C ++接口似乎没有重塑方法。有没有人知道如何转换,例如[A,B,C,D]
进入[A*B,C,D]
?看起来这样做的唯一方法就是使用Eigen?但是,那里的文档非常简洁,代码是模板地狱,不容易解析。
答案 0 :(得分:1)
检查重构张量是否具有相同数量的源张量元素的解决方案:
// 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();
答案 1 :(得分:0)
这应该有效:
Tensor my_tensor; // [A, B, C, D]
Tensor reshaped_tensor = my_tensor.shaped<float, 3>({A*B, C, D}); //[A*B, C, D]