You are on page 1of 42

Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Home Java Keras JavaScript Bootstrap C HTML XHTML CSS jQuery XML

Keras Convolutional Layers


Conv1D

1. keras.layers.Conv1D(filters, kernel_size, strides=1, padding='valid', data_format='channels_last', dilation

It refers to a one-dimensional convolutional layer. For


example, temporal convolution which generates a
convolution kernel for creating a tensor of outputs. The
convolution kernel is convolved with input layer over a
single temporal (spatial) dimension. A bias vector will be
developed and included to the outputs, if use_bias is True.
It will be applied to the output, if activation is set None.

When we utilize the conv1D layer as the initial layer in our


model, it provides us with an input_shape argument, which
is either a tuple of integers or None. It does not incorporate
the batch axis.

Arguments

filters: Filters refers to an integer in which the output


space dimensionality or the number of output filters
present in the convolution.

kernel_size: It is an integer or tuple/list of an


individual integer that specifies the length of the 1D
convolution window.

https://www.javatpoint.com/keras-convolutional-layers Page 1 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

strides: It is an integer or tuple/list of an individual


integer that specifies the stride length of the
convolution. Determining any stride value != 1 is
incompatible with specifying any dilation_rate value
!= 1.

padding: It is one of "valid", "casual" or "same",


where valid implies to no padding, same means
padding the input in such a way that it generates the
output having the same length as that of the original
input and casual results in dilated output, i.e.,
output[t] is independent of output[t + 1:]. To get
the output length similar to the input, a zero-padding
can be used. The concept of padding is useful while
modeling a temporal data in order to make sure that
the model does not violate temporal

data_format: It is a string of "channels_last" or


"channels_first", which is the order of input
dimensions. Here the "channels_last" links to the
input shape (batch, steps, channels), which is the
default format for temporal data in Keras. However,
the "channels_first" is used to relate the input shape
(batch, channels, steps).

dilation_rate: It is an integer or tuple/ list of an


individual integer that relates to the dilation rate of a
dilated convolution. It currently relates any
dilation_rate value != 1 is incompatible by specifying
any strides value != 1.

activation: It refers to an activation function to be


used. When nothing is specified, then by defaults, it
is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

https://www.javatpoint.com/keras-convolutional-layers Page 2 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

kernel_initializer: It can be defined as an initializer


for the kernel weights matrix.

bias_initializer: It refers to an initializer for bias


vector.

kernel_regularizer: It refers to a regularizer function,


which is applied to the kernel weights matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

kernel_constraint: It is a constraint function applied


to the kernel matrix.

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

Input shape

It refers to a 3D tensor of shape (batch, steps, channels).

Output shape

https://www.javatpoint.com/keras-convolutional-layers Page 3 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

The output shape is a 3D tensor of shape (batch,


new_steps, filters) steps. The values might differ due to
strides and padding.

Conv2D

1. 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

It refers to a two-dimensional convolution layer, like a spatial


convolution on images. It develops a convolution kernel,
which can be convolved with the input layer for the
generation of the tensors output. If we set use_bias to
True, it will create a bias vector, which will be added to the
output. Similarly, if we set activation to None, then also it
will be added to the output. The layer can be used as an
initial layer in the model by using the input_shape keyword
argument, which is a tuple of integers, and it does not
include the batch axis.

Arguments

filter: It is an integer that signifies the output space


dimensionality or a total number of output filters
present in a convolution.

kernel_size: It can either be an integer or tuple/list of


2 integers to represent the height and width of a 2D
convolution window. It can also exist as a single
integer that signifies the same value for rest all of the
spatial domain.

strides: It is either an integer or a tuple/list of 2


integers that represents the convolution strides along
with height and width. It might exist as a single

https://www.javatpoint.com/keras-convolutional-layers Page 4 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

integer that indicates the same value for the spatial


dimension. If we signify any stride value!=1, it relates
to its incompatibility with specifying the dilation_rate
value!=1.

padding: One of "valid" or "same," where the same


reflects some inconsistency across the backend with
strides !=1.

data_format: It is a string of "channels_last" or


"channels_first", which is the order of input
dimensions. Here the "channels_last" describes the
input shape (batch, height, width, channels), and
the "channels_first" describes the input shape
(batch, channels, height, width). It defaults to the
image_data_format value that is found in Keras
config at ~/.keras/keras.json. If you cannot find it in
that folder, then it is residing at "channels_last".

dilation_rate: It can be an integer or tuple/ list of 2


integers that relates to the dilation rate to be used for
dilated convolution. It might have an individual integer
that indicates the same value for a spatial dimension.
If we specify any stride value!=1, it relates to its
incompatibility with specifying the dilation_rate
value!=1.

activation: It refers to an activation function to be


used. When nothing is specified, then by defaults, it
is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

kernel_initializer: It can be defined as an initializer


for the kernel weights matrix.

bias_initializer: It refers to an initializer for bias

https://www.javatpoint.com/keras-convolutional-layers Page 5 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

vector.

kernel_regularizer: It refers to a regularizer function,


which is applied to the kernel weights matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

kernel_constraint: It is a constraint function applied


to the kernel matrix.

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

Input shape

If the data_format is "channels_first", then the input


shape of a 4D tensor is (batch, channels, rows, cols), else
if data_format is "channels_last" the input shape of a 4D
tensor is (batch, rows, cols, channels).

Output shape

https://www.javatpoint.com/keras-convolutional-layers Page 6 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

If the data_format is "channels_first", the output shape of


a 4D tensor will be (batch, filters, new_rows, new_cols),
else if the data_format is "channels_last" the output will be
(batch, new_rows, new_cols, filters). The values of rows
and cols might variate due to the effect of padding.

SeparableConv1D

1. keras.layers.SeparableConv1D(filters, kernel_size, strides=1, padding='valid', data_format='channels_la

It is a Depthwise separable 1D convolution. Firstly, it


accomplishes a depthwise spatial convolution on an single
channel and then pointwise convolution to mix the resultant
channels output. The argument depth_multiplier manages
the generation of number of outputs channels per input
channel in a depthwise manner.

The Separable Convolutions can be easily understood by


means of factorizing a convolution kernel into two smaller
kernels.

Arguments

filter: It is an integer that signifies the output space


dimensionality or a total number of output filters
present in a convolution.

kernel_size: It can either be an integer or tuple/list of


single integer to represent the length of a 1D
convolution window.

strides: It is either an integer or a tuple/list of a single


integer that represents the convolution strides
length. If we specify any stride value!=1, it relates to
its incompatibility with specifying the dilation_rate
value!=1.

https://www.javatpoint.com/keras-convolutional-layers Page 7 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

padding: One of "valid" or "same," where the same


shows some inconsistency across the backend with
strides !=1.

data_format: It is in either mode, i.e.,


'channels_first' that corresponds to input shape:
(batch, channels, steps) or 'channels_last'
corresponds to (batch, steps, channels).

dilation_rate: It can be an integer or tuple/ list of a


single integer that relates to the dilation rate to be
used for dilated convolution. If we specify any stride
value!=1, it relates to its incompatibility with
specifying the dilation_rate value!=1.

depth_multiplier: It represents the total number of


depthwise convolution channels each of the
respective input channels, which is equivalent to
filters_in * depth_multiplier.

activation: It refers to an activation function to be


used. When nothing is specified, then by defaults, it
is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

depthwise_initializer: It refers to an initializer for the


depthwise kernel matrix.

pointwise_initializer: It refers to an initializer for the


pointwise kernel matrix.

bias_initializer: It refers to an initializer for bias


vector.

depthwise_regularizer: It refers to a regularizer


function that is applied to the depthwise kernel
matrix.

https://www.javatpoint.com/keras-convolutional-layers Page 8 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

pointwise_regularizer: It refers to a regularizer


function that is applied to the pointwise kernel matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

depthwise_constraint: It can be defined as a


constraint function applied to the depthwise kernel
matrix.

pointwise_constraint: It can be defined as a


constraint function applied to the pointwise kernel
matrix.

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

Input shape

If the data_format is "channels_first", then the input


shape of a 3D tensor is (batch, channels, steps), else if
the data_format is "channels_last," the input shape of a
3D tensor is (batch, steps, channels).

https://www.javatpoint.com/keras-convolutional-layers Page 9 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Output shape

If the data_format is "channels_first", then the output


shape of a 3D tensor will be (batch, filters, new_steps),
else if the data_format is "channels_last" the output
shape of a 3D tensor will be (batch, new_steps, filters).
The value of new_steps may vary due to the padding or
strides.

SeparableConv2D

1. keras.layers.SeparableConv2D(filters, kernel_size, strides=


(1, 1), padding='valid', data_format=None, dilation_rate=
(1, 1), depth_multiplier=1, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', point

It is a depthwise separable 2D convolution. Firstly, it


performs a depthwise spatial convolution on an individual
channel and then pointwise convolution to mix the output of
the resultant channel. The argument depth_multiplier
manages the generation of the number of outputs channels
per input channel in a depthwise manner.

The Separable Convolutions can be easily understood by


means of factorizing a convolution kernel into two smaller
kernels or as an extension of an Inception block.

Arguments

filter: It is an integer that signifies the output space


dimensionality or the total number of output filters
present in a convolution.

https://www.javatpoint.com/keras-convolutional-layers Page 10 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

kernel_size: It can either be an integer or tuple/list of


2 integers to represent the height and width of a 2D
convolution window. It can also exist as a single
integer that signifies the same value for rest all of the
spatial domain.

strides: It is either an integer or a tuple/list of 2


integers that represents the convolution strides along
with the height and width. It can also exist as a single
integer that signifies the same value for rest all of the
spatial domain. If we specify any stride value!=1, it
relates to its incompatibility with specifying the
dilation_rate value!=1.

padding: One of "valid" or "same," where the same


shows some inconsistency across the backend with
strides !=1.

data_format: It is in either mode, i.e.,


'channels_first' that corresponds to input shape:
(batch, channels, height, width) or 'channels_last'
corresponds to (batch, height, width, channels). It
defaults to the image_data_format value that is
found in Keras config at ~/.keras/keras.json. If you
cannot find it in that folder, then it is residing at
"channels_last".

dilation_rate: It can be an integer or tuple/ list of 2


integers that relates to the dilation rate to be used for
dilated convolution. If we specify any stride value!=1,
it relates to its incompatibility with specifying the
dilation_rate value!=1.

depth_multiplier: It represents the total number of


depthwise convolution channels for each of the
respective input channels, which is equivalent to
filters_in * depth_multiplier.

activation: It refers to an activation function to be

https://www.javatpoint.com/keras-convolutional-layers Page 11 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

used. When nothing is specified, then by defaults, it


is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

depthwise_initializer: It refers to an initializer for the


depthwise kernel matrix.

pointwise_initializer: It refers to an initializer for the


pointwise kernel matrix.

bias_initializer: It refers to an initializer for bias


vector.

depthwise_regularizer: It refers to a regularizer


function that is applied to the depthwise kernel
matrix.

pointwise_regularizer: It refers to a regularizer


function that is applied to the pointwise kernel matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

depthwise_constraint: It can be defined as a


constraint function applied to the depthwise kernel
matrix.

pointwise_constraint: It can be defined as a


constraint function applied to the pointwise kernel
matrix.

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

Input shape

https://www.javatpoint.com/keras-convolutional-layers Page 12 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

If the data_format is "channels_first", then the input


shape of a 4D tensor is (batch, channels, rows, cols), else
if the data_format is "channels_last" the input shape of a
4D tensor is (batch, rows, cols, channels).

Output shape

If the data_format is "channels_first", then the output


shape of a 4D tensor will be (batch, filters, new_rows,
new_cols), else if the data_format is "channels_last" the
output shape of a 4D tensor will be (batch, new_rows,
new_cols, filters). The value of rows and cols may vary
due to the padding or strides.

DepthwiseConv2D

1. keras.layers.DepthwiseConv2D(kernel_size, strides=
(1, 1), padding='valid', depth_multiplier=1, data_format=None, dilation_rate=
(1, 1), activation=None, use_bias=True, depthwise_initializer='glorot_uniform', bias_initializer='zeros'

It is a depthwise 2D convolution layer that firstly performs a


similar action as that of the depthwise spatial convolution in
which it separately performs on each input channel. The
argument depth_multiplier manages the generation of the
number of outputs channels per input channel in a
depthwise manner.

Arguments

https://www.javatpoint.com/keras-convolutional-layers Page 13 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

kernel_size: It can either be an integer or tuple/list of


2 integers to represent the height and width of a 2D
convolution window. It can also exist as a single
integer that signifies the same value for all of the
spatial domain.

strides: It is either an integer or a tuple/list of 2


integers that represents the convolution strides along
with the height and width. It can exist as a single
integer that signifies the same value for rest all of the
spatial domain. If we specify any stride value!=1, it
relates to its incompatibility with specifying the
dilation_rate value!=1.

padding: One of "valid" or "same," where the same


shows some inconsistency across the backend with
strides !=1.

data_format: It is in either mode, i.e.,


'channels_first' that corresponds to input shape:
(batch, channels, height, width) or 'channels_last'
corresponds to (batch, height, width, channels). It
defaults to the image_data_format value that is
found in Keras config at ~/.keras/keras.json. If you
cannot find it in that folder, then it is residing at
"channels_last".

dilation_rate: It can be an integer or tuple/ list of 2


integers that relates to the dilation rate to be used for
dilated convolution. If we specify any stride value!=1,
it relates to its incompatibility with specifying the
dilation_rate value!=1.

https://www.javatpoint.com/keras-convolutional-layers Page 14 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

depth_multiplier: It represents the total number of


depthwise convolution channels for each of the
respective input channels, which is equivalent to
filters_in * depth_multiplier.

activation: It refers to an activation function to be


used. When nothing is specified, then by defaults, it
is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

depthwise_initializer: It refers to an initializer for the


depthwise kernel matrix.

bias_initializer: It refers to an initializer for bias


vector.

depthwise_regularizer: It refers to a regularizer


function that is applied to the depthwise kernel
matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

depthwise_constraint: It can be defined as a


constraint function applied to the depthwise kernel
matrix.

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

Input shape

https://www.javatpoint.com/keras-convolutional-layers Page 15 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

If the data_format is "channels_first", then the input


shape of a 4D tensor is (batch, channels, rows, cols), else
if the data_format is "channels_last" the input shape of a
4D tensor is (batch, rows, cols, channels).

Output shape

If the data_format is "channels_first", then the output


shape of a 4D tensor will be (batch, channels *
depth_multiplier, new_rows, new_cols), else if the
data_format is "channels_last" the output shape of a 4D
tensor will be (batch, new_rows, new_cols, channels *
depth_multiplier). The value of rows and cols may vary
due to the padding or strides.

Conv2DTranspose

1. keras.layers.Conv2DTranspose(filters, kernel_size, strides=


(1, 1), padding='valid', output_padding=None, data_format=None, dilation_rate=
(1, 1), activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel

It is a Transpose convolution layer, which is sometimes


incorrectly known as Deconvolution. But in reality, it does
not perform Deconvolution. The Conv2DTranspose layer is
mainly required when the transformation moves in the
opposite direction to that of a normal convolution, or simply
we can say when the transformation goes from something
that has an output shape of some convolution to the one
that has input shape of convolution.

The layer can be used as an initial layer by using an


argument input_shape, which is nothing but a tuple of
integers and does not encompass the batch axis.

https://www.javatpoint.com/keras-convolutional-layers Page 16 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Arguments

filter: It is an integer that signifies the output space


dimensionality or a total number of output filters
present in a convolution.

kernel_size: It can either be an integer or tuple/list of


2 integers to represent the height and width of a 2D
convolution window. It can also exist as a single
integer that signifies the same value for all of the
spatial domain.

strides: It is either an integer or a tuple/list of 2


integers that represents the convolution strides along
with the height and width. It can exist as a single
integer that signifies the same value for rest all of the
spatial domain. If we specify any stride value!=1, it
relates to its incompatibility with specifying the
dilation_rate value!=1.

padding: One of "valid" or "same," where the same


shows some inconsistency across the backend with
strides !=1.

output_padding: It can either be an integer or


tuple/list of 2 integers to represent the height and
width of a 2D convolution window. It can also exist as
a single integer that signifies the same value for all of
the spatial domain. The amount of output data
padding along any specified dimension should be
given less than the stride along the same dimension.
By default, it is set to None, which states that the
output shape is inferred.

data_format: It is in either mode, i.e.,


'channels_first' that corresponds to input shape:
(batch, channels, height, width) or 'channels_last'
corresponds to (batch, height, width, channels). It

https://www.javatpoint.com/keras-convolutional-layers Page 17 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

defaults to the image_data_format value that is


found in Keras config at ~/.keras/keras.json. If you
cannot find it in that folder, then it is residing at
"channels_last".

dilation_rate: It can be an integer or tuple/ list of 2


integers that relates to the dilation rate to be used for
dilated convolution. If we specify any stride value!=1,
it relates to its incompatibility with specifying the
dilation_rate value!=1.

activation: It refers to an activation function to be


used. When nothing is specified, then by defaults, it
is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

kernel_initializer: It can be defined as an initializer


for the kernel weights matrix.

bias_initializer: It refers to an initializer for bias


vector.

kernel_regularizer: It refers to a regularizer function,


which is applied to the kernel weights matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

kernel_constraint: It is a constraint function applied


to the kernel matrix.

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

https://www.javatpoint.com/keras-convolutional-layers Page 18 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Input shape

If the data_format is "channels_first" then input shape of


a 4D tensor is (batch, channels, rows, cols), else if the
data_format is "channels_last" the input shape of a 4D
tensor is (batch, rows, cols, channels).

Output shape

If the data_format is "channels_first" then the output


shape of a 4D tensor will be (batch, filters, new_rows,
new_cols), else if the data_format is "channels_last" the
output shape of a 4D tensor will be (batch, new_rows,
new_cols, filters). The value of rows and cols may vary
due to the padding. If output_padding is specified:

1. new_rows = ((rows - 1) * strides[0] + kernel_size[0]


2. - 2 * padding[0] + output_padding[0])
3. new_cols = ((cols - 1) * strides[1] + kernel_size[1]
4. - 2 * padding[1] + output_padding[1])

Conv3D

1. keras.layers.Conv3D(filters, kernel_size, strides=


(1, 1, 1), padding='valid', data_format=None, dilation_rate=
(1, 1, 1), activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kern

It is a 3D convolution layer; for example, spatial convolution


over volumes helps in the creation of the convolution kernel,
which is convolved with the input layer in order to generate
outputs of a tensor. It creates a bias vector if the use_bias

https://www.javatpoint.com/keras-convolutional-layers Page 19 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

is set to True, and then the bias vector is added to the


output. It is applied outputs only if the activation is set to
None.

The layer can be used as the first layer in the model by


using the input_shape keyword argument, which is nothing
but a tuple of integers and does not embrace the batch
axis.

Arguments

filter: It is an integer that signifies the output space


dimensionality or a total number of output filters
present in a convolution.

kernel_size: It can either be an integer or tuple/list of


3 integers to represent the depth, height, and width
of a 3D convolution window. It can also exist as a
single integer that signifies the same value for all of
the spatial domain.

strides: It is either an integer or a tuple/list of 3


integers that represents the convolution strides along
with the depth, height, and width. It can exist as a
single integer that signifies the same value for rest all
of the spatial domain. If we specify any stride
value!=1, it relates to its incompatibility with
specifying the dilation_rate value!=1.

padding: One of "valid" or "same," where the same


shows some inconsistency across the backend with
strides !=1.

data_format: It is in either mode, i.e. 'channels_first'


that corresponds to input shape: (batch, channels,
spatial_dim1, spatial_dim2, spatial_dim3) or
'channels_last' corresponds to (batch,
spatial_dim1, spatial_dim2, spatial_dim3,

https://www.javatpoint.com/keras-convolutional-layers Page 20 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

channels). It defaults to the image_data_format


value that is found in Keras config at
~/.keras/keras.json. If you cannot find it in that
folder, then it is residing at "channels_last".

dilation_rate: It can be an integer or tuple/ list of 3


integers that relates to the dilation rate to be used for
dilated convolution. If we specify any stride value!=1,
it relates to its incompatibility with specifying the
dilation_rate value!=1.

activation: It refers to an activation function to be


used. When nothing is specified, then by defaults, it
is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

kernel_initializer: It can be defined as an initializer


for the kernel weights matrix.

bias_initializer: It refers to an initializer for bias


vector.

kernel_regularizer: It refers to a regularizer function,


which is applied to the kernel weights matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

kernel_constraint: It is a constraint function applied


to the kernel matrix.

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

https://www.javatpoint.com/keras-convolutional-layers Page 21 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Input shape

If the data_format is "channels_first" then input shape of


a 5D tensor is (batch, channels, conv_dim1, conv_dim2,
conv_dim3), else if the data_format is "channels_last" the
input shape of a 5D tensor is (batch, conv_dim1,
conv_dim2, conv_dim3, channels).

Output shape

If the data_format is "channels_first" then the output


shape of a 5D tensor will be (batch, filters,
new_conv_dim1, new_conv_dim2, new_conv_dim3), else if
the data_format is "channels_last" the output shape of a
5D tensor will be (batch, new_conv_dim1, new_conv_dim2,
new_conv_dim3, filters). The value of new_conv_dim1,
new_conv_dim2 and new_conv_dim3 may vary due to the
padding.

Conv3D Transpose

1. keras.layers.Conv3DTranspose(filters, kernel_size, strides=


(1, 1, 1), padding='valid', output_padding=None, data_format=None, activation=None, use_bias=True, k

It is a transposed convolution layer, which is sometimes also


called as Deconvolution. This layer is mainly required when
the transformation moves in the opposite direction to that
of a normal convolution, or simply we can say when the
transformation goes from something that has an output
shape of some convolution to the one that has input shape
of convolution.

https://www.javatpoint.com/keras-convolutional-layers Page 22 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

The layer can be used as an initial layer by using an


argument input_shape, which is nothing but a tuple of
integers and does not encompass the batch axis.

Arguments

filter: It is an integer that signifies the output space


dimensionality or a total number of output filters
present in a convolution.

kernel_size: It can either be an integer or tuple/list of


3 integers to represent the depth, height, and width
of a 3D convolution window. It can also exist as a
single integer that signifies the same value for all of
the spatial domain.

strides: It is either an integer or a tuple/list of 3


integers that represents the convolution strides along
with the depth, height, and width. It can exist as a
single integer that signifies the same value for rest all
of the spatial domain. If we specify any stride
value!=1, it relates to its incompatibility with
specifying the dilation_rate value!=1.

padding: One of "valid" or "same," where the same


shows some inconsistency across the backend with
strides !=1.

output_padding: It can either be an integer or


tuple/list of 3 integers to represent the depth, height,
and width of a 3D convolution window. It can also
exist as a single integer that signifies the same value
for all of the spatial domain. The amount of output
data padding along any specified dimension should
be given less than the stride along the same
dimension. By default, it is set to None, which states
that the output shape is inferred.

data_format: It is in either mode, i.e.,

https://www.javatpoint.com/keras-convolutional-layers Page 23 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

'channels_first' that corresponds to input shape:


(batch, channels, depth, height, width) or
'channels_last' corresponds to (batch, depth,
height, width, channels). It defaults to the
image_data_format value that is found in Keras
config at ~/.keras/keras.json. If you cannot find it in
that folder, then it is residing at "channels_last".

dilation_rate: It can be an integer or tuple/ list of 3


integers that relates to the dilation rate to be used for
dilated convolution. If we specify any stride value!=1,
it relates to its incompatibility with specifying the
dilation_rate value!=1.

activation: It refers to an activation function to be


used. When nothing is specified, then by defaults, it
is a linear activation a(x) = x, or we can say no
activation function is applied.

use_bias: It represents a Boolean that shows


whether the layer utilizes a bias vector.

kernel_initializer: It can be defined as an initializer


for the kernel weights matrix.

bias_initializer: It refers to an initializer for bias


vector.

kernel_regularizer: It refers to a regularizer function,


which is applied to the kernel weights matrix.

bias_regularizer: It can be defined as a regularizer


function, which is applied to the bias vector.

activity_regularizer: It refers to a regularizer


function that is applied to the activation (output of
the layer).

kernel_constraint: It is a constraint function applied


to the kernel matrix.

https://www.javatpoint.com/keras-convolutional-layers Page 24 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

bias_constraint: It can be defined as a constraint


function applied to the bias vector.

Input shape

If the data_format is "channels_first" then input shape of


a 5D tensor is (batch, channels, depth, rows, cols), else if
the data_format is "channels_last" the input shape of a
5D tensor is (batch, depth, rows, cols, channels).

Output shape

If the data_format is "channels_first" then the output


shape of a 5D tensor will be (batch, filters, new_depth,
new_rows, new_cols), else if the data_format is
"channels_last" the output shape of a 5D tensor will be
(batch, new_depth, new_rows, new_cols, filters). The
value of depth, rows and cols may vary due to the
padding. If output_padding is specified::

1. new_depth = ((depth - 1) * strides[0] + kernel_size[0]


2. - 2 * padding[0] + output_padding[0])
3. new_rows = ((rows - 1) * strides[1] + kernel_size[1]
4. - 2 * padding[1] + output_padding[1])
5. new_cols = ((cols - 1) * strides[2] + kernel_size[2]
6. - 2 * padding[2] + output_padding[2])

Cropping1D

1. keras.layers.Cropping1D(cropping=(1, 1))

https://www.javatpoint.com/keras-convolutional-layers Page 25 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

It is a cropping layer for 1Dimension input, for example, a


temporal sequence that crops alongside axis 1, i.e., time
dimension.

Arguments

cropping: It is a tuple, which is of int length 2


ensures a total number of units to be trimmed at the
beginning and end of axis 1(cropping dimension). In
case if you provide a single int, then the same value
will be utilized at the beginning and end.

Input shape

It is a 3D tensor of shape (batch, axis_to_crop, features).

Output shape

It is a 3D tensor of shape (batch, cropped_axis, features).

Cropping2D

1. keras.layers.Cropping2D(cropping=
((0, 0), (0, 0)), data_format=None)

https://www.javatpoint.com/keras-convolutional-layers Page 26 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

It is a 2Dimension cropping layer for example picture that


yields along the spatial dimensions such as height and
width.

Arguments

cropping: It is a int, or tuple of 2 ints, or a tuple of 2


tuples of 2 int, such that if int, which is the same
cropping symmetric is applied to height and width
and if tuple of 2 int is interpreted as two different
symmetric cropping value for height and width:
(symmetric_height_crop, symmetric_width_crop)

data_format: It is in either mode, i.e. 'channels_first'


that corresponds to input shape: (batch, channels,
height, width) or 'channels_last' corresponding to
(batch, height, width, channels). It is default to the
image_data_format value that is found in Keras
config at ~/.keras/keras.json. If you cannot find it in
that folder then it is residing at "channels_last".

Input shape

If the data_format is "channels_first" then input shape of


a 4D tensor is (batch, channels, rows, cols), else if the
data_format is "channels_last" the input shape of a 4D
tensor is (batch, rows, cols, channels).

Output shape

If the data_format is "channels_first" then the output


shape of a 4D tensor will be (batch, channels,
cropped_rows, cropped_cols), else if the data_format is
"channels_last" the output shape of a 4D tensor will be
(batch, cropped_rows, cropped_cols, channels).

Examples

https://www.javatpoint.com/keras-convolutional-layers Page 27 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

1. # Crop the input 2D images or feature maps


2. model = Sequential()
3. model.add(Cropping2D(cropping=((2, 2), (4, 4)),
4. input_shape=(28, 28, 3)))
5. # now model.output_shape == (None, 24, 20, 3)
6. model.add(Conv2D(64, (3, 3), padding='same'))
7. model.add(Cropping2D(cropping=((2, 2), (2, 2))))
8. # now model.output_shape == (None, 20, 16, 64)

Cropping3D

1. keras.layers.Cropping3D(cropping=
((1, 1), (1, 1), (1, 1)), data_format=None)

It is a 3D cropping layer just like spatio-temporal or spatial.

Arguments

cropping: It is an int, or a tuple of 3 ints, or a tuple of


3 tuples of 2ints, such that; If int is the same
symmetric cropping that is applied to depth, height
and width, If tuple of 3 ints is interpreted as three
distinct values of symmetric cropping for depth,
height and width: (symmetric_dim1_crop,
symmetric_dim2_crop, symmetric_dim3_crop) and
If tuple of 3 tuples of 2 ints is interpreted as
((left_dim1_crop, right_dim1_crop),
(left_dim2_crop, right_dim2_crop),
(left_dim3_crop, right_dim3_crop)).

data_format: It is a string of either mode, i.e.


'channels_first' that corresponds to input shape:
(batch, channels, spatial_dim1, spatial_dim2,
spatial_dim3) or 'channels_last' corresponding to

https://www.javatpoint.com/keras-convolutional-layers Page 28 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

(batch, spatial_dim1, spatial_dim2, spatial_dim3,


channels). It is default to the image_data_format
value that is found in Keras config at
~/.keras/keras.json. If you cannot find it in that
folder then it is residing at "channels_last".

Input shape

If the data_format is "channels_first" then input shape of


a 5D tensor is (batch, depth, first_axis_to_crop,
second_axis_to_crop, third_axis_to_crop), else if the
data_format is "channels_last" the input shape of a 5D
tensor is (batch, first_axis_to_crop, second_axis_to_crop,
third_axis_to_crop, depth).

Output shape

If the data_format is "channels_first" then the output


shape of a 5D tensor will be (batch, depth,
first_cropped_axis, second_cropped_axis,
third_cropped_axis), else if the data_format is
"channels_last" the output shape of a 5D tensor will be
(batch, first_cropped_axis, second_cropped_axis,
third_cropped_axis, depth).

UpSampling1D

1. keras.layers.UpSampling1D(size=2)

It is an Upsampling layer for 1 Dimensional inputs that


repeat each individual temporal steps in terms of size times
alongside time axis.

Arguments

https://www.javatpoint.com/keras-convolutional-layers Page 29 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

size: It is an integer, which is an Upsampling factor.

Input shape

It is a 3D tensor of shape: (batch, steps, features).

Output shape

It is a 3D tensor with shape: (batch, upsampled_steps,


features).

UpSampling2D

1. keras.layers.UpSampling2D(size=
(2, 2), data_format=None, interpolation='nearest')

It is an

Upsampling layer for 2D input that repeats the rows of the


data by size [0] and columns of the data by size [1].

Arguments

size: It is an int or tuple of 2 integers, which is an


upsampling factor for rows and columns.

data_format: It is a string of either mode, i.e.,


'channels_first' that corresponds to input shape:
(batch, channels, height, width) or 'channels_last'
corresponding to (batch, height, width, channels).
It defaults to the image_data_format value that is

https://www.javatpoint.com/keras-convolutional-layers Page 30 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

found in Keras config at ~/.keras/keras.json. If you


cannot find it in that folder, then it is residing at
"channels_last".

interpolation: It is a string one of nearest or


bilinear. It should be illustrated that CNTK does not
support yet the bilinear upscaling and that with
Theano, only size=(2, 2) is possible.

Input shape

If data_format is "channels_last", then the input shape of


a 4D tensor is (batch, rows, cols, channels), else if
data_format is "channels_first", then the input shape of a
4D tensor is (batch, channels, rows, cols).

Output shape

If data_format is "channels_last", then the output shape


of a 4D tensor is (batch, upsampled_rows,
upsampled_cols, channels), else if the data_format is
"channels_first", then the output shape of a 4D tensor is
(batch, channels, upsampled_rows, upsampled_cols).

UpSampling3D

1. keras.layers.UpSampling3D(size=
(2, 2, 2), data_format=None)

It refers to an Upsampling layer for 3 dimensional input that


repeats 1st dimension of the data by size [0], 2nd dimension
of the data by size [1], and 3rd dimension of the data by size
[2].

Arguments

https://www.javatpoint.com/keras-convolutional-layers Page 31 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

size: It is an int or tuple of 3 integers, which is an


upsampling factor for dim1, dim2, and dim3.

data_format: It is a string of either mode, i.e.


'channels_first' that corresponds to input shape:
(batch, channels, spatial_dim1, spatial_dim2,
spatial_dim3) or 'channels_last' corresponding to
(batch, spatial_dim1, spatial_dim2, spatial_dim3,
channels). It defaults to the image_data_format
value that is found in Keras config at
~/.keras/keras.json. If you cannot find it in that
folder, then it is residing at "channels_last".

Input shape

If data_format is "channels_last", then the input shape of


a 5D tensor is (batch, dim1, dim2, dim3, channels), else if
data_format is "channels_first", then the input shape of a
5D tensor is (batch, channels, dim1, dim2, dim3).

Output shape

If data_format is "channels_last", then the output shape


of a 4D tensor is (batch, upsampled_dim1,
upsampled_dim2, upsampled_dim3, channels), else if
the data_format is "channels_first", then the output shape
of a 4D tensor is (batch, channels, upsampled_dim1,
upsampled_dim2, upsampled_dim3).

ZeroPadding1D

1. keras.layers.ZeroPadding1D(padding=1)

https://www.javatpoint.com/keras-convolutional-layers Page 32 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

It refers to a zero-padding layer for one-dimensional input.


For example, a temporal sequence.

Argument

padding: It is an int, or tuple of int (length 2) or


dictionary, such that If int demonstrates a total
number of zeros to be added at the beginning as well
as at the end of the padding dimension(axis 1),
whereas in case of If a tuple of int (length 2) the
zeros are added at the beginning and end of the
padding dimension ((left_pad, right_pad)).

Input shape

It is a 3D tensor of shape (batch, axis_to_pad, features).

Output shape

It refers to a 3 dimensional tensor of shape (batch,


padded_axis, features).

ZeroPadding2D

1. keras.layers.ZeroPadding2D(padding=
(1, 1), data_format=None)

It refers to a two-dimensional input zero-padding layer (for


example, picture) that supports the addition of zero rows
and columns containing zeros at the top, bottom, left, and
right of a tensor image.

Arguments

padding: It is an int, or tuple of 2 ints, or tuple of 2

https://www.javatpoint.com/keras-convolutional-layers Page 33 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

tuples of 2 ints; where If int is the similar symmetric


padding being applied to height and width, If a tuple
of 2 ints is taken as two distinct values symmetric
padding values for height and width of:
(symmetric_height_pad, symmetric_width_pad),
whereas If a tuple of 2 tuples of 2 ints is understood
as ((top_pad, bottom_pad), (left_pad, right_pad)).

data_format: It is a string of either mode, i.e.,


'channels_first' that corresponds to input shape:
(batch, channels, height, width) or 'channels_last'
corresponding to (batch, height, width, channels).
It defaults to the image_data_format value that is
found in Keras config at ~/.keras/keras.json. If you
cannot find it in that folder, then it is residing at
"channels_last".

Input shape

If data_format is "channels_last", then the input shape of


a 4D tensor is (batch, rows, cols, channels), else if
data_format is "channels_first", then the input shape of a
4D tensor is (batch, channels, rows, cols).

Output shape

If data_format is "channels_last", then the output shape


of a 4D tensor is (batch, padded_rows, padded_cols,
channels), else if the data_format is "channels_first",
then the output shape of a 4D tensor is (batch, channels,
padded_rows, padded_cols).

ZeroPadding3D

1. keras.layers.ZeroPadding3D(padding=
(1, 1, 1), data_format=None)

https://www.javatpoint.com/keras-convolutional-layers Page 34 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

It is a three-dimensional zero-padding layer. For example,


spatial or Spatio-temporal.

Arguments

padding: It is an int, or a tuple of 3 ints, or a tuple of


3 tuples of 2ints, such that; If int is the same
symmetric padding that is applied to depth, height
and width, If tuple of 3 ints is interpreted as three
distinct values of symmetric padding values for
depth, height and width: (symmetric_dim1_pad,
symmetric_dim2_pad, symmetric_dim3_pad) and
If tuple of 3 tuples of 2 ints is interpreted as
((left_dim1_pad, right_dim1_pad), (left_dim2_pad,
right_dim2_pad), (left_dim3_pad,
right_dim3_pad)).

data_format: It is a string of either mode, i.e.


'channels_first' that corresponds to input shape:
(batch, channels, spatial_dim1, spatial_dim2,
spatial_dim3) or 'channels_last' corresponding to
(batch, spatial_dim1, spatial_dim2, spatial_dim3,
channels). It is default to the image_data_format
value that is found in Keras config at
~/.keras/keras.json. If you cannot find it in that
folder then it is residing at "channels_last".

Input shape

If the data_format is "channels_first" then input shape of


a 5D tensor is (batch, depth, first_axis_to_pad,
second_axis_to_pad, third_axis_to_pad), else if the
data_format is "channels_last" the input shape of a 5D
tensor is (batch, first_axis_to_pad, second_axis_to_pad,
third_axis_to_pad, depth).

Output shape

https://www.javatpoint.com/keras-convolutional-layers Page 35 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

If the data_format is "channels_first" then the output


shape of a 5D tensor will be (batch, depth,
first_padded_axis, second_padded_axis,
third_axis_to_pad), else if the data_format is
"channels_last" the output shape of a 5D tensor will be
(batch, first_padded_axis, second_padded_axis,
third_axis_to_pad, depth).

← Prev Next →

For Videos Join Our Youtube Channel:


Join Now

Feedback

Send your Feedback to feedback@javatpoint.com

https://www.javatpoint.com/keras-convolutional-layers Page 36 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Help Others, Please Share

Learn Latest Tutorials

Splunk SPSS

Swagger Transact-SQL

Tumblr ReactJS

Regex Reinforcement
Learning

R Programming RxJS

https://www.javatpoint.com/keras-convolutional-layers Page 37 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

React Native Python Design


Patterns

Python Pillow Python Turtle

Keras tutorial

Keras

Preparation

Aptitude

Aptitude Reasoning

Verbal Ability

Verbal Ability Interview


Questions

https://www.javatpoint.com/keras-convolutional-layers Page 38 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Company
Questions

Trending Technologies

AWS Tutorial

Artificial AWS
Intelligence

Selenium tutorial

Selenium Cloud Computing

Hadoop tutorial ReactJS Tutorial

Hadoop ReactJS

Data Science Angular 7

Git Tutorial

Blockchain Git

DevOps Tutorial

Machine Learning DevOps

https://www.javatpoint.com/keras-convolutional-layers Page 39 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

B.Tech / MCA

DBMS tutorial

DBMS Data Structures

DAA tutorial

DAA Operating System

Computer Network Compiler Design

https://www.javatpoint.com/keras-convolutional-layers Page 40 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Computer Discrete
Organization Mathematics

Ethical Hacking Computer Graphics

html tutorial

Software Web Technology


Engineering

Cyber Security Automata

C++ tutorial

C Programming C++

Java tutorial

Java .Net

Python tutorial List of Programs

Python Programs

https://www.javatpoint.com/keras-convolutional-layers Page 41 of 42
Keras Convolutional Layer - Javatpoint 26/05/2022, 05:17

Control System Data Mining

Data Warehouse

https://www.javatpoint.com/keras-convolutional-layers Page 42 of 42

You might also like