Machine Learning - Going Furthur with CNN Part 2
Tags: machinelearning, beginners, computerscience
Published: 2020-03-17 15:55:28

---
title: Machine Learning - Going Furthur with CNN Part 2
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's continue without furthur ado.

In order to understand how CNN's work with color images,  we need to dive a little deeper into how CNN's work.  So let's start by taking a quick recap. 

![details](https://i.ibb.co/G9ttTrr/previous.png)

We saw in one of our previous lessons that computer  interpret gray scale images as 2D arrays.  This 2D arrays contain  the corresponding pixel values of the gray scale images.  The width and height of  the 2D array will be determined by the size of the image.  For example, let's assume for simplicity that  this gray scale image is 6 pixels in width and 6 pixels in height.  Therefore, the corresponding 2D array will also  be 6 pixels in width and 6 pixels in height.  In a similar manner,  computers interpret color images as 3D arrays.

![details](https://i.ibb.co/M8q6wKz/coloimage1.png)

The width and height of the 3D array  will be determined by the height and width of the image,  and the depth will be determined by the number of color channels.  Most color images can be represented by three color channels namely red, green and blue. 

![details](https://i.ibb.co/HgnybWG/rgb.png)

Images that contain red,  green and blue color channels are known as RGB images.  Altogether, these three channels combine to create a single color image.  In RGB images, each color channel is represented by its own 2D array. 

![details](https://i.ibb.co/yyDtW47/own2d.png)

Since we have three color channels,  we end up with 3 2D arrays.  Therefore, in the case of RGB images,  the depth of the 3D array is just the stack  of these three 2D arrays corresponding to the red,  green and blue color channels.

![details](https://i.ibb.co/hWdkRpd/last.png)

So in this particular example,  where we have a five by five RGB image,  the corresponding 3D array will be five pixels in height,  five pixels in width and we'll have a depth of three







Now, since our input image is going to be 3D,  we have to modify our code accordingly.  
If we look at the code we used using in our previous lesson,  we had an input shape of 28 by 28 by 1.
 
![details](https://i.ibb.co/kq7Vm6g/civ2.png)

<ul>
<li>The first two numbers in the input shape  parameter refer to the height and width of the input image.  In the Fashion MNIST dataset,  the images were 28 pixels high,  and 28 pixels wide.</li>
<li>So the first two numbers are 28 and 28.  The third number in the input shape parameter refers to the number of color channels.</li>
<li>In the Fashion MNIST dataset,  the images were grayscale which means they only have one color channel.  Consequently, the last number here is a 1.  But now, our dogs and cats dataset contains RGB images of different sizes.</li>
</ul>

![details](https://i.ibb.co/gRn6vMm/civ3.png)

<ul>
<li>As mentioned earlier, we will resize all our images to be 150 pixels in height,  and 150 pixels in width.  Therefore, the first two numbers in the input shape parameter will now be 150 and 150.</li>
<li>Since our images now are RGB,  that means they have three color channels,  which means we have to change the last number in the input shape parameter to three.</li></ul>  
In the next post, we will learn how to perform convolutions on RGB images.