Skip to main content
Follow me for more posts @modeless

Tensorflow tidbit: What's up with :0 in the names of my variables?

tl;dr replace with to get rid of the :0

When getting the names of things in Tensorflow I've sometimes been confused by the difference between x and x:0. It turns out that x:0 is the name of a Tensor object, while x is the name of the op that generates it (such as Add or MatMul).

If you have a Tensor object t and you say, you will get a name with :0 at the end. If you want the name without :0, don't just try to use string processing to remove the :0! Instead, you can access the op related to the Tensor with the op member variable, so you can get the name you want with

If instead you have an operation my_op and you want the name of its output tensor, you can say my_op.outputs[0].name.

Follow me for more posts @modeless
Share this post: