Returns the symbolic shape of a tensor or variable. Arguments: x: A tensor or variable. Returns: A symbolic shape (which is itself a tensor). Examples: ```python # TensorFlow example >>> from keras import backend as K >>> tf_session = K.get_session() >>> val = np.arra
(x)
| 1122 | |
| 1123 | @keras_export('keras.backend.shape') |
| 1124 | def shape(x): |
| 1125 | """Returns the symbolic shape of a tensor or variable. |
| 1126 | |
| 1127 | Arguments: |
| 1128 | x: A tensor or variable. |
| 1129 | |
| 1130 | Returns: |
| 1131 | A symbolic shape (which is itself a tensor). |
| 1132 | |
| 1133 | Examples: |
| 1134 | |
| 1135 | ```python |
| 1136 | # TensorFlow example |
| 1137 | >>> from keras import backend as K |
| 1138 | >>> tf_session = K.get_session() |
| 1139 | >>> val = np.array([[1, 2], [3, 4]]) |
| 1140 | >>> kvar = K.variable(value=val) |
| 1141 | >>> input = keras.backend.placeholder(shape=(2, 4, 5)) |
| 1142 | >>> K.shape(kvar) |
| 1143 | <tf.Tensor 'Shape_8:0' shape=(2,) dtype=int32> |
| 1144 | >>> K.shape(input) |
| 1145 | <tf.Tensor 'Shape_9:0' shape=(3,) dtype=int32> |
| 1146 | # To get integer shape (Instead, you can use K.int_shape(x)) |
| 1147 | >>> K.shape(kvar).eval(session=tf_session) |
| 1148 | array([2, 2], dtype=int32) |
| 1149 | >>> K.shape(input).eval(session=tf_session) |
| 1150 | array([2, 4, 5], dtype=int32) |
| 1151 | ``` |
| 1152 | """ |
| 1153 | return array_ops.shape(x) |
| 1154 | |
| 1155 | |
| 1156 | @keras_export('keras.backend.int_shape') |
no test coverage detected