是否可以使用没有标记输入(或输出)节点的 Tensorflow C++ API 执行图形?据我所知,在训练我的模型时(在 python 中使用 skflow,后来我将其保存为二进制 protobuf),我没有标记输入/输出节点,但我能够毫无困难地恢复模型并进行预测在 Python 中。当使用 C++ API 执行图形时,输入 vector 是字符串和张量对,我假设字符串指的是输入节点的标签。来自文档:
Session::Run(const std::vector< std::pair< string, Tensor > > &inputs, const std::vector< string > &output_tensor_names, const std::vector< string > &target_node_names, std::vector< Tensor > *outputs)=0
Runs the graph with the provided input tensors and fills outputs for the endpoints specified in output_tensor_names. Runs to but does not return Tensors for the nodes in target_node_names.
有什么方法可以在不知道输入/输出节点标签的情况下执行图形?也许有一种方法可以用 Python 加载图形,给节点标签,然后再次将其保存为 protobuf?理想情况下,我只想传入一个应用于输入节点的 vector ,而不必担心任何标签。
最佳答案
在 skflow 中,所有节点都已经有标签,它只负责为您恢复它们。
X
和 y
的默认名称分别为 input:0
和 output:0
,然后是一些自定义名称预测和损失的名称取决于您使用的模型。
找出预测和概率节点名称的方法是查看保存模型目录中的 endpoints
文件(如果您使用了 estimator.save(path)
用于保存)。
它应该是这样的:
input:0
output:0
logistic_regression/softmax_classifier/Softmax
logistic_regression/softmax_classifier/xent:0
其中前两个是输入/输出节点的名称,后两个是预测和损失节点。
关于python - 使用 Tensorflow C++ API 执行在 skflow 中训练的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35120102/