# tf.keras.layers.InputLayer

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/engine/input_layer.py#L43-L292) |

Layer to be used as an entry point into a Network (a graph of layers).

Inherits From: [`Layer`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/keras/layers/Layer), [`Module`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/Module)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

\`tf.compat.v1.keras.layers.InputLayer\`

<br />

    tf.keras.layers.InputLayer(
        input_shape=None,
        batch_size=None,
        dtype=None,
        input_tensor=None,
        sparse=None,
        name=None,
        ragged=None,
        type_spec=None,
        **kwargs
    )

It can either wrap an existing tensor (pass an `input_tensor` argument)
or create a placeholder tensor (pass arguments `input_shape`, and
optionally, `dtype`).

It is generally recommend to use the Keras Functional model via `Input`,
(which creates an `InputLayer`) without directly using `InputLayer`.

When using `InputLayer` with the Keras Sequential model, it can be skipped
by moving the `input_shape` parameter to the first layer after the
`InputLayer`.

This class can create placeholders for `tf.Tensors`, `tf.SparseTensors`, and
`tf.RaggedTensors` by choosing `sparse=True` or `ragged=True`. Note that
`sparse` and `ragged` can't be configured to `True` at the same time.
Usage:

    # With explicit InputLayer.
    model = tf.keras.Sequential([
      tf.keras.layers.InputLayer(input_shape=(4,)),
      tf.keras.layers.Dense(8)])
    model.compile(tf.keras.optimizers.RMSprop(0.001), loss='mse')
    model.fit(np.zeros((10, 4)),
              np.ones((10, 8)))

    # Without InputLayer and let the first layer to have the input_shape.
    # Keras will add a input for the model behind the scene.
    model = tf.keras.Sequential([
      tf.keras.layers.Dense(8, input_shape=(4,))])
    model.compile(tf.keras.optimizers.RMSprop(0.001), loss='mse')
    model.fit(np.zeros((10, 4)),
              np.ones((10, 8)))

<br />

<br />

<br />

| ## Args ||
|---|---|
| `input_shape` | Shape tuple (not including the batch axis), or `TensorShape` instance (not including the batch axis). |
| `batch_size` | Optional input batch size (integer or `None`). |
| `dtype` | Optional datatype of the input. When not provided, the Keras default `float` type will be used. |
| `input_tensor` | Optional tensor to use as layer input. If set, the layer will use the [`tf.TypeSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/TypeSpec) of this tensor rather than creating a new placeholder tensor. |
| `sparse` | Boolean, whether the placeholder created is meant to be sparse. Defaults to `False`. |
| `ragged` | Boolean, whether the placeholder created is meant to be ragged. In this case, values of `None` in the `shape` argument represent ragged dimensions. For more information about [`tf.RaggedTensor`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/RaggedTensor), see [this guide](https://www.tensorflow.org/guide/ragged_tensor). Defaults to `False`. |
| `type_spec` | A [`tf.TypeSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/TypeSpec) object to create Input from. This [`tf.TypeSpec`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/TypeSpec) represents the entire batch. When provided, all other args except name must be `None`. |
| `name` | Optional name of the layer (string). |

<br />