Machine Learning - Going Furthur with CNN Part 1
Tags: machinelearning, beginners, computerscience
Published: 2020-03-15 09:07:03

---
title: Machine Learning - Going Furthur with CNN Part 1
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,  
Another weekend right?
Lets motivate those who reading this a little bit
<i>
A man found a cocoon of butterfly. One day he noticed there is a butterfly struggled to force its body through the small opening of the cocoon. So the man decides to help the butterfly by snipping off the remaining bit of cocoon since the butterfly looked like it was stuck.
So the fly then emerged easily also it had a swollen body and small , shriveled wings. The man was waiting for the butterfly to enlarge its wings and fly.
But the fly was unable to fly and crawling around with tiny wings and swollen body.
Despite the kind heart of the man, he didn’t understand that the restricting cocoon and the struggle needed by the butterfly to get itself through the small opening; were God’s way of forcing fluid from the body of the butterfly into its wings. To prepare itself for flying once it was out of the cocoon.
</i>

Moral of the story:
<blockquote>Our struggles in life develop our strengths. Without struggles, we never grow and never get stronger, so it’s important for us to tackle challenges on our own, and not be relying on help from others </blockquote>

<blockquote> Never ever try to crack open a coccoon. Mind your own business</blockquote>

<h1>Main Content From Here</h1>
So far, we've only looked at small grayscale images such as a 28 by 28 grayscale images from the Fashion-Mnist dataset. 

![details](https://i.ibb.co/RytzV5z/2828.png)

In real applications however, we usually have to deal with high resolution color images of different sizes like the ones we see here.

![details](https://i.ibb.co/d0XNvzz/color-images.png)

 As we mentioned earlier in this lesson, we're going to create a CNN that can classify colored images of cats and dogs. To do this, we're going to use cat and dog images from Microsoft's image database. Each image in this dataset is labeled with either a one or a zero. Where a 1 indicates the image corresponds to a dog, and a 0 indicates that the image corresponds to a cat. 

![details](https://i.ibb.co/3v3sQKV/labels.png)

Even though Microsoft's  dataset contains over 3 million labeled images of cats and dogs, only 25,000 of them are publicly available. Training our CNN on this 25,000 images will take a very long time. Therefore, in order to decrease the training time, we will only use a small subset of images to train our CNNs. Our subset contains 2,000 training images and 1,000 validation images.

![details](https://i.ibb.co/3kv7qvH/cats-and-dog-dataset.png)

Out of the 2,000 training images, 1,000 of them are dog images and 1,000 of them are cat images. When working with this dataset, we will face two main challenges. <ul>
<li>Working with images of different sizes</li>
<li>Working with color images</li></ul>
So let's start by learning how to work with images of different sizes.
<br>
<br>
<h2>Working with images of different sizes</h2>

first challenge will be dealing with images of different sizes.  This is because a neural network needs a fixed size input.  As an example, 

![details](https://i.ibb.co/T0sh0xV/flattening.png)

We had to flatten  the grayscale images from  the Fashion MNIST dataset before feeding them into our neural network.  We used a flattened layer to transform the 28 by 28 grayscale images  from a 2D array to a 1D array of 784 pixels.  Since all of the images from the Fashion MNIST dataset have the same size,  they all get flattened to 1D arrays of the same size.  However, when working with images of different sizes,  flattening the images will give rise to one-dimensional arrays of different sizes.  Since neural networks need a fixed size input,  just flattening the images won't work.  When doing image classification,  we always solve this problem by resizing all the images to the same size.

![details](https://i.ibb.co/YBvjxNR/resize.png)

In this lesson, we'll choose to resize all the images in  our dogs and cats dataset to be 150 pixels in height,  and 150 pixels in width.  By resizing all images to the same size,  this will guarantee that when we flatten the images,  they'll result in 1D arrays of the same size.  

![details](https://i.ibb.co/MM9mWgL/afterflat.png)

Our second challenge will be dealing with color images which we can see in the next one. 

Adios . Muchas Gracias