- Keras Tutorial
- Keras - Home
- Keras - Introduction
- Keras - Installation
- Keras - Backend Configuration
- Keras - Overview of Deep learning
- Keras - Deep learning
- Keras - Modules
- Keras - Layers
- Keras - Customized Layer
- Keras - Models
- Keras - Model Compilation
- Keras - Model Evaluation and Prediction
- Keras - Convolution Neural Network
- Keras - Regression Prediction using MPL
- Keras - Time Series Prediction using LSTM RNN
- Keras - Applications
- Keras - Real Time Prediction using ResNet Model
- Keras - Pre-Trained Models
- Keras Useful Resources
- Keras - Quick Guide
- Keras - Useful Resources
- Keras - Discussion

# Keras - Convolution Layers

Keras contains a lot of layers for creating Convolution based ANN, popularly called as *Convolution Neural Network (CNN)*. All convolution layer will have certain properties (as listed below), which differentiate it from other layers (say Dense layer).

**Filters** − It refers the number of filters to be applied in the convolution. It affects the dimension of the output shape.

**kernel size** − It refers the length of the convolution window.

**Strides** − It refers the stride length of the convolution.

**Padding** − It refers the how padding needs to be done on the output of the convolution. It has three values which are as follows −

means no padding*valid*means causal convolution.*causal*means the output should have same length as input and so, padding should be applied accordingly*same*

**Dilation Rate** − dilation rate to be applied for dilated convolution. −

Another important aspect of the convolution layer is the data format. The data format may be to two type,

** channel_last: channel_last** − specifies that the channel data is placed as last entry. Here, channel refers the actual data and it will be placed in the last dimension of the input space. −

For example, let us consider an input shape, **(30, 10, 128)**. Here, the value in first dimension, **30** refers the batch size, the value in second dimension, **10** refers the ** timesteps** in temporal convolution and the value in third dimension

**128**refers the actual values of the input. This is the default setting in Keras.

** channel_first: channel_first** is just opposite to

**. Here, the input values are placed in the second dimension, next to batch size.**

*channet_last*Let us see check the all the layer used for CNN provided by Keras layers in this chapter.

### Conv1D

** Conv1D layer** is used in temporal based CNN. The input shape of the ConvID will be in below format −

(batch_size, timesteps, features)

where,

refers the size of the batch.*batch_size*refers the number of time steps provided in the input.*timesteps*refer the number of features available in the input.*features*

The output shape of the *Conv1D* is as follows −

(batch_size, new_steps, filters)

where, ** filters** refer the number of filters specified as one of the arguments.

The signature of the *ConvID* function and its arguments with default value is as follows −

keras.layers.Conv1D( filters, kernel_size, strides = 1, padding = 'valid', data_format = 'channels_last', dilation_rate = 1, activation = None, use_bias = True, kernel_initializer = 'glorot_uniform', bias_initializer = 'zeros', kernel_regularizer = None, bias_regularizer = None, activity_regularizer = None, kernel_constraint = None, bias_constraint = None )

### Conv2D

It is a convolution 2D layer. It creates a convolutional kernel with the layer input creates a tensor of outputs. input_shape refers the tuple of integers with RGB value in data_format = “channels_last”.

The signature of the ** Conv2D** function and its arguments with default value is as follows −

keras.layers.Conv2D (filters, kernel_size, strides = (1, 1), padding = 'valid', data_format = None, dilation_rate = (1, 1), activation = None, use_bias = True, kernel_initializer = 'glorot_uniform', bias_initializer = 'zeros', kernel_regularizer = None, bias_regularizer = None, activity_regularizer = None, kernel_constraint = None, bias_constraint = None )

Here,

refer an integer specifying the strides of the convolution along the height and width.*strides*