tf.keras.backend.shape

TensorFlow 1 version View source on GitHub

Returns the symbolic shape of a tensor or variable.

x A tensor or variable.

A symbolic shape (which is itself a tensor).

Examples:

val = np.array([[1, 2], [3, 4]])
kvar = tf.keras.backend.variable(value=val)
tf.keras.backend.shape(kvar)
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([2, 2], dtype=int32)>
input = tf.keras.backend.placeholder(shape=(2, 4, 5))
tf.keras.backend.shape(input)
<tf.Tensor &#x27;Shape_...' shape=(3,) dtype=int32>