Example Usage of keras.Input

In this section, we have defined a CNN model with an input shape of (28, 28, 1) and a batch size of 3 using TensorFlow’s Keras API. It includes a convolutional layer with 16 filters, a max pooling layer, a flatten layer, and a dense layer with 10 units and a softmax activation function for classification. The shape of the input layer is printed, showing the specified shape and batch size.

Python3
from tensorflow import keras
from keras import models, layers
input_layer = keras.layers.Input(shape=(28, 28, 1),batch_size=3)
model = models.Sequential([
  layers.Conv2D(16, (3,3)),
  layers.MaxPooling2D(pool_size=2),
  layers.Flatten(),
  layers.Dense(10, activation='softmax'),
])
print("The shape of input layer: ",input_layer.shape)

Output:

The shape of input layer:  (3, 28, 28, 1)
  • The input layer in Keras is in charge of obtaining and transforming the input data, making it a crucial part of deep learning models.
  • The whole neural network architecture depends on the shape of the input data.
  • Thus to start with building an efficient neural network, Input layer is necessary.



Keras Input Layer

When deep learning models are built, the foundation step of the model preparation starts with the input layer. Keras Input Layer is essential for defining the shape and size of the input data the model with receive. In this article, we are going to learn more on Keras Input Layer, its purpose, usage and it’s role in model architecture.

Table of Content

  • What is Keras Input Layer?
  • Key Features of Keras Input Layer
  • Syntax of Keras Input Layer
  • Example Usage of keras.Input

Similar Reads

What is Keras Input Layer?

The Input Layer in Keras is the starting point of any neural network. It is not a traditional layer that processes or transforms data. Instead, it serves as a specification of the kind of input the model expects, including the dimensions and type of data. Essentially, it defines how the network should receive the input data, setting the stage for the subsequent layers....

Key Features of Keras Input Layer

Input Shape Specification: The Input Layer specifies the shape of the input data, not including the batch size. For instance, for a 28×28 pixel image, the input shape would be (28, 28).Compatibility: Ensures that the first layer of the model is prepared to receive the correct form of data, facilitating smoother data processing through the network.Flexibility: It allows the model to handle input data of varying lengths, especially important in models processing sequences or time series....

Syntax of Keras Input Layer

The keras.Input function is used to instantiate a tensor object that is useful when building model that use the functional API....

Example Usage of keras.Input

In this section, we have defined a CNN model with an input shape of (28, 28, 1) and a batch size of 3 using TensorFlow’s Keras API. It includes a convolutional layer with 16 filters, a max pooling layer, a flatten layer, and a dense layer with 10 units and a softmax activation function for classification. The shape of the input layer is printed, showing the specified shape and batch size....