Keras Core Layers

Dense

The dense layer can be defined as a densely-connected common Neural Network layer. The output = activation(dot(input, kernel) +bias) operation is executed by the Dense layer. Here an element-wise activation function is being performed by the activation, so as to pass an activation argument, a matrix of weights called kernel is built by the layer, and bias is a vector created by the layer, which is applicable only if the use_bias is True.


It is to be noted that if the input given to the layer has a rank greater than two, it will be flattened previously to its primary dot product with the kernel.


Arguments

  • units: It refers to a positive integer that acknowledges the output space dimensionality.
  • activation: It makes sure that the dense layer utilizes the element-wise activation function. It is a linear activation, which is set to none by default. Since its linearity is limited, we don't have much of its in-built activation function.
  • use_bias: It is an optional parameter, which means we may or may not incorporate it in our calculation. 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 can be defined as an initializer for the bias vector for which Keras uses zero initializer by default. It is assumed that it sets the bias vector to all zeros.
  • kernel_regularizer: It can be termed as a regularizer function, which is implemented on the kernel weights matrix.
  • bias_regularizer: It can be defined as a regularizer function, which is applied to the bias vector.
  • activity_regualrizer: It relates to a regularizer function that is applied to the output of the layer (its activation).
  • kernel_constraint: It refers to the constraint, which is applied to the kernel weights matrix.
  • bias_constraint: It can be defined as a constraint, which is applied to the bias vector.

Input shape

The input shape layer accepts an nD tensor of shape (batch_size, …, input_dim), and makes sure that its most common situation would have to be a 2D input encompassing a shape of (batch_size, input_dim).


Output shape

It outputs an nD tensor of shape (batch_size, …, units). For instance, where input is a 2D of shape (batch_size, input_dim), the corresponding output will be of shape (batch_size, units).


Activation

keras.layers.Activation(activation)
This is the layer that implements an activation function on the output.

Arguments

o activation: Basically, it refers to the name of an activation function to be used, or simply we can say a Theano or TensorFlow operation.

Input Shape

It comprises of an arbitrary input shape. It makes use of an argument called input_shape while using it as an initial layer in the model. The input_shape can be defined as a tuple of integers that does not include the samples axis.

Output Shape

The output shape is the same as that of the input shape.


Dropout

keras.layers.Dropout(rate, noise_shape=None, seed=None)
The dropout is applied to the input as it prevents overfitting by randomly setting units of a fraction rate to 0 during the training time at each update.

Arguments

o rate: It refers to a float value between 0 and 1, which represents the fraction units to be dropped.

o noise_shape: It refers to a one-dimension tensor integer that epitomizes the shape of a binary dropout mask, which will be used in its multiplication with the input. If the input shape is (batch_size, timesteps, features), and for all timesteps, you wish your dropout mask to be similar, then, in that case, noise_shape=(batch_size, 1, feature) can be utilized.

o seed: It indicates a python integer that will be used as a random seed.


Flatten

keras.layers.Flatten(data_format=None)
The flatten layer is used for flattening the input by not affecting the batch size.

Arguments

o data_format: It can be defined as a string one of channels_last (by default) or channels_first. It is mainly used for ordering the input dimensions, so as to preserve ordering of weight when a model is being switched from one data format to another. Here the channels_last. relates to the input shape of (batch, …, channels), whereas the channels_first relates to the input shape of (batch, channels, …). By default, the image_data_format value found in Keras config file is residing at ~/.keras/keras.json, else if it has not been set, then it will be at "channels_last".



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 Previous