Python Tensorflow - tf.keras.layers.Conv2D() Function Last Updated : 09 Feb, 2025 Comments Improve Suggest changes Like Article Like Report The tf.keras.layers.Conv2D() function in TensorFlow is a key building block of Convolutional Neural Networks (CNNs). It applies convolutional operations to input images, extracting spatial features that improve the model’s ability to recognize patterns.The Conv2D layer applies a 2D convolution over an input image, performing the following operation:\text{output=activation(convolution(input,kernel)+bias)}where:convolution(input, kernel): A sliding window operation (filter) applied over the input image.kernel: A set of learnable weights (filters) that detect specific features.bias: A bias vector added to the convolution output.activation: An activation function applied element-wise.Syntax of tf.keras.layers.Conv2D()tf.keras.layers.Conv2D( filters, kernel_size, strides=(1, 1), padding='valid', activation=None, use_bias=True, kernel_initializer="glorot_uniform", bias_initializer="zeros")Parameters Explained: filters (Required): Number of filters (kernels) applied in the convolution. Determines the number of output channels.kernel_size (Required): Size of the filter (e.g., (3,3) for a 3×3 kernel).strides (Default: (1,1)): Step size for moving the filter across the input.padding:'valid' (default): No padding, output size is reduced.'same': Zero-padding is added to keep the output size the same as the input.activation (Optional): Activation function (e.g., 'relu', 'sigmoid').use_bias (Default: True): Whether to include a bias term.kernel_initializer (Default: glorot_uniform): Defines how the filters are initialized.bias_initializer (Default: zeros): Defines how the bias is initialized.Using Conv2D in a CNN ModelBelow is the implementation of the CNN model. Python from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras.utils import plot_model from IPython.display import Image # Define a simple CNN model model = keras.Sequential([ layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)), # First conv layer layers.MaxPooling2D(pool_size=(2, 2)), # Downsample the feature maps layers.Conv2D(64, (3, 3), activation='relu'), # Second conv layer layers.MaxPooling2D(pool_size=(2, 2)), # Downsample again layers.Flatten(), # Flatten the output for the dense layer layers.Dense(128, activation='relu'), # Fully connected layer layers.Dense(10, activation='softmax') # Output layer (10 classes) ]) # Compile the model model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) model.summary() Output: Comment More infoAdvertise with us Next Article Python Tensorflow - tf.keras.layers.Conv2D() Function jaintarun Follow Improve Article Tags : Machine Learning AI-ML-DS python Python-Tensorflow Practice Tags : Machine Learningpython Similar Reads Python Tensorflow â tf.keras.layers.Conv3D() Function In this article, we will cover Tensorflow tf.keras.layers.Conv3D() function. TensorFlow is a free and open-source machine learning library. TensorFlow was created by Google Brain Team researchers and engineers as part of Google's Machine Intelligence research group with the aim of performing machine 6 min read Python Tensorflow - tf.keras.layers.Conv1DTranspose() Function The tf.keras.layers.Conv1DTranspose() function is used to apply the transposed 1D convolution operation, also known as deconvolution, on data. Syntax:tf.keras.layers.Conv1DTranspose( filters, kernel_size, strides=1, padding='valid', output_padding=None,  data_format=None, dilation_rate=1, activatio 2 min read Tensorflow.js tf.layers.conv2d() Function Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. 3 min read Tensorflow.js tf.layers.conv3d() Function Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. 3 min read Tensorflow.js tf.layers.conv1d() Function Tensorflow.js is a javascript library developed by Google to run and train machine learning models in the browser or in Node.js. Tensorflow.js tf.layers.conv1d() function is used to create convolution layer. It is used to applied 1d convolution to the input data. The convolutional layer is used to m 4 min read Tensorflow.js tf.layers.convLstm2d() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.layers.convLstm2d() function is used for creating a ConvRNN2D layer which consists of one ConvLSTM2DCell a 5 min read Tensorflow.js tf.layers.cropping2D() Function Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. 2 min read Tensorflow.js tf.layers.convLstm2dCell() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.layers.convLstm2dCell() is used to create ConvLSTM2DCell which is different from the ConvRNN2D subclass Co 4 min read Tensorflow.js tf.layers.dot() Function Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. Tensorflow.js tf.layers.dot() function is used to apply the dot product between the two tensors provided. Syntax: tf.layers.dot(args) 3 min read Tensorflow.js tf.layers.rnn() Function Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. Tensorflow.js tf.layers.rnn() function is basically base class for recurrent layers. Syntax: tf.layers.rnn( args ); Parameters: arg 4 min read Like