Variables 是否可以为Tensorflow节点提供别名?
我有一个复杂的网络,我为它创建了一个非常简单的类,用于在将模型序列化为冻结的图形文件后推断模型 问题是,在这个文件中,我需要加载带有其名称空间的变量,这可能最终取决于我构建模型的方式。就我而言,结果是这样的:Variables 是否可以为Tensorflow节点提供别名?,variables,namespaces,tensorflow,alias,serving,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_mo
# 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")
在将这两个节点存储到模型中之前,我想给它们一个别名,这样它们最终会有一个公共名称,然后我的推断类可以用作获取模型的通用类。在这种情况下,我会这样做:
# 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”的新passthrough,并从指定的节点获取其值
输入有点棘手,您需要更改构建模型的方式-例如,让它从外部获取输入,然后创建一个具有固定名称的输入占位符,然后将其传递给构建模型的函数。tf.identified
:“返回与输入张量值具有相同形状和内容的张量。“也许我在Tensorflow方面缺乏更深入的知识,但这难道不是因为它根本没有连接到图形吗?”?无论如何,如果它是一个新向量,即使它具有张量的值,它也不会以与原始节点相同的方式交互,因此在调用sess.run并向新输入节点馈电时,它不会工作,对吗?