如何访问张量流::张量C++
How to access tensorflow::Tensor C++
我正在使用其C++ API运行Tensorflow。
我有以下调用,它在 finalOutput 中返回四个张量:
std::string str1 = "detection_boxes";
std::string str2 = "detection_scores";
std::string str3 = "detection_classes";
std::string str4 = "num_detections";
std::vector<Tensor> finalOutput;
status = session->Run({ {InputName, inputTensor} }, { str1, str2, str3, str4 }, {}, &finalOutput);
std::cout << finalOutput[0].DebugString() << std::endl;
print 语句输出以下内容:
"张量<类型:浮点形状:[1,100,4]>">
现在我有一个包含 100 个元素的张量,每个元素有 4 个值,我该如何遍历元素和值?
似乎我必须调用一个函数来返回 Eigen::TensorMap,然后以某种方式访问元素。 我只是不确定该怎么做。
非常感谢您的帮助!
我可以这样做
// tensor<float, 3>: 3 here because it's a 3-dimension tensor
auto output_detection_boxes = outputs[0].tensor<float, 3>();
std::cout << "detection boxes" << std::endl;
for (int i = 0; i < 100; ++i) {
for (int j = 0; j < 4; ++j)
// using (index_1, index_2, index_3) to access the element in a tensor
std::cout << output_detection_boxes(0, i, j)
<< "t";
std::cout << std::endl;
}
这是输出
detection boxes
0.0370 0.0465 0.8914 0.3171
0.0924 0.3944 0.9344 0.9769
0.0155 0.2988 0.8812 0.5263
0.1518 0.3817 0.9316 1.0000
0.0000 0.3285 0.8447 0.6669
0.0389 0.2030 0.8504 0.4749
...
(100 in total)
相关文章:
- C++中的张量流对象检测
- 在官方张量流 resnet50 模型上运行 tflite 精度工具
- 如何使用 c++ 更改张量流中的per_process_gpu_memory_fraction?
- 编译 GPU 的张量流示例自定义操作
- C++ ABI 兼容性问题/张量流
- 如何从内存缓冲区加载张量流图
- 张量流错误 此文件需要编译器和库支持 ISO C++ 2011 标准
- 部署在张量流中训练的神经网络来火炬C++的最佳方法是什么?
- 微调张量流对象检测预训练模型
- 添加 OP 张量流调试
- 如何通过一次运行将多个输入样本馈送到C++张量流模型
- 未定义的符号'fixed_address_empty_string':带有protobuf的新张量流运算
- F 张量流/核心/common_runtime/device_factory.cc:77]具有相同优先级 210 的 G
- 张量流 c++ API 是否支持反向传播的自动微分?
- 最小工作示例张量流服务客户端
- 从 Eigen::Tensor 创建张量流::张量
- 如何访问张量流::张量C++
- 如何使用 c++ API 获取秩 3 张量流::张量的最大值的索引
- 如何从C++中的原始指针数据构造张量流::张量
- C++从张量流::张量对象访问Eigen::张量类函数