Turn a nD tensor into a 2D tensor with same 0th dimension. In other words, it flattens each data samples of a batch. Arguments: x: A tensor or variable. Returns: A tensor. Examples: Flattening a 3D tensor to 2D by collapsing the last dimension. ```python >>> from ten
(x)
| 2927 | |
| 2928 | @keras_export('keras.backend.batch_flatten') |
| 2929 | def batch_flatten(x): |
| 2930 | """Turn a nD tensor into a 2D tensor with same 0th dimension. |
| 2931 | |
| 2932 | In other words, it flattens each data samples of a batch. |
| 2933 | |
| 2934 | Arguments: |
| 2935 | x: A tensor or variable. |
| 2936 | |
| 2937 | Returns: |
| 2938 | A tensor. |
| 2939 | |
| 2940 | Examples: |
| 2941 | Flattening a 3D tensor to 2D by collapsing the last dimension. |
| 2942 | |
| 2943 | ```python |
| 2944 | >>> from tensorflow.keras import backend as K |
| 2945 | >>> x_batch = K.ones(shape=(2, 3, 4, 5)) |
| 2946 | >>> x_batch_flatten = K.batch_flatten(x_batch) |
| 2947 | >>> K.int_shape(x_batch_flatten) |
| 2948 | (2, 60) |
| 2949 | ``` |
| 2950 | """ |
| 2951 | x = array_ops.reshape(x, array_ops.stack([-1, prod(shape(x)[1:])])) |
| 2952 | return x |
| 2953 | |
| 2954 | |
| 2955 | @keras_export('keras.backend.expand_dims') |