2017-04-18 22 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();