Keras Input Layer (original) (raw)

Last Updated : 16 Jul, 2025

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.

Keras_neural_network

Keras NN architecture

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:

  1. Using the **keras.Input() function.
  2. By specifying the **input_shape argument in the first layer of the model.

Syntax of 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.

Python `

keras.Input( shape=None, batch_size=None, dtype=None, sparse=None, batch_shape=None, name=None, tensor=None )

`

Parameters:

Example: Defining a CNN Model with an Input Layer

Below is an example of using keras.Input() to define a Convolutional Neural Network (CNN) for grayscale image classification:

from tensorflow.keras import Input, Model from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense

#input layer input_layer = Input(shape=(28, 28, 1), batch_size=3)

#convolution and pooling x = Conv2D(16, kernel_size=(3, 3), activation='relu')(input_layer) x = MaxPooling2D(pool_size=(2, 2))(x)

#flattening and classification x = Flatten()(x) output_layer = Dense(10, activation='softmax')(x)

#model assembly and output model = Model(inputs=input_layer, outputs=output_layer) print("The shape of input layer: ", input_layer.shape)

`

Key Features Keras Input Layer