tf.keras.layers.InputLayer
Stay organized with collections
Save and categorize content based on your preferences.
Layer to be used as an entry point into a Network (a graph of layers).
Inherits From: Layer
, Module
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)))
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 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 , see
this guide.
Defaults to False .
|
type_spec
|
A tf.TypeSpec object to create Input from. This
tf.TypeSpec represents the entire batch. When provided, all other
args except name must be None .
|
name
|
Optional name of the layer (string).
|
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. Some content is licensed under the numpy license.
Last updated 2024-01-23 UTC.
[null,null,["Last updated 2024-01-23 UTC."],[],[],null,["# tf.keras.layers.InputLayer\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.15.0/keras/engine/input_layer.py#L43-L292) |\n\nLayer to be used as an entry point into a Network (a graph of layers).\n\nInherits From: [`Layer`](../../../tf/keras/layers/Layer), [`Module`](../../../tf/Module) \n\n tf.keras.layers.InputLayer(\n input_shape=None,\n batch_size=None,\n dtype=None,\n input_tensor=None,\n sparse=None,\n name=None,\n ragged=None,\n type_spec=None,\n **kwargs\n )\n\nIt can either wrap an existing tensor (pass an `input_tensor` argument)\nor create a placeholder tensor (pass arguments `input_shape`, and\noptionally, `dtype`).\n\nIt is generally recommend to use the Keras Functional model via `Input`,\n(which creates an `InputLayer`) without directly using `InputLayer`.\n\nWhen using `InputLayer` with the Keras Sequential model, it can be skipped\nby moving the `input_shape` parameter to the first layer after the\n`InputLayer`.\n\nThis class can create placeholders for `tf.Tensors`, `tf.SparseTensors`, and\n`tf.RaggedTensors` by choosing `sparse=True` or `ragged=True`. Note that\n`sparse` and `ragged` can't be configured to `True` at the same time.\nUsage: \n\n # With explicit InputLayer.\n model = tf.keras.Sequential([\n tf.keras.layers.InputLayer(input_shape=(4,)),\n tf.keras.layers.Dense(8)])\n model.compile(tf.keras.optimizers.RMSprop(0.001), loss='mse')\n model.fit(np.zeros((10, 4)),\n np.ones((10, 8)))\n\n # Without InputLayer and let the first layer to have the input_shape.\n # Keras will add a input for the model behind the scene.\n model = tf.keras.Sequential([\n tf.keras.layers.Dense(8, input_shape=(4,))])\n model.compile(tf.keras.optimizers.RMSprop(0.001), loss='mse')\n model.fit(np.zeros((10, 4)),\n np.ones((10, 8)))\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_shape` | Shape tuple (not including the batch axis), or `TensorShape` instance (not including the batch axis). |\n| `batch_size` | Optional input batch size (integer or `None`). |\n| `dtype` | Optional datatype of the input. When not provided, the Keras default `float` type will be used. |\n| `input_tensor` | Optional tensor to use as layer input. If set, the layer will use the [`tf.TypeSpec`](../../../tf/TypeSpec) of this tensor rather than creating a new placeholder tensor. |\n| `sparse` | Boolean, whether the placeholder created is meant to be sparse. Defaults to `False`. |\n| `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`](../../../tf/RaggedTensor), see [this guide](https://www.tensorflow.org/guide/ragged_tensor). Defaults to `False`. |\n| `type_spec` | A [`tf.TypeSpec`](../../../tf/TypeSpec) object to create Input from. This [`tf.TypeSpec`](../../../tf/TypeSpec) represents the entire batch. When provided, all other args except name must be `None`. |\n| `name` | Optional name of the layer (string). |\n\n\u003cbr /\u003e"]]