在 Tensorflow 中,如何重命名某个操作名称? [英] In Tensorflow, how can I rename a certain operation name?

查看:31
本文介绍了在 Tensorflow 中,如何重命名某个操作名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这个问题可能听起来很奇怪.假设有一个张量 a.

I think this question may sound weird. Let's say, there is a tensor a.

x = tf.placeholder(tf.float32, [None, 2400], name="x")
y = tf.placeholder(tf.float32, [None, 2400], name="y")
a = tf.add(x, y, name="a")

是否有一种有效的方法来引用具有不同名称的 a,例如 out?我在想像

Is there an efficient way to refer a with a different name, like out? I am thinking a dummy operation like

b = tf.add(a, 0, name="out")

我问这个是因为我正在尝试不同的网络架构,无论架构如何,我都想访问具有一致名称的输出张量,例如

I am asking this because I am trying different network architectures, and regardless of architectures, I would like to access the output tensor with a consistent name like

tf.get_default_graph().get_tensor_by_name("out:0")`

目前,输出张量取决于 fc1/fc1wb:0fc2/fc2wb:0 等架构.如何用特定名称包装最终操作?

For now, output tensors are depending on architectures like fc1/fc1wb:0 or fc2/fc2wb:0. How can I wrap the final op with a certain name?

推荐答案

这个 答案表明 tf.Graph 只能追加,不能修改.

This answer suggests that tf.Graph is append only, you cannot modify it.

话虽如此,重命名张量的更好方法是使用 tf.identity 像这样:

That being said, a slightly better way to rename a tensor is to use tf.identity like this:

tf.identity(a, name="out")

在找出我自己的一个问题的答案后,我可以看到一种更好的方法:

After figuring out answer to one of my own questions, I can see a slightly better way to do this:

graph_def.node[<index of the op you want to change>].name = "out"

index 通常是 -1 因为最终输出张量在 graph_def

the index is usually -1 because final output tensors are in the end of the graph_def

这篇关于在 Tensorflow 中,如何重命名某个操作名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆