2017-04-18 23 views
2

TensorFlow的C++接口似乎没有重构方法。有没有人有一个想法如何转换[A,B,C,D]分成[A*B,C,D]?它看起来像这样做的唯一方法是使用Eigen?然而,那里的文档非常渺茫,代码是模板地狱,不容易解析。在C++中重构张量

回答

0

这应该工作:

Tensor my_tensor; // [A, B, C, D] 
Tensor reshaped_tensor = my_tensor.shaped<float, 3>({A*B, C, D}); //[A*B, C, D] 
0

解检查重塑张量是否具有相同数量的源极张量的元素:

// 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();