python - 如何将 Python Tensorflow Session Run Call 转换为 Tensorflow 的 C++ API
问题描述
我想弄清楚如何调用 Tensorflow 的 C++ API。
我有以下 Python 代码:
with open("logfile.txt", "w") as logFile:
logFile.write("detection_boxes=" + str(detection_boxes))
logFile.write("detection_scores=" + str(detection_scores))
logFile.write("detection_classes=" + str(detection_classes))
logFile.write("num_detections=" + str(num_detections))
logFile.write("image_tensor=" + str(image_tensor))
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
其中 detection_boxes、detection_scores、detection_classes、num_detections 和 image_tensor 是张量。当 str() 应用于 print 语句时,它们如下所示:
detection_boxes=Tensor("detection_boxes:0", dtype=float32)
detection_scores=Tensor("detection_scores:0", dtype=float32)
detection_classes=Tensor("detection_classes:0", dtype=float32)
num_detections=Tensor("num_detections:0", dtype=float32)
image_tensor=Tensor("image_tensor:0", shape=(?, ?, ?, 3), dtype=uint8)
但是,似乎 Tensorflow 的 C++ API 的 Session Run() 调用具有不同的签名。在 session.h 中,
虚拟状态运行(const std::vector >& 输入,const std::vector& output_tensor_names,const std::vector& target_node_names,std::vector* 输出)= 0;
似乎 C++ API 需要向量而不是张量的列表/集合。
如何调用具有与 Python 代码等效参数的 C++ API?
非常感谢您提前提供的帮助!
解决方案
推荐阅读
- r - 计算R中两列中每个元素的总数
- javascript - 为什么在javascript中的reduce函数上添加了Infinitity?
- javascript - 优化和重构在连接字符串(Javascript)中交换值的不同样式的按钮组?
- google-cloud-platform - 如何自动启动 AI 平台作业?
- azure-databricks - Databricks Kusto 连接器:ModuleNotFoundError:没有名为“azure”的模块
- amazon-web-services - 使用 AWS-SDK JS V3 实例化 S3 类时出现“缺少凭据”错误
- php - 运行时事通讯 cron.php 时未定义的索引远程地址
- php - curl 请求在 localhost 上没有返回任何数据,但没有 curl_errno。在网络服务器上工作正常
- c - 哈希函数精度问题
- php - 使用键重新排列多维数组值