![]() |
VOOZH | about |
Keras Input Layer helps setting up the shape and type of data that the model should expect. It doesn’t do any processing itself, but tells the model what kind of input to receive like the size of an image or the number of features in a dataset. This makes sure all the layers that come after can work properly with the data making it an important part of building any neural network.
It acts as the entry point for data in a neural network. It essentially informs the model about:
There are two ways to define the input layer in Keras:
keras.Input()To explicitly create an input layer we can use keras.Input() function which returns a symbolic tensor. This is especially useful in the Functional API.
shape: Tuple specifying the input dimensions (excluding batch size). E.g., (32, 32, 3) for a 32x32 RGB image.batch_size: Optional integer that sets a fixed batch size for the inputs. Useful in stateful models.dtype: Data type of the input tensor (e.g., 'float32'). Defaults to 'float32'.sparse: Boolean indicating whether the input is a sparse tensor.batch_shape: Like shape, but includes the batch size (e.g., (None, 28, 28)).name: Optional string to name the input layer.tensor: Existing tensor to wrap in an Input layer (advanced use case for external tensors).Below is an example of using keras.Input() to define a Convolutional Neural Network (CNN) for grayscale image classification:
(28, 28) represents a 28x28 grayscale image.