TensorFlow 2.0 Tutorial for Beginners | Deep Learning with TensorFlow 2.0 | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everyone this is junit here from eduraka and i welcome you all to this session in which i'm gonna talk about tensorflow 2.0 so without any further delay let's take a look at today's agenda we'll start off this session by understanding why and what is tensorflow then i shall walk you through tensorboard and how to install tensorflow on your system following that we shall see the basics of tensorflow and how it can be implemented in deep learning finally we'll end this session by looking at the real world examples or the use cases of tensorflow in the market before we begin do consider subscribing to our channel and hit the bell icon to stay updated on trending technologies and also if you're looking for online trading certification in tensorflow check out the link given in the description box below so to start off let us now see why do we need tensorflow you see tensorflow is actually an open source machine learning framework to carry out high performance numeric computing it provides excellent architecture support which allows easy development of computations across a variety of platform ranging from desktop to clusters of servers mobiles and edge devices now you might be wondering why tensorflow and how it becomes so popular in such a short span of time right and what makes tensorflow so special that we see a huge surge of developers and researchers opting for tensorflow framework well you see when it comes to artificial intelligence framework showdown you will find tensorflow emerges as a clear winner most of the time the majority of credit goes to soaring popularity and contribution across various forms such as github stack overflow and quora the fact is tensorflow is being used over 600 open source repository showing its roots in many real-world research projects and applications and coming to the features that i would like to mention is that tensorflow is supported for different languages this allows developers to integrate tensorflow in unique way as we know tensorflow was developed by google which itself makes it a state of the art but a point to be noted is that it has well written and easy to understand documentation even for the beginners most of the tech giants like google coca-cola instagram and general electrics and many more use tensorflow in their deep learning and machine learning model thus making it an industry standard and hence must have skill for a relevant job role so now what is tensorflow well tensorflow is an open source end-to-end platform for creating machine learning applications it is a systematic math library that uses data flow and differentiable programming to perform various tasks focus on training and interface for deep neural network it allows developers to create machine learning applications using various tools libraries and community resources as mentioned earlier currently the most famous deep learning library in the world is google's tensorflow google makes sure to use this tensorflow in its machine learning product in order to enhance those use for example it uses tensorflow in search engine translation image captioning or even recommendation engine to give you a concrete example google users experience a faster and more refined search with ai if the users typed a keyword in a search bar google provides a recommendation about what the next word could be unlike other framework i would like to say tensorflow as an ecosystem and the building blocks of tensorflow ecosystem is nothing but a tensor so now you might be wondering what's a tensor right well you see tensor is nothing but a multi-dimensional array tensor can have a shape and a data type but do not have actual values and honestly speaking tensorflow over here makes use of this shape even though the value is scalar that is nothing but you know if you have a value like 22 it is also represented as one cross one array no matter be it a single dimension array or a n-dimension array everything over here is referred to as a tensor now you might be wondering hey junaid you said tensorflow is an ecosystem so how does it work well you see the way tensorflow works is on something called as computation graph so what is this computation graph right computation graph is defined as directed graph where nodes corresponds to a mathematical equation computational graphs are the ways of expressing and evaluating mathematical equation so let me now quickly move to my canvas and show you how computational graph works to give you a better example of what is computational graph let me just quickly take an equation over here let's say this equation over here represents p is equal to x plus y so this is basically a simple mathematical equation so now how would i put this in a computational graph so as i mentioned earlier over here the node represents an operation so this part over here is referred to as node and the operation which this is going to represent is positive or plus or the addition operation so the inputs for this is going to be x and y and then we have an output over here p which is nothing but p is equal to x plus y so this is what a computation graph represents so to give you a better understanding of why we use computational graph that's because of something called as forward propagation and a backward propagation so to understand this let me take up a bit complex equation let's say we have something like g is equal to then we have let's say we have an operation here x plus y and then this would be product times z so if i have to put this in a computational graph first off we'll have this node right so let's go by board mass rule so it'll be brackets so obviously we'll put the brackets over here and operation within this is positive or plus and then we'll give this as x and y and the output of this is p and this p over here represents x plus y and now we have to add another node right that's because we have a multiplication to be done here so let me add one more node over here which would represents product of two numbers and i would just pass an arrow and one more input that's nothing but z this is going to be g right and this output over here represents p times z right so let me quickly erase this so this is going to be p times z or i can just write as p z right so i'm pretty sure this is something which is crystal clear to all and the output if i give over here this is going to be p times z and here p represents x plus y so let me quickly write that as well x plus y times z whatever we did now is refer to as forward propagation and what happens in the forward propagation is we are trying to find the value of g but when we are dealing with deep neural network as i have mentioned earlier we use tensorflow to create or to work with neural networks or deep learning and we all know deep learning is completely based on neural networks or i can also say it as it is inspired by artificial neural networks so now what i'm going to do over here is the other most important thing when it comes to deep learning is something called as updating the value of weights so how do you update the value of weights it's obviously by back propagation and the way back propagation works is by taking a partial derivative so to give you a better understanding let me just take this particular example here let me quickly erase the rest of the stuff so let us now take or assign the value for our x y and z let's say x over here represents a value x is equal to 5 and at the same time we have y is equal to 10 and let's take the value of z over here as let's take it as one okay let's take it as like two right so one like product times one is nothing but the same number so just to differentiate let's give us two so now if i'm trying to move this towards forward propagation what's going to happen is i'm supposed to find like it would follow the same map so now the value of x over here would be 5 y here would be 10 and z over here would be 2. so this is the initial value so now let's see what happens in the forward propagation so now x and y get added up so this would be 15 and this would be represented over here as 15. and now as you can see here we are supposed to perform the product so this is nothing but product between p and z 15 times 2 is what 30 right and so finally the value of g over here is nothing but 30. let me now show you what back propagation is with back propagation what's going to happen is we are going to change or we are going to update the value of these x y and z if you don't believe me let me quickly show you how that works so first off what we'll do is we're going to take the differentiation so this is going to be like a partial derivative so first off we're going to start over here we're going to start over here by saying it as delta g by delta g which is nothing but what do you say what do you think delta g by delta g this is nothing but one and then finally coming down over here we have to take partial derivative with respect to this so let me quickly show you so partial derivative of this with respect to p and with respect to z so let's take this let me quickly write this down here so first off we take partial derivative of g g and this should be one and next we have pz we are moving in a backward direction so obviously we will be moving from right to the left so let me quickly do partial derivative over here in a stage two we'll have pz so pz partial derivative of this by with respect to p which is nothing but z and the value of z is what 2 and then similarly we are going to do partial derivative of p z by z so partial derivative of this i hope you know what is derivation so obviously this would end up being p and the value of p over here is 30. so the value of p over here what did we get it's 30 so this is gonna be 30 here so where does this value 30 represents this is the place where i'm performing the partial derivative so if you have confusions from where am i getting this it's going to be here i'm going to perform partial derivative over here so this is going to be pz by partial derivative with respect to z so this is going to be p the value over here is going to be 30. i hope this is pretty much clear and similarly if i perform partial derivative here so it's going to be p z by dou p and this would give me z and the value over here is going to be somewhere around 2 because that's the value of a z so finally we are supposed to come back to our third stage that is nothing but the third layer so in the third layer we have x and y so the way this is going to be is something like we have dou g by dou x and dou g by dou y because we are trying to perform the partial derivative of g so the way this is going to look like is dou g by dou x first we'll do it for x and then we'll go on for y and the way this would look like is you know i'm supposed to perform something called as chain rule because now g x is not directly related to g if you can see here the x part is not directly related to g so let me quickly take another color and show you so if you can see here x is not directly related to g x is related with g we have p and the same thing goes with y so this is why we'll be performing chain rule over here and the way chain rule works is this is something going to be something like this so this doe g would remain the same and then as it's via p right so it's going to be dou p times is going to be dou x by dou x so let me quickly erase this and write it properly so this is going to be dou p by dou x similarly let's do it for y so if it is dou g by dou y this is going to be dou g by dou p times dou p by dou y so let's see what does this represents so we know what is dou g by dou p so doe g by dou p over here so now what's going to happen over here is i hope you understand why we have using this part over here so let me just quickly highlight this and this part over here and this part over here and this part over here this is nothing but part of a chain rule because these people are dependent upon p x and y are dependent upon p in order to be related to g let's quickly see what happens let me take another color here so as p and x have a direct relationship what's gonna happen is this p x going to be replaced by 1 and the same thing goes over here we already know the value of dou g by dou p i'm pretty sure you might be wondering where did we calculate this on the graph over here well if you look close this pz over here is nothing but g this p z over here is nothing but g because after computation we are getting this and p here refers to x comma y so what i'm trying to say here is p so this p z so now what's going to happen is we will try to form now delta g by delta p and what is the value of this so if you remember this what would be the value of dou g by dou p we can refer to this part over here because this is represent the same thing so this is nothing but dou g by dou p which is nothing but z which in turn is 2. let me quickly erase this z just to avoid the confusion so this is how we get dou g by dou p and the value of this is 2 so let me quickly fix that so this is going to be 2 and the same thing over here and this is going to be 2 times 1 same thing over here 2 times 1 and now this is going to be 2 and 2. so what change did we see here first off let's see what is the initial values so initial value over here is nothing but 5 10 and 2. so these were the initial values so what are the new values over here that we have well if you can see close they all have updated the value of z now is nothing but 30 and the value of x and y has changed from 5 to all the way down to 2. so let me quickly update that and y is equal to two and this is exactly how back propagation work and this is how the weights get updated when we are trying to perform artificial neural network or you know when you try to perform back propagation during any of the deep learning process i hope now you understood why you're using this computational graph so now that you know what is tensorflow and why we need it let me quickly show you a tool or i can also say it as a fun past time to understand how neural network works and there is something which is written in javascript and this is called as tensorflow playground so what is this tensorflow playground well you see tensorflow playground is an interactive visualization of neural networks written in a thai script using d3 javascript it contains a tiny neural network library that meets the demand of educational visualization you can simulate real time in your browser with small neural network and see the results instantaneously so let me quickly move to my browser and show you how this tensorflow playground looks like well as you can see here we have some kind of interface or you can say some kind of table over here which represents something over here well let me quickly show you how and what would this look like so over here this x1 and x2 these are nothing but the inputs and these are nothing but the neurons and this is nothing but the output neuron let's say we're trying to perform a classification task here classification if you know it's nothing but you know whether it's yes or no we have two outputs either it's there or it's not there so we are going to pass some learning rate you can give any value it will be like this thing and then activation you can use any of these i'll be using relu and then we can also use regularization but as of now it's not needed then yeah learning rate and then we can perform we have a couple of options here we can perform classification or regression task so if i am taking this regression task let me quickly execute this so you will see here that a beautiful line is being drawn over here and this part over here represents one cluster and this part over here represents the other cluster so let me quickly increase this neuron and let me add a couple of layers you know i'm just randomly using this i'm just randomly trying to play around over here so let me see let's increase some noise and also have some batch size increased and the ratio of training to test data let me keep it somewhere like this and let me execute this now so as you can see here we have some kind of regression task which has been happening and this is going to run but the important thing over here to consider is the way it is classifying over here so there is a thin border line which is being performed and this part over here represents one thing and the other one over here so now that you know what is tensorboard and you know how neural network works from within we have also seen the visualization so now let us get started off with installation of tensorflow so installation of tensorflow is pretty simple all you need to do is you know open up your anaconda virtual environment and install tensorflow there so let me quickly show you how that works so over here i'm here down to my anaconda prompt so what i'm gonna do is let me activate my environment or we can also create our environment so i've already created it so let me activate it so it's gonna be conda activate tensorflow so in order to install tensorflow you have to just perform a simple step that is nothing but type pip install tensorflow so once you hit this just hit enter so you'll see that you know it would take some time to install tensorflow package on your system all right guys as you can see here we have successfully installed tensorflow 2.0 so in order to see whether we have installed it or not let me open up a python shell here so for that python and let me quickly import tensorflow the reason why i'm getting this error is because i don't have gpu installed but tensorflow is working when it comes to the cpu version of it so this is exactly how this would work but you know most of the time what happens is people don't have a high-end laptop in order to train a deep learning model or in order to use tensorflow on your system you're supposed to use something like a high-end gpu which can be a bit expensive because you cannot run tensorflow gpu on any graphic cards so in order to overcome this what i'm gonna do is we're gonna mostly work on google collab so now that we have installed tensorflow on a system but as i mentioned earlier we won't be using our inbuilt id or our system id in order to run or in order to use tensorflow we will be using something called as google collab which is nothing but a jupiter notebook like system which is provided by google so let me quickly jump to my code editor that is google collab and show you the basics of tensorflow so the first thing that we are going to do over here is we are going to import tensorflow so to do that we all we need to do is import tensorflow as tf and then we'll execute it so to execute this i'll be clicking shift enter so if you remember some time back i told you this tensorflow i consider it to be an ecosystem so now you'll understand why i call it an ecosystem see usually when i try to perform like when i give a variable so it's going to be something like 5 and then i have another variable over here this is going to be like 10 and finally let's say if i want to perform this operation it's going to be c is equal to a plus b and i get an output over here which is nothing but it's going to be 15. so this is how convention weight works but this is not the case in tensorflow so the way it works in tensorflow is if you want to have a constant or variable you're supposed to define it so it's going to be tf so this is nothing but a constant so constant or i can also set as variable and now what we're going to do is we're going to pass the value so the value that i'm going to pass over here let's say it has 5 and we're also supposed to give a data type so this is nothing but we have d type and we can use it as tf dot int that i do so similarly what i can do is let me copy this let me have something down for v here and let's give the value over here as 10 and let me quickly execute this part so now as you can see here so now if i want to perform addition over here what i'm going to do is i'm going to have c which is nothing but a variable so for this it would be tf which stands for tensorflow.add a comma b so now if i see this you will see that we will get a value over here which is a numpy and it gives 15. similarly let me see if i can create an array here so we have this array and within this let's take some random values so let it be like 3 comma 3 comma 4 some random values it has no order here and similarly let's create an array here let's give it as nine comma eight comma seven and now let me execute this so the output over here is going to be an array wherein it's going to be 12 12 and 13 and the shape it also gives us the shape of an array now if you want to convert this into numpy all you need to do is dot numpy and just give it a function so you will see that we get this in the form of an empty array this is the very basics of how and what is tensorflow we are trying to assign a variable here and now another thing that tensorflow also provides us is with conditional statement as well as the if loop or for loop so let me quickly show you how an if condition would look like or let me give it as conditional statements so what is this conditional statement conditional statement is nothing like if a is equal to 5 and b is equal to 10 and now usually what i would be doing is if a is greater than b then print a and then i also have else condition else print b so now whichever is higher i get that value so let me put 15 here so we will see the value now changes to 15. similarly we can perform the same kind of operations using our tensorflow so let me take an example of a itself so first of all what we're going to do is we're going to have a constant so tf dot constant and now what i'm going to do is let's take some constant value like 10 and then we'll have b is equal to tf dot constant let's say 20. so in general what we will be doing is we'll put if a greater than b or less than b so it's that's not how it works here the way it's going to work over here is first of all we'll have a variable and in order to perform any comparison or any condition we have this built-in function called as condition so it's t f dot condition c o n d and now within this condition it takes up three parameters the first parameter is going to be the condition so for that what we can do is we can perform any operator we have greater than equal to greater than equal to less than equal to not equal to so similarly we can have tf dot various kind of operations such as like greater than less than so let's take less you can see here we have less than equal to greater than equal to so and this is a function again and what this is going to take is this is going to take a and b i hope you understand this and now it's going to take another parameter and what we are going to pass over here is nothing but the function we haven't created this function yet let's say we have functions f1 and f2 so now the way i want this condition statement to be is like if a is greater print a if b is greater print b so in short what i would say is if a is greater than b print f1 else print f2 or over here it's going to be if a is less than b print f1 else print f2 so this f1 f2 over here is nothing but the function we cannot just pass the values so in order to do that all we need to do is we need to define a function so df f1 as is the function this has to return tf dot constant a and similarly we are going to do it for function f2 so let me just copy this and print it down here so let me execute this so now we have a and b as you can see a is obviously less than b so it's gonna print a so let's see what it gets so we have r dot numpy and let's execute this you can see here we have 10. now if i change the value of 10 over here to 100 we are going to get the output here as 20 because it's going to be 20. so this is how we can perform if condition or conditional operation similarly we can also perform our looping statements here so let me quickly show you how that works so first off what we're going to do is we want something like you know an array wherein we want to print numbers like from one two three four five to ten so first off unlike the normal way wherein we can append to the list what we're gonna do is first off we are gonna create an array i hope you understand what is an array array is nothing but it's a fixed size and we cannot change it so it's gonna be tf dot variable this will have nothing but zeros so let me quickly import my numpy so it'd be np import numpy as np and now what's going to happen is we need 0 so i'll just use np dot zeros and i need like 10 whose integer or data type is nothing but np dot in 32 so this is one numpy array and let me execute this here so now what i'm going to do is i'm going to create a function so def run and let me just give here so i'll have i so this is tf dot constant because we obviously need like some value to close our while so obviously this i will start from zero and the data type of this i is going to be in so d type is nothing but tf dot in 32 so now let's see we have while loop tf as i mentioned earlier in order to perform any operations we have a lot of built-in libraries so if you want less than greater than all you do is tf dot less or less than equal to whichever suits you and then we'll give a number here less than or equal to 10 but obviously this value has to be compared so we'll give here as i as long as i is less than and equal to 10 it will continue to run so now what i'm going to do is we have this result of i so this is i is nothing but the index and then we'll assign this value and the value that i'm going to assign is nothing but the value i and now what i'm gonna do is we obviously have to increase the index value so as this is the constant it will not change so i plus equal to one so now let us call our function here so to call a function we'll have run and this would return as a while though so let me quickly execute this so we are getting this error it says index 10 of dimension 10 out of bound it should be pretty simple let's see where we are going wrong the reason why we are going wrong over here is because we have defined here as 10 but it should be 11 or we can just change it to less than and not equal to so it would work properly fine but it's okay we changed it there so now let's print out this result so what i'm expecting is initially the result was nothing but zero zero zero like eleven zeros and now we'll be having zeros something like zero to eleven or zero to ten okay let me quickly run this from the start okay so let me just enter here all right so now what we are expecting here is when we had this result it was nothing but like 11 0's but now as we have inserted the value of i and also incremented it so what i'm expecting here is it's going to be like 0 to 10 so let's print this so let's print our result so result if i just print out result we will get this in the form of a tensorflow we can still see it it's an mprint so we have it from all the way from 0 to 10 but now if you by any chance if you want this in numpy array so all you can do is numpy and then this would give you an ampere here these were the very basics or i should say tip of the iceberg when you're dealing with tensorflow it's very simple you can always refer to the documentation of tensorflow to get a better or best understanding of how it works so moving ahead let us now see how we can implement tensorflow in a simple artificial neural network so what i'm going to do over here is i'm going to use a built-in data set which is called as fashion amnesty and what i'm going to do is we're going to perform a classification task and we're going to use tensorflow for it so let me quickly jump to my code editor and show you how we can implement that so same as before i'm going to use google collab here let me quickly delete all of our tabs so to start off let's import couple of libraries first off would need numpy then let's have something like matplotlib and then we obviously need tensorflow and then we need our data set so in order to get our data set what i'm going to do is import tensorflow dot keras dot data set so it's going to be from tensorflow.keras.dataset so let me quickly change this here or else you're supposed to write entire long sentence so i don't want to do that so import fashion mnist okay so let me execute this it has executed successfully so now let us load our data set so for this it's going to be fashion amnest dot load before i load our data set let me quickly show you what this contains it has images of 28 chroma 28 size and then it has this 60 000 images and the different classes that we have over here is t-shirt pullover hoodies and the labels given to them or i should say key value pair of this is nothing but a list from zero to nine and what this would return us is list of tuples so which should contain xtrain and validation data so let me quickly paste this over here so now we have loaded our data let me quickly execute this perfect so we have loaded our data and whatever it is and now what we're going to do is we obviously before feeding this into our deep learning model we obviously have to pre-process our data so let me give here as preprocessing to pre-process my data what i'm going to do is i'm going to write a function here let me give the name here itself as preprocessing this will take up arguments like x and y and now what x is going to be is nothing but we are going to convert this into tensorflow so tf dot cast so what we want to convert we want to convert x obviously and then we want to convert or up cast this to float so it's going to be tf dot float 32 bit and as we all know we want to normalize our data so to do that all i'm going to do is i'm going to divide it by 255 and similarly what i'm going to do for y is i'm going to convert this into integer so it will be tf dot cast and we want the y value and this i will be converting into our integer so in 64. and what this would return over here is x comma y similarly what i'm going to do is we have to like pre-process this even more so i'll create one more function def create data set and what this is going to take is xs i'll explain you what is xs in a while ys and then number of classes so by default it's going to be 10 because as you can see we have 10 number of individual classes and here ys this is gonna be tf dot once so what i'm trying to do now here is i'm gonna convert my y into a one hot vector so let me convert that to one hot vector so one hot and obviously i'm going to pass my y here and the depth this is nothing but n classes if you know how one hot vector works you will understand why we need the depth so it will be n classes perfect so what this is going to return is this is going to return as a data set return tf.data so i don't want the entire data to be in the form of an array i want to slice it up so to slice the data what's going to happen is data set dot from tensor slices and what i'm going to pass over here is xs comma ys so let me execute this part here so as i move here now what i'm going to do is we'll create our training data set here training data so training data over here is going to be a create data set and i'm going to pass here as x test and white test so x train and then we'll have y train similarly we want to do it for our validation data so validation data so this is nothing but create data set so x val or this is going to be x test and then white test so let me execute this so we are not having any error so now what we are going to do is we are going to create a model so we are going to use sequential model so for this all i'm going to do is i'm going to import our keras library so first off let me have from tensorflow dot keras dot models import let me see what are the models that i need first off as i'm gonna use sequential so it's just gonna be one so sequential we also need the layers so from tensorflow.keras dot layers so what i'm gonna import now is i need a reshape layer and a dense layer so import reshape and then add dense layer so let me execute this now perfect so now what's going to happen is we're going to create a model so this is going to be model is equal to keras or dot sequential so we have already imported sequential it's going to be sequential and now we are going to add the different list of layers so now we are going to add different set of deep neural layers so first of all we have keras dot reshape so we are going to do the reshape here so the target shape over here is going to be 28 comma 28. so it's not going to be 28.28 it's 28 times 28 so it's 28 times 28 comma so whatever the value is there and then the input shape over here so we all know that 28 comma 28 is the size of our image so it's going to be 28 comma 28 comma whatever the number of images are so i would like to give here as one because we are going to take one image at a time finally we are going to add the layers so keras dense layers so it's going to be dense so what i'm going to do here is units so number of densely you want so let me give here as 36 and activation the activation i'm going to use is relu similarly let's create a couple more so all we need to do is we'll copy this here and let me just give some increments here so instead of 36 let it be 64. and finally we have let's give it here as 128 and finally in our output layer we'll have just 10 because we have 10 number of classes and the activation that i'm going to use is softmax so let me execute this fantastic so we are not getting any error here so let me also show you model.compile so model.compile so now what we're going to do is we're going to see model.summary so it's going to be model.summary and let me execute this over here so here as you can see right we have couple of layers so first off we'll be having 728 and then 36 64 128 and then finally we have 10 the reason we have 10 is because the total number of classes we have is 10. so let's now compile our code so to do that we'll have model dot compile and now what couple of parameters that i would pass here is optimizer so the optimizer that i'm gonna use is adam and then we obviously have to use the loss over here so loss so what i'm going to do is tf dot losses dot categorical cross interval so the loss i'm using here is categorical cross entropy so this is going to be true so the finally we need to pass the metrics so let's give the matrix here so the matrix over here we need the accuracy so let me give it as acc so let me execute this now finally what you're going to do is you're going to train a model so to train our model we use model.fit but what i'm going to do is you know this returns as the history so we'll give here his and then we'll do model.fit so what we're going to do is we're going to now pass our data set we have our training data set so we'll pass that so let me quickly put this here in place let's see what are the different parameters this take let me quickly run this again so this takes couple of parameters if you want to execute this so as you can see how it takes x y and batch size and all so let me quickly show you that so what i'm going to do is so this is going to be our data set here and then we have to pass the number of epochs so epochs so we'll give it as like 10 and then steps per epochs so even this will give us 500 because the data set is pretty huge let me quickly close this here we obviously need the validation split so let me give here as validation split 0.2 and then finally let me give here as valid this should be fine so before we execute there's a small correction that i would like to make this validation split over here doesn't hold good for this particular model instead of validation split what i'm going to do is i'm going to pass the validation data itself so let me quickly do some changes over here so let me bring this down just to give a better appearance and now what i'm going to do is i'm going to pass validation data so this would be validation this would be nothing but validator where data dot repeat and then finally we also have to give validation steps so validation so this would be two so let me quickly execute this or train our model here let's see how it looks like so let me scroll down a bit so yeah so as you can see here we have successfully trained our model and we are getting this validation accuracy over here as 86 percent which is pretty good so now what we're going to do is rather than performing getting our predictions now let's see how our validation data or let's graph these values over here so we'll get this by his dot history so let's give a variable here which says something like h is equal to history and now this is nothing but a dictionary so let's see the key values over here so we are not getting these key values let me see what's wrong over here the reason why i'm getting this error is because it's supposed to be keys and not key so these are nothing but the key value pairs and each of these values is nothing but this value over here so let me put these values in a graph and see how it's look like so first off we have to import matplotlib so import matplotlib as pi plot i think i've already imported this but it's okay so now what we're going to do is plt dot plot we'll be plotting the validation data so validation let's see what is the data we have we'll be passing accuracy and let me plot this first at the same time now we are going to plot validation accuracy so plt dot plot and i'm gonna pass here validation accuracy and finally we'll have plt dot show so let me execute this so as you can see here this is at one point where our accuracy has been increased and after that you know the accuracy has decreased the reason why we're getting this graph shows that the model is overfitting and in order to work this better what we can do is we can perform early stopping so let's see let's do one thing let's train our model only to the sixth epoch so let me just change from 10 to 6. if you want to execute this in a faster manner what you can do is you can just change your runtime to gpu what this would do is this would enhance or increase the speed of your every epoch that's happening here so as you can see here you know the validation accuracy is decreasing so this is something very bad the reason why we're getting this is because now we're supposed to run this from the start so what i'm going to do is let me change the runtime first and i'll change the runtime to gpu and let me save it so what this will do is this will really create the memory and we'll have to run this from the start so let me run this now so for me to run this all i'm going to do is shift enter shift enter so i'm going to do this for every value here finally coming down to fit transform so this is the place where our model is going to get trained so as you can see here now the execution is pretty fast compared to what was before so as you can see here initially our validation accuracy was 85 percent then it came down to 82 percent and then it was 89 which is good and then finally it came down to 90 and then 87 so what we're going to do is let's hit model.history and then we have to perform the same drills and let's execute this before i execute this let me give you the reason why we might have got this graph as i was executing this model multiple times maybe the model might have overfitted so now we should get a proper graph so as you can see here although there is some overfitting happening but we can fix that by having early stopping technique or something like that so but it's okay now this would work so now what we're going to do is let's perform some prediction so let's give prediction and then we give model dot fit so model dot fit so here it's going to be model dot predict and we are going to do predict classes and then we will give here validation data and let me execute this as of now so now what this classes does is we all know we have 10 classes here it can be like shirt panned or whatever it is and this is what it's supposed to do and let's see how prediction would look like so prediction and let me execute this so basically this is nothing but a numpy array and now what i'm going to do is so what we'll do is we'll take up some values here we'll take up the values from prediction and the values from xtrain extess and let's see whether we are getting a correct values or not so let me quickly go there so we'll have prediction so we have predictions so if i execute this as you can see we get this numpy array let me quickly take the random value here let's say something like 100 so the value of the class over here is 2. let's do one thing you know let's create a dictionary or something or what we can do over here is we can see what is present in this data so fashion mnist anyways so what i can do here is so i have prediction over here and this is giving the class 2. so let's see what does our x test does it's going to be white is so we have white test and let's see what does white test give us so we have 100. it should predict the same class and as you can see it's predicting the same class so let's go down let's take some random number again like thousand so it should predict as the same class with schemas two and now if i put down something like 500 so here you know 500 should also give us five so as you can see here now our model is performing fairly well this is because you know we have trained this using deep learning and when we train model during deep learning it tries to extract more features than what it would normally do now that we saw how tensorflow can be used in deep learning let's say it's practical implementation and how it is being implemented by big tech companies first off we have voice or sound recognition one of the most popular well known use case of tensorflow is sound based application with the proper data feed neural networks are capable of understanding audio signals and they perform tasks like voice recognition voice search sentiment analysis voice activated assistance these are used in products like apple siri google's android assistant and microsoft cortana further popular use case of tensorflow is text based applications such as sentiment analysis thread detection and fraud detection language detection is one of the most popular uses of text based application we all know google translate which supports over 100 language translating it from one to other the evolve version can be used in many cases next we have text summarization you see google also found one of the use case for short text summarization can be used to learn with technique called as sequence to sequence learning this can be used to produce headlines for news articles moving ahead to image recognition this is mostly used by social media telecom and headset manufacturers face recognition image search motion detection machine vision and photo clustering can also be used in automation aviation and healthcare industry image recognition aims to recognize and identify people and objects in images as well as understanding the content and context tensorflow object recognition algorithm classifies and identify arbitrary objects within larger images this is usually used in engineering application to identify shapes for modeling purposes and by social network for photo tagging up last but not least we have time series tensorflow time series algorithm are used for analyzing time series data in order to extract meaningful statistics they allow forecasting non-specific time periods in addition to generating alternative version of time series the most common use of time series is recommendation engine you have probably heard of this used in amazon google facebook and netflix where they analyze customer activity and compare it to millions of other users to determine whether a customer might like a purchase or watch something these recommendations are getting smarter every year the other use of tensorflow time series algorithm is mainly in the field of interest finance accounting government security iot with risk detection and then finally we have enterprise and resource planning all right guys with this we come to the end of our session i hope you enjoyed and learned something new if you have any further queries please do mention them in the comment box below until next time good bye and take care i hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to edureka channel to learn more happy learning you
Info
Channel: edureka!
Views: 4,831
Rating: 4.8800001 out of 5
Keywords: yt:cc=on, tensorflow 2.0, tensorflow 2, Tensorflow 2.0 tutorial, tensorflow tutorial for beginners, TensorFlow tutorial, deep learning tensorflow 2.0, deep learning using tensorflow, tensorflow 2.0 features, introduction to tensorflow, deep learning tensorflow, what is tensorflow, tensorflow basics, tensorflow for beginners, neural network python tutorial, Edureka, deep learning tensorflow tutorial, edureka deep learning, edureka tensorflow, Tensorflow training
Id: OHZqmJwj7n4
Channel Id: undefined
Length: 48min 7sec (2887 seconds)
Published: Fri Mar 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.