Keras Input Layer Last Updated : 16 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 NN architectureIt acts as the entry point for data in a neural network. It essentially informs the model about:The number and type of features in the inputThe expected dimensionalityThe batch size (optional)There are two ways to define the input layer in Keras:Using the keras.Input() function.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: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).Example: Defining a CNN Model with an Input LayerBelow is an example of using keras.Input() to define a Convolutional Neural Network (CNN) for grayscale image classification:Input Layer: The model begins with an explicit Input() declaration, specifying the input shape (28, 28, 1) for grayscale images and a fixed batch_size=3. This helps the model know exactly what kind of input to expect.Convolution and Pooling: A Conv2D layer with 16 filters and ReLU activation extracts spatial features. It's followed by a MaxPooling2D layer that reduces spatial dimensions helping with downsampling and reducing computation.Flattening and Classification: Flatten() converts the pooled feature maps into a 1D vector. Then, a Dense() layer with 10 neurons and softmax activation is used to classify the input into one of 10 categories (e.g., digits 0–9).Model Assembly and Output: Using Keras’s Functional API, the input and output layers are connected to create the final model. Python 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 LayerInput Shape Definition: Specifies the shape of the input, excluding the batch size. For example, an input shape of (28, 28) represents a 28x28 grayscale image.Compatibility: Ensures that the model receives the correct format of input, helping prevent shape mismatch errors.Flexibility: Particularly useful for handling variable-length inputs in models dealing with sequences like NLP or time-series. Comment More infoAdvertise with us Next Article tf.keras.layers.Dropout in TensorFlow N navyathoo2vw Follow Improve Article Tags : Deep Learning AI-ML-DS AI-ML-DS With Python Similar Reads Keras Layers API The Keras Layers API is a fundamental building block for designing and implementing deep learning models in Python. It offers a way to create networks by connecting layers that perform specific computational operations. The Layers API provides essential tools for building robust models across variou 5 min read Building Custom Layers in Keras Keras is a tool that helps us build deep learning models easily which gives us many layers like Dense, Conv2Do and LSTM that we can use in our models. But sometimes we want to do something different that these layers canât do. In such cases we can create our own custom layer where we can write our o 3 min read What is Keras? Keras is a deep learning API that simplifies the process of building deep neural networks. Initially it was developed as an independent library, Keras is now tightly integrated into TensorFlow as its official high-level API. It supports multiple backend engines like TensorFlow, Theano and Microsoft 4 min read tf.keras.layers.Dropout in TensorFlow In deep learning, overfitting is a common challenge where a model learns patterns that work well on training data but fails to generalize to unseen data. One effective technique to mitigate overfitting is Dropout, which randomly deactivates a fraction of neurons during training. In TensorFlow, this 2 min read What is Embedding Layer ? The embedding layer converts high-dimensional data into a lower-dimensional space. This helps models to understand and work with complex data more efficiently, mainly in tasks such as natural language processing (NLP) and recommendation systems. In this article, we will discuss what an embedding lay 6 min read Types of Convolution Kernels Convolution kernels, or filters, are small matrices used in image processing. They slide over images to apply operations like blurring, sharpening, and edge detection. Each kernel type has a unique function, altering the image in specific ways. The article aims to provide a comprehensive overview of 8 min read Like