【问题标题】:Is it possible to have an alias for a Tensorflow node?是否可以为 Tensorflow 节点设置别名?
【发布时间】:2017-03-15 10:13:16
【问题描述】:

我有一个复杂的网络,我为此创建了一个非常简单的类,用于在模型序列化为冻结图形文件后推断模型。

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

# 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")

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

非常感谢!

【问题讨论】:

    标签: variables namespaces tensorflow alias serving


    【解决方案1】:

    您可以使用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”的新直通操作,并将从您指定的节点获取其值。

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

    【讨论】:

    • tf.identify: "返回一个与输入张量或值具有相同形状和内容的张量。"也许我对Tensorflow缺乏更深入的了解,但它不是根本没有连接到图表吗?无论如何,如果它是一个新向量,即使它具有张量的值,它也不会以与原始节点相同的方式交互,因此在调用 sess.run 并提供新的输入节点时它不会工作,对吧?
    猜你喜欢
    • 2014-02-01
    • 2010-09-16
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多