Machine Learning -  Dropout
Tags: machinelearning, beginners, computerscience
Published: 2020-04-04 07:59:22

---
title: Machine Learning -  Dropout
published: true
description: Machine Learning studies
cover_image: https://i.ibb.co/gyDsXzP/0-hzqhs-KFIZNWJKhvq.jpg
tags: machinelearning, Beginners, Computer Science
series: Making Of Terminator
---
Hey there,

Let us have a beautiful story.

<i>This parable is told of a farmer who owned an old mule. The mule fell into the farmer’s well. The farmer heard the mule praying or whatever mules do when they fall into wells.

After carefully assessing the situation, the farmer sympathized with the mule, but decided that neither the mule nor the well was worth the trouble of saving. Instead, he called his neighbors together, told them what had happened, and enlisted them to help haul dirt to bury the old mule in the well and put him out of his misery.

Initially the old mule was hysterical! But as the farmer and his neighbors continued shoveling and the dirt hit his back, a thought struck him. It suddenly dawned on him that every time a shovel load of dirt landed on his back, HE WOULD SHAKE IT OFF AND STEP UP!

This he did, blow after blow. “Shake it off and step up… shake it off and step up… shake it off and step up!” He repeated to encourage himself. No matter how painful the blows, or how distressing the situation seemed, the old mule fought panic and just kept right on SHAKING IT OFF AND STEPPING UP!

It wasn’t long before the old mule, battered and exhausted, stepped triumphantly over the wall of that well! What seemed like it would bury him actually helped him … all because of the manner in which he handled his adversity.</i>


<blockquote>
THAT’S LIFE! If we face our problems and respond to them positively, and refuse to give in to panic, bitterness, or self-pity.
</blockquote>


<h1>Main Content From here</h1>

In this lesson, we'll learn about dropout, which is another technique that can also help us avoid overfitting. 
<ul>
<li>We learned that during training and neural network adjusts its weights and biases to minimize the loss function.</li>
<li>One problem that can sometimes occur during training is that one part of the network ends up with very large weights, while other parts end up with very small weights.</li></ul>

![details](https://i.ibb.co/qsPm78k/dropout1.png) 

This results in the parts having the larger weights playing a major role in the training process, while the other parts with smaller weights won't play much of a role and they don't get trained very much. 

One way to avoid this from happening, is to perform <code>dropout</code>.

![details](https://i.ibb.co/DGWmbKW/turnoff.png) 

<ul><li>Dropout consists of randomly turning off some of the neurons in the network during training.</li><li> By turning off some neurons during training, this forces the other neurons to pick up the slack and to take a more active part in the training.</li>
<li>So as we go through the epics during training, we'll randomly turn off some neurons.</li></ul>

For example, let's suppose in the first epoch we choose not to use these two neurons. 

![details](https://i.ibb.co/MBWCG47/example.png) 

So we do our feedforward and our backpropagation passes without using these neurons. The second epoc we choose not to use these three neurons. 

![details](https://i.ibb.co/7CgTkwV/ex2.png) 

Again, we do feed forward and back-propagation passes without using those neurons, and then the third epic which is not to use these two neurons. 

![details](https://i.ibb.co/rmNNfMm/ex3.png) 

Again, we do feed forward and back-propagation passes without using the neurons and so on. By training our neural network in this way, we can avoid overfitting.

<ul><li>You can say that the network becomes more resistant, because it cannot rely on all of the neurons being there to solve the problem.</li><li> Consequently, other neurons will have to step up and also be able to do the job.</li><li> In practice, we specify the probability that each neuron gets dropped at each training epic.</li><li> Notice, that since we specify a probability, some neurons may get turned off more than others and some may never get turned off at all.</li><li> However, this is not a problem, because we're doing it many many times over.</li><li> Therefore on average, each neuron will get the same chance of being turned off.</li></ul>

Other Techniques to Prevent Overfitting

In this lesson we saw three different techniques to prevent overfitting: 
<ul><li>
Early Stopping: In this method, we track the loss on the validation set during the training phase and use it to determine when to stop training such that the model is accurate but not overfitting.</li>
<li>Image Augmentation: Artificially boosting the number of images in our training set by applying random image transformations to the existing images in the training set.</li> 
<li>Dropout: Removing a random selection of a fixed number of neurons in a neural network during training. However, these are not the only techniques available to prevent overfitting. </li>
</ul>

You can read more about these and other techniques in the link below: <a href="https://hackernoon.com/memorizing-is-not-learning-6-tricks-to-prevent-overfitting-in-machine-learning-820b091dc42">Memorizing is not learning! — 6 tricks to prevent overfitting in machine learning</a> 

Summary In this lesson we learned how Convolutional Neural Networks work with color images and saw various techniques that we can use to avoid overfitting . The main key points of this lesson are: 

CNNs with RGB Images of Different Sizes: 

<ul><li>Resizing: When working with images of different sizes, you must resize all the images to the same size so that they can be fed into a CNN. </li>

<li>Color Images: Computers interpret color images as 3D arrays.</li> 

<li>RGB Image: Color image composed of 3 color channels: Red, Green, and Blue.</li>

<li> Convolutions: When working with RGB images we convolve each color channel with its own convolutional filter. Convolutions on each color channel are performed in the same way as with grayscale images, i.e. by performing element-wise multiplication of the convolutional filter (kernel) and a section of the input array. The result of each convolution is added up together with a bias value to get the convoluted output. </li>

<li>Max Pooling: When working with RGB images we perform max pooling on each color channel using the same window size and stride. Max pooling on each color channel is performed in the same way as with grayscale images, i.e. by selecting the max value in each window. </li>

<li>Validation Set: We use a validation set to check how the model is doing during the training phase. Validation sets can be used to perform Early Stopping to prevent overfitting and can also be used to help us compare different models and choose the best one. </li></ul>

Methods to Prevent Overfitting: 

<ul><li>Early Stopping: In this method, we track the loss on the validation set during the training phase and use it to determine when to stop training such that the model is accurate but not overfitting. </li>

<li>Image Augmentation: Artificially boosting the number of images in our training set by applying random image transformations to the existing images in the training set. </li>

<li>Dropout: Removing a random selection of a fixed number of neurons in a neural network during training.</li>
</ul>