假如 predict 是你要获取的tensor的值,其类型为 tensorflow::Tensor
auto features_ptr = predict.tensor<float, 4>();
auto N = (int) predict.dim_size(0);
auto H = (int) predict.dim_size(1);
auto W = (int) predict.dim_size(2);
auto C = (int) predict.dim_size(3);
for (int n = 0; n < N; ++n) {
for (int h = 0; h < H; ++h) {
for (int w = 0; w < W; ++w) {
for (int c = 0; c < C; ++c) {
std::cout << features_ptr(n, h, w, c) << std::endl;
}
}
}
}
以此类推,其他类似。