tf.keras.layers.Flatten
Stay organized with collections
Save and categorize content based on your preferences.
Flattens the input. Does not affect the batch size.
Inherits From: Layer
tf.keras.layers.Flatten(
data_format=None, **kwargs
)
If inputs are shaped (batch,)
without a channel dimension, then flattening
adds an extra channel dimension and output shapes are (batch, 1)
.
Arguments |
data_format
|
A string,
one of channels_last (default) or channels_first .
The ordering of the dimensions in the inputs.
channels_last corresponds to inputs with shape
(batch, ..., channels) while channels_first corresponds to
inputs with shape (batch, channels, ...) .
It defaults to the image_data_format value found in your
Keras config file at ~/.keras/keras.json .
If you never set it, then it will be "channels_last".
|
Example:
model = Sequential()
model.add(Convolution2D(64, 3, 3,
border_mode='same',
input_shape=(3, 32, 32)))
# now: model.output_shape == (None, 64, 32, 32)
model.add(Flatten())
# now: model.output_shape == (None, 65536)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.layers.Flatten\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/keras/layers/Flatten) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/layers/core.py#L538-L604) |\n\nFlattens the input. Does not affect the batch size.\n\nInherits From: [`Layer`](../../../tf/keras/layers/Layer)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.layers.Flatten`](/api_docs/python/tf/keras/layers/Flatten), \\`tf.compat.v2.keras.layers.Flatten\\`\n\n\u003cbr /\u003e\n\n tf.keras.layers.Flatten(\n data_format=None, **kwargs\n )\n\nIf inputs are shaped `(batch,)` without a channel dimension, then flattening\nadds an extra channel dimension and output shapes are `(batch, 1)`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data_format` | A string, one of `channels_last` (default) or `channels_first`. The ordering of the dimensions in the inputs. `channels_last` corresponds to inputs with shape `(batch, ..., channels)` while `channels_first` corresponds to inputs with shape `(batch, channels, ...)`. It defaults to the `image_data_format` value found in your Keras config file at `~/.keras/keras.json`. If you never set it, then it will be \"channels_last\". |\n\n\u003cbr /\u003e\n\n#### Example:\n\n model = Sequential()\n model.add(Convolution2D(64, 3, 3,\n border_mode='same',\n input_shape=(3, 32, 32)))\n # now: model.output_shape == (None, 64, 32, 32)\n\n model.add(Flatten())\n # now: model.output_shape == (None, 65536)"]]