MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / batch_flatten

Function batch_flatten

tensorflow/python/keras/backend.py:2929–2952  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2927
2928@keras_export('keras.backend.batch_flatten')
2929def 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')

Callers

nothing calls this directly

Calls 4

reshapeMethod · 0.80
prodFunction · 0.70
shapeFunction · 0.70
stackMethod · 0.45

Tested by

no test coverage detected