python - 使用 Tensorflow C++ API 执行在 skflow 中训练的模型

标签 python c++ machine-learning tensorflow skflow

是否可以使用没有标记输入(或输出)节点的 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 中,所有节点都已经有标签,它只负责为您恢复它们。

Xy 的默认名称分别为 input:0output: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/

相关文章:

python - 如何从数据框 Pandas 制作列表列表?

python - 导入错误 : No module named 'wordcloud'

c++ - Borland 字符串::查找错误

c++ - 从内核模式执行用户模式可执行文件

machine-learning - 使用 gensim 构建的 doc2vec 模型的 GridSearch

python - 如何将一条推文输入分类器模型?

r - 在 R 中计算 RMSE 时遇到问题

python - 处理第 6/7 页之后的 Cookie 弹出窗口

python - 有没有一种简单的方法可以判断等待 Python GIL 花费了多少时间?

c++ - 将数组作为参数传递给 printf