Given x, y
are tensors, I know I can do
with tf.name_scope("abc"):
z = tf.add(x, y, name="z")
So that z
is named "abc/z"
.
I am wondering if there exists a function f
which assign the name directly in the following case:
with tf.name_scope("abc"):
z = x + y
f(z, name="z")
The stupid f
I am using now is z = tf.add(0, z, name="z")
To rename a variable:Right-click the variable and select Rename.
Place the cursor inside a variable you want to rename and press Ctrl + R . Then type other name and editor will change all occurrences of that variable. Save this answer.
Drag a 'Create variable' block into the block editor. Click the name (item) and select 'Rename variable...' Type in the new name and click enter and now the variable has a new name.
If you want to "rename" an op, there is no way to do that directly, because a tf.Operation
(or tf.Tensor
) is immutable once it has been created. The typical way to rename an op is therefore to use tf.identity()
, which has almost no runtime cost:
with tf.name_scope("abc"):
z = x + y
z = tf.identity(z, name="z")
Note however that the recommended way to structure your name scope is to assign the name of the scope itself to the "output" from the scope (if there is a single output op):
with tf.name_scope("abc") as scope:
# z will get the name "abc". x and y will have names in "abc/..." if they
# are converted to tensors.
z = tf.add(x, y, name=scope)
This is how the TensorFlow libraries are structured, and it tends to give the best visualization in TensorBoard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With