 So in this video let's have a quick look at an example of a convolutional neural network. So we've discussed some of the types of layers that go inside of a convolutional neural network and what the idea is behind this convolutional operation and that we're really talking about images here. Images really work well when we talk about convolutional neural networks. So we're going to use one of the datasets that is available right inside of QRS and that's the MNIST dataset. I'm quite sure you've heard of that. That's just tiny little images of handwritten digits. They're all in monochrome, in other words black and white, and they're all labeled. So someone wrote an 8 and a 7 and a 6, I suppose, all sorts of people and those were just labeled by human beings as such. So let's import that and we're just going to assign that to a computer variable called MNIST and what we are loading is this dataset underscore MNIST and that dataset already has, it's already been divided into a training and test set, so with these built in datasets we don't have to worry too much about that. So all we have to do is just assign four computer variables and as usual I'm going to call mine X underscore train, Y underscore train, X underscore test, Y underscore test and we see there that it's MNIST and then as always with our little dollar sign that's shift of four on my keyboard and then train because the training set and then the feature which is actually images X and then it's the labels Y. So we're going to do that both for the training and the test set. So if we look at the dimensions just of X train we notice 60,000, 2828, so what does this mean? Certainly this is something larger than we've seen before. In other words we usually just had the feature variable and there were say 70 rows or 10,000 rows comma so many columns and the columns those were the number of features. But this indicates that we have 60,000 samples of 28 by 28 and that is what these images look like, they're little grayscale images, they're 28 pixels by 28 pixels so tiny little squares and then each value is just between 0 and 255 as we saw before and that's just the brightness value. So let's record those as just as computer variables I'm going to call it image underscore IMG underscore rows and IMG underscore columns that's just the pixel dimension because what we need to do we need to reshape this as a tensor in a format that our model is going to expect because what is missing from this 60,000, 2828 is the number of channels. So we have to add that. So let's use the array underscore reshape function so it takes extrane as our argument and then we have to pass in the number of rows in extrane so we use C function and then the in row function of extrane then image rows, image columns comma one. So we add that comma one at the end just to show that there's one channel and we're going to do exactly the same for, we're going to do exactly the same for the test set there and then we're just going to store input shape because as we pass our first layer or our first data into this model we just need to know the input shape and the input shape is going to be 28 by 28 by 1. That is the size of the images and comma one there's one channel and this is the way it is set up if you use other frameworks some of them might use the one or the number of channels first and then the row and column size but here inside of KRS using tensor flow back end it is image width, image height basically comma one or comma three in case it was a color image with three channels. If we now look at the dimensions of extrane we know that it's 60,000, 2828, 1. Next up we have to of course we have to normalize our data sets and because each value that's just between zero and 255 we can just divide by the maximum which is 255 so that's going to bring everything in this zero to one range for us nicely. I'm going to create a computer variable called numclasses is 10 because I'm going to use the two underscore categorical to do the one hot encoding remember they're 10 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and we, so they're 10 classes and the way that we use two categorical as we're going to pass the variable there that contains our labels white train and white test comma the number of classes in this instance they're 10 so that if we have a look at this first example in the training set its label was and it starts getting coming from zero so 0, 1, 2, 3, 4, 5 so one hot encoding for the first little image being a 5. So let's create our model and as always it's just going to be a sequential model so we pass we're going to create a computer variable called model it's going to be a Keras underscore model underscore sequential we're going to pass a two dimensional convolutional layer next 2D because we have it is a 2D image it has two dimensions in other words it has a height and width and height and we're going to do 16 filters of 3 by 3 each so we have these nine values that are going to pass over our 28 by 28 but we have 16 of them so you can imagine we're going to run through it once and we're going to have a slightly smaller image our resultant image that we spoke about before but we're going to stack 16 of them behind each other if you want to visualize that we're still going to use an activation function the rectified linear unit and now we put that input shape in the vase which was 28 by 28 by 1 next up is going to be a max pooling layer so that's going to take a little 2 by 2 blocks and it's just going to take the maximum value out of that then we're going to have some dropout we can have dropout layers here as well and we're going to drop a quarter of of the values and then we're going to flatten so that 28 by 28 this is going to be flattened in the 756 just single vector because we have to pass this to a to a multi-layer perceptron a densely connected neural network and the end so our first dense layer there is just going to have 10 units or the activation function is always real you we're going to have a 50% dropout and then another dense layer which is going to be just 10 units because that is what we want our output we have the number of classes is 10 and the activation they remember softmax and if we run the summary on that we note that we have 27,320 learnable parameters and that is really not bad if we consider the size of our input vector 28 times 28 now this is a I'm going to say straight up this is a horrible model this is not going to do probably not going to do very well and definitely add a second convolutional layer there maybe add the number of the number of filters there or the kernels and then certainly have more than 10 units of my first dense layer there if you really want to do some good accuracy but this is just to demonstrate the different layers that we have spoken about compiling that we're going to always have the loss the categorical cross entropy the optimizer I chose here just for argument's sake is the delta optimizer and the metric is going to be accuracy we'll make a batch size of 128 and we'll run through 12 epochs and then pass the fit function pass the model to the fit function and have a validation split of 0.2 so if you download this actual code you can run that and you have a look on our studio what the outcome is going to be and then all I did at the end was just to create a score computer available here we pass the model to the evaluate function and we pass x test and y test and we concatenate this the test loss and the score dollar loss so that's one of the values that is inside of the score and we see a test loss of 0.18 and we see a test accuracy of about 96.45% so encourage you to download this file or create your own create your own convolutional neural network as you can see it really isn't that easy and start start your first look at some other convolutional neural network using the inbuilt using the inbuilt image data sets in future I'm going to show you how you can use your own images if they do live on your internal drive how you can use them to pass it to because that's quite a bit different than just using these these inbuilt images now there are lots of other image data sets available as well CIFAR 10 that it does images of 10 classes CIFAR 100 these things are all built into kerosene I urge you to explore those