<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/layers/reshaping/flatten.py#L11-L84) |

Flattens the input. Does not affect the batch size.

Inherits From: [`Layer`](https://www.tensorflow.org/api_docs/python/tf/keras/Layer), [`Operation`](https://www.tensorflow.org/api_docs/python/tf/keras/Operation)

    tf.keras.layers.Flatten(
        data_format=None, **kwargs
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Effective Tensorflow 2](https://www.tensorflow.org/guide/effective_tf2) - [Migrate early stopping](https://www.tensorflow.org/guide/migrate/early_stopping) - [Use TF1.x models in TF2 workflows](https://www.tensorflow.org/guide/migrate/model_mapping) - [tf.data: Build TensorFlow input pipelines](https://www.tensorflow.org/guide/data) - [Migrate checkpoint saving](https://www.tensorflow.org/guide/migrate/checkpoint_saver) | - [Image classification](https://www.tensorflow.org/tutorials/images/classification) - [Scalable model compression](https://www.tensorflow.org/tutorials/optimization/compression) - [Simple audio recognition: Recognizing keywords](https://www.tensorflow.org/tutorials/audio/simple_audio) - [Custom training with tf.distribute.Strategy](https://www.tensorflow.org/tutorials/distribute/custom_training) - [Using DTensors with Keras](https://www.tensorflow.org/tutorials/distribute/dtensor_keras_tutorial) |

> [!NOTE]
> **Note:** If inputs are shaped `(batch,)` without a feature axis, then flattening adds an extra channel dimension and output shape is `(batch, 1)`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `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, ...)`. When unspecified, uses `image_data_format` value found in your Keras config file at `~/.keras/keras.json` (if exists). Defaults to `"channels_last"`. |

<br />

#### Example:

    x = keras.Input(shape=(10, 64))
    y = keras.layers.Flatten()(x)
    y.shape
    (None, 640)

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `input` | Retrieves the input tensor(s) of a symbolic operation. <br /> Only returns the tensor(s) corresponding to the *first time* the operation was called. |
| `output` | Retrieves the output tensor(s) of a layer. <br /> Only returns the tensor(s) corresponding to the *first time* the operation was called. |

<br />

## Methods

### `from_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/operation.py#L322-L362)

    @classmethod
    from_config(
        config
    )

Creates an operation from its config.

This method is the reverse of `get_config`, capable of instantiating the
same operation from the config dictionary.

> [!NOTE]
> **Note:** If you override this method, you might receive a serialized dtype config, which is a `dict`. You can deserialize it as follows:

    if "dtype" in config and isinstance(config["dtype"], dict):
        policy = dtype_policies.deserialize(config["dtype"])

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | A Python dictionary, typically the output of `get_config`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An operation instance. ||

<br />