Key Functions

In this lesson, we will discuss some of the key functions that we will be using throughout the course.

Key functions

Below are the key function froms keras, which will be used throughout the course.

Dense()

This function will be used to create our regular densely-connected neural network layer. There are many parameters accepted by this function, but we will mainly use the parameters below:

  • units - the number of neurons (nodes) in a layer. In other words, the dimensionality of output space.
  • activation - the type of activation function for this layer. We will discuss the types of activation functions last.

Dropout()

The dropout layer randomly sets the neurons or nodes of a layer to 0 with a frequency of the rate at each step during training time, which helps prevent overfitting. We pass the value of rate as a parameter, i.e., how many neurons in a layer we want to be set to 0.

Flatten()

This function is used to convert the shape of the data to a single column vector. For example, after passing the input to the dropout layer, we get a shape of (1, 10, 64) then, after applying the flattening we get the shape as (640,).

Conv2D()

This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs. In other words, this function is used to perform the convolution operation on the data. There are many parameters accepted by this function but we will mainly use the following parameters:

  • filters - the number of filters we need or the number of feature maps we want after performing the convolution step.
  • kernel_size - the size of the filter. In the project below, we will see what type of values we should give for better performance.
  • activation - the type of activation function for this layer. We will discuss the types of activation functions last.
  • input_shape - the shape of the input that our model will expect. When we use the layer as the first layer in a model, we need to provide the keyword argument input_shape at that time only. For colored images, we will pass a tuple of three values (three dimensions) because colored images have three color channels.

MaxPooling2D()

This function performs the max pooling operation. There are many parameters accepted by this function, but we will mainly use the following parameter:

  • pool_size - the window size over which to take the maximum. If we pass (2, 2) as the value for this parameter, then we will take the max value over a 2 x 2 pooling window.

Get hands-on with 1200+ tech skills courses.