tf.identity

TensorFlow 1 version View source on GitHub

Return a Tensor with the same shape and contents as input.

The return value is not the same Tensor as the original, but contains the same values. This operation is fast when used on the same device.

For example:

a = tf.constant([0.78])
a_identity = tf.identity(a)
a.numpy()
array([0.78], dtype=float32)
a_identity.numpy()
array([0.78], dtype=float32)

Calling tf.identity on a variable will make a Tensor that represents the value of that variable at the time it is called. This is equivalent to calling <variable>.read_value().

a = tf.Variable(5)
a_identity = tf.identity(a)
a.assign_add(1)
<tf.Variable ... shape=() dtype=int32, numpy=6>
a.numpy()
6
a_identity.numpy()
5

input A Tensor.
name A name for the operation (optional).

A Tensor. Has the same type as input.