tf.keras.backend.shape

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 'Shape_...' shape=(3,) dtype=int32>