variables - Tensorflow 节点可以有别名吗?

标签 variables namespaces tensorflow alias serving

我有一个复杂的网络,我为它创建了一个非常简单的类,用于在模型序列化为卡住图形文件后对其进行推理。

问题是在这个文件中,我需要使用他的命名空间加载变量,这可能最终取决于我如何构建模型。就我而言,结果是这样的:

# Load the input and output node with a singular namespace depending on the model
self.input_node = self.sess.graph.get_tensor_by_name("create_model/mymodelname/input_node:0")
self.output_node = self.sess.graph.get_tensor_by_name("create_model/mymodelname/out/output_node:0")

我想在将这两个节点存储到模型之前给它一个别名,例如它们最终会有一个通用名称,然后我的推理类可以用作获取模型的通用类。在这种情况下,我最终会做这样的事情:
# Load the input and output node with a general node namespace
self.input_node = self.sess.graph.get_tensor_by_name("input_node:0")
self.output_node = self.sess.graph.get_tensor_by_name("output_node:0")

那么有没有办法给他们一个别名?我真的什么也没找到。

非常感谢你!

最佳答案

您可以使用 tf.identity为输出。

output_node = sess.graph.get_tensor_by_name("create_model/mymodelname/output_node:0")
tf.identity(output_node, name="output_node")

将创建一个名为“output_node”的新直通操作,并将从您指定的节点获取其值。

输入有点棘手,您需要更改构建模型的方式 - 例如让它从外部获取输入,然后创建一个具有固定名称的输入占位符,然后将其传递给构建模型的函数模型。

关于variables - Tensorflow 节点可以有别名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42806690/

相关文章:

web-services - BizTalk 与 WCF 服务 - 服务中的空对象

r - 同一 R 包中非导出函数的显式命名空间 - 最佳实践

php - 向自身添加数字的更好方法?

python - 在 Python 中设置多个相似的变量

c# - 检查对象的类型是否来自特定的命名空间

python - Tensorflow 1.11 支持 python 3.7 吗?

machine-learning - 如何使用Tensorflow训练简单模型

python - 使用 Tensorflow 进行 future 预测

javascript - 使用 jQuery 编写应用程序 - 如何存储变量?

java - 如何在 Dialog 和 Activity 之间传递值?