tf.keras.Input
Stay organized with collections
Save and categorize content based on your preferences.
Used to instantiate a Keras tensor.
tf.keras.Input(
shape=None,
batch_size=None,
dtype=None,
sparse=None,
batch_shape=None,
name=None,
tensor=None
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
A Keras tensor is a symbolic tensor-like object, which we augment with
certain attributes that allow us to build a Keras model just by knowing the
inputs and outputs of the model.
For instance, if a
, b
and c
are Keras tensors,
it becomes possible to do:
model = Model(input=[a, b], output=c)
Args |
shape
|
A shape tuple (tuple of integers or None objects),
not including the batch size.
For instance, shape=(32,) indicates that the expected input
will be batches of 32-dimensional vectors. Elements of this tuple
can be None ; None elements represent dimensions where the shape
is not known and may vary (e.g. sequence length).
|
batch_size
|
Optional static batch size (integer).
|
dtype
|
The data type expected by the input, as a string
(e.g. "float32" , "int32" ...)
|
sparse
|
A boolean specifying whether the expected input will be sparse
tensors. Note that, if sparse is False , sparse tensors can still
be passed into the input - they will be densified with a default
value of 0. This feature is only supported with the TensorFlow
backend. Defaults to False .
|
name
|
Optional name string for the layer.
Should be unique in a model (do not reuse the same name twice).
It will be autogenerated if it isn't provided.
|
tensor
|
Optional existing tensor to wrap into the Input layer.
If set, the layer will use this tensor rather
than creating a new placeholder tensor.
|
Example:
# This is a logistic regression in Keras
x = Input(shape=(32,))
y = Dense(16, activation='softmax')(x)
model = Model(x, y)
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-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.Input\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/layers/core/input_layer.py#L89-L152) |\n\nUsed to instantiate a Keras tensor.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.keras.layers.Input`](https://www.tensorflow.org/api_docs/python/tf/keras/Input)\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.Input`](https://www.tensorflow.org/api_docs/python/tf/keras/Input)\n\n\u003cbr /\u003e\n\n tf.keras.Input(\n shape=None,\n batch_size=None,\n dtype=None,\n sparse=None,\n batch_shape=None,\n name=None,\n tensor=None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Migrate \\`tf.feature_column\\`s to Keras preprocessing layers](https://www.tensorflow.org/guide/migrate/migrating_feature_columns) - [Use TF1.x models in TF2 workflows](https://www.tensorflow.org/guide/migrate/model_mapping) - [Extension types](https://www.tensorflow.org/guide/extension_type) - [Debug a TensorFlow 2 migrated training pipeline](https://www.tensorflow.org/guide/migrate/migration_debugging) - [Migrate from TPU embedding_columns to TPUEmbedding layer](https://www.tensorflow.org/guide/migrate/tpu_embedding) | - [Parameter server training with ParameterServerStrategy](https://www.tensorflow.org/tutorials/distribute/parameter_server_training) - [pix2pix: Image-to-image translation with a conditional GAN](https://www.tensorflow.org/tutorials/generative/pix2pix) - [Classify structured data using Keras preprocessing layers](https://www.tensorflow.org/tutorials/structured_data/preprocessing_layers) - [Transfer learning with YAMNet for environmental sound classification](https://www.tensorflow.org/tutorials/audio/transfer_learning_audio) - [Load CSV data](https://www.tensorflow.org/tutorials/load_data/csv) |\n\nA Keras tensor is a symbolic tensor-like object, which we augment with\ncertain attributes that allow us to build a Keras model just by knowing the\ninputs and outputs of the model.\n\nFor instance, if `a`, `b` and `c` are Keras tensors,\nit becomes possible to do:\n`model = Model(input=[a, b], output=c)`\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `shape` | A shape tuple (tuple of integers or `None` objects), not including the batch size. For instance, `shape=(32,)` indicates that the expected input will be batches of 32-dimensional vectors. Elements of this tuple can be `None`; `None` elements represent dimensions where the shape is not known and may vary (e.g. sequence length). |\n| `batch_size` | Optional static batch size (integer). |\n| `dtype` | The data type expected by the input, as a string (e.g. `\"float32\"`, `\"int32\"`...) |\n| `sparse` | A boolean specifying whether the expected input will be sparse tensors. Note that, if `sparse` is `False`, sparse tensors can still be passed into the input - they will be densified with a default value of 0. This feature is only supported with the TensorFlow backend. Defaults to `False`. |\n| `name` | Optional name string for the layer. Should be unique in a model (do not reuse the same name twice). It will be autogenerated if it isn't provided. |\n| `tensor` | Optional existing tensor to wrap into the `Input` layer. If set, the layer will use this tensor rather than creating a new placeholder tensor. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Keras tensor. ||\n\n\u003cbr /\u003e\n\n#### Example:\n\n # This is a logistic regression in Keras\n x = Input(shape=(32,))\n y = Dense(16, activation='softmax')(x)\n model = Model(x, y)"]]