Image Classification - End to End Machine Learning Project | From Data Gathering to Deployment

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning guys okay just a quick update whether you can hear me or not type in yes in the comment section if you can hear me okay good morning everyone good morning waiting yes we are starting now we are going live and please let me know guys whether am i audible or not so that we can start with today's session okay i can just hear fine all right uh so i welcome you all to today's session and as the topic uh we have given here it is image classification using machine learning all right so we will be trying to actually create a complete end-to-end machine learning project today so what does end to end exactly mean first of all let me tell you that so we will be beginning our project by taking the data as you know in machine learning the most important thing is data we would take the data or we would fetch the data and there are a couple of techniques where we can actually use uh how we can fetch the data from all right i'm gonna mention a couple of them okay and afterwards after you have the data we will apply machine learning model then we will go through feature extraction and then afterwards we will uh build a machine learning model we will do some hyper parameter tuning and finally we will be building a machine learning model which will give us good accuracy and once we get you good accuracy will not stop then we will learn how to deploy that how we can get the final product as well okay so these are a couple of things which we will be actually checking out so please do hit our subscribe button of our channel if you are new to our channel please do consider subscribing our channel we uh deliver webinars on a weekly basis every sunday we conduct webinar related to data science python cyber security website development etc if you have any specific topic which you want us to cover you can please uh do that write that in the comment section or else mail us and we will be taking that query all right so a little bit about myself my name is mohammed amir and i will be the instructor for today for this particular session and i am the co-founder of diazonic labs as i have already mentioned isonic labs uh is one edutech company we are now out uh to deliver something of completely for free for uh you know people out there we are connecting free live sessions every sunday on youtube that is what we do all right so let's begin today's session guys so first of all i'm gonna take a few moments in explaining you what exactly is machine learning and afterwards i'm gonna make it completely practical that means we will learn how to build a machine learning model we will code all right we will learn how to code okay so let me open up this slide i've got a couple of slides to show you first and then afterwards we will go and uh get started with our coding all right so first of all you will have to understand this particular thing i have put here three important uh say bubbles okay there are three important circles we have got artificial intelligence as the outer bubble and inside that we have got machine learning and inside that we have got deep learning so first of all if you want to understand what is machine learning you will have to understand where exactly does machine learning come okay so it is actually a subset of artificial intelligence if you see here machine learning is in between okay it is inside this artificial intelligence bubble so basically machine learning is a subset of artificial intelligence technique which uses statistical methods that means it actually uses the concept of stats okay so statistics is what is being considered here that is the first thing and after that is there you will have to use or you will have to use little bit of programming to make sure that machines improve with experience so the definition of machine learning is pretty simple you make machines get improved with one specific experience all right you make sure that your machines are enabled to improve with experience and here you will be using two things one is the programming background and the second one is little bit of maths all right these two things when we are using you get something called as machine learning okay so with that being said let's move on uh we'll not be talking about deep learning today because deep learning is another concept or a subset of machine learning uh that is uh we will be talking about deep learning maybe you know in the upcoming session if you want us to conduct a session on deep learning please do type it in the comment section we will consider your request all right so for now we will be learning about traditional machine learning okay so let's move on all right now what exactly happens in traditional machine learning i have got a small graph here not graph i've got a small chart here okay so uh what you will have to understand here is here we have got say data we have got data in the left hand side okay on the other most left hand side we have got data and then that particular data is actually given to the machine machine gets trained with that particular data so pretty simple you have got data you actually train your machine with that particular data and then once you train the machine with that particular data you actually build a model all right once again what exactly is a model model is nothing but a trained machine all right model is nothing but a train machine now imagine that i am your say i am your mathematics teacher all right and you are my student for the first time when i'm actually taking you a class you will not necessarily know uh anything related to mathematics right so when you are uh when i'm actually teaching you for the first time you're not trained with that particular data you are just a machine all right now what i do is i put in you a lot of data now what you will do is you will actually find patterns like imagine i tell you okay one plus two i give you the concept of input as well as the concept of output i tell you one plus two as my input and then the output what you get is three i tell you two plus three uh as my input and then the output what you get is four or five okay so this is how i feed in lot of data all right when i'm feeding in lot of data to a machine the machine gets trained with that particular data and i at the end you build something called as model now that you have trained everything okay you build a model you can use that particular thing to predict one specific output all right you can predict one specific output with the help of that and that is how machine learning also uh works exactly all right so now uh when we are talking about data let's understand what and all are the different types of data which we are uh seeing in our day to day lives all right so the first data i'm gonna mention the data can be in the form of numbers okay whatever you are using to train the model right for that we would need either same numbers all right you can consider this particular data to be one information maybe you know you can just consider the simplest uh app which we use regularly in our day-to-day life consider that we are using whatsapp okay in whatsapp what and all are the different types of data which we send all right so i've already told you numbers again the heading i have already told you is image classification right so we can consider image as well all right so we have got numbers we have got apart from the text we have got images as well now can i want you guys to actually type in few of the other data just consider whatsapp just consider whatsapp as the platform can you tell me what can be the other other data types what can be the other structures of data which we use daily in our day-to-day life i have told you numbers okay we send numbers when we are whatsapping text yes we are sending some text images also we send yes we have got emojis we have got pdf okay pdf i can consider it to be text or image all right i would put it in that category uh yes videos we have got we have got audios voice comes in audio yes very well very well good all right yes so there are a lot of uh different types of data okay so as i have told you we have got videos we have got audios all right so yes rajya lakshmi when you say files what exactly do files mean right files can be numbers text images videos and audios i wanted it to be a little bit more specific all right but then i hope this is clear for you in understanding what exactly is the overall uh uh is the overall understanding of data what and all are the different types of data which we see in our day-to-day life all right so now if you see here clearly i have put up images in the capital letters or the upper case letter because that is the topic for this exercise right that is the topic for today's uh understanding of this all right yes so let's begin with uh today's session all right so we will be learning about image classification here how we can actually classify the images and how we can build up a machine learning model with the help of this all right so now what i'm gonna do is i'm gonna go back to my say google collab window i'm gonna use software to actually code this as i have told you mostly my session will be practical where in we will learn how to completely code all right so i will just press escape and then let me open up a new window here all right let me open up a new window and let's start to code okay whatever it is then we will be coding right now okay so first of all uh let me tell you the image classification whatever we are doing we will be using python as a backend okay so we will be actually using python software and with the help of python we will learn how to code now when i say python for python there are a lot of other softwares which you can actually use but i would prefer using google collab okay there's something called as google collab we will be using google collab as our basic software now what exactly is this google collab google collab is one type of online idle online uh sorry integrated development environment for python which actually allows you to write your machine learning code okay it is one type of interactive notebook interactive python ide all right that is what it is called as no problem kanishk you we just got started now maybe you might have missed a beginning say 10 15 minutes not to worry so i have given you the link here for google collab in the chat box okay so i would consider uh that everyone will open this particular link and for having the seamless experience i would request everyone to use laptop or desktop okay because we will have to code and more of that can't be easily done on say mobile okay so i would request you to open it using laptop so let me open this and this is how google collab looks like all right so here this is how google collab looks like and in this google collab you will have one option for new notebook okay you will have an option for new notebook let me click on new notebook here okay and i'm gonna wait for everyone to make sure that they have they are in the same page as i am okay so once you have opened this please type in done in the comment section so that i can continue type in done so that i can continue type in done so that i can continue okay i'm gonna take a break and let me know if you are able to open this particular thing okay fine so i hope everyone is getting this all right now let's move on uh here i'm gonna type the starting heading of this this is how my notebook or my google collab environment looks like i have got here untitled 19 the first thing what i'll do is i will change the name to image classification okay let me change it to image classification all right and then press enter now if you see here it says ipy and b ipy and b stands for interactive python notebook okay so this is the interactive notebook which we are using what do you mean by interactive notebook we know that python is actually built on interpreter okay it is interpreted language that means whatever you write right it gets executed line by line okay so you type in one line and you get the output for that particular line that is the whole understanding of this and that is why interactive notebooks can be used for writing better codes and for better analysis all right so the first thing what you'll have to do here is change the name of the notebook so that you can remember where exactly it will be and you can find out that particular notebook name okay the second thing is please click on connect all right the moment you click on connect what is going to happen is that whatever google collab environment you are using it is actually working online right so it is connected to the global server so if you want to make sure that you get started with the connection of global server you will have to click on that connect option okay that's it that is what you'll have to do and now you will be able to see here it says it it got connected to python 3 google compute engine back end that means you are actually running a system inside another system okay that is what it means you are actually getting access to the virtual system here all right now let's move on so uh now that you have understood this particular thing let's move on and let's start coding all right so as uh we remember the heading for our project is image classification we would need data right so we would need data here and the data are in the form of images all right now we can use now what we are going to do is we will be actually using lots of images to actually classify on particular variants all right so you will have to click categorize on different different features or something like that just to give you an example maybe you know we can classify say two different kinds of fruits or three different kinds of fruits all right maybe i want to classify uh i want to make a machine learning model which can classify say an apple uh or apple and lemon okay that means uh if i make a machine learning model if i keep an apple in front of that particular machine learning model it should my machine should actually tell me that this is an apple okay this is what it is going to do or else it should just tell me that it is a lemon okay it should classify properly whether it is an apple or it is a lemon all right i'll give you a quick example of how my project will look like you might have definitely heard about ptable machine with google if you have not heard about it don't worry i'm gonna show you this particular thing because this will be again our base on how we will be creating our project okay so i will pass on this particular link for you guys okay if you want you can just type in a teachable machine or else let me give you the link guys i will be sending you the link into the chat section you can just check it out all right so let's move on once you go inside this just click on get started here and what is going to happen is we can build our own machine learning model here and since we are learning about images let me just click on image project here so basically here in this teachable machine learning what is going to happen is that uh whatever we are doing right now okay whatever we are doing right now it will just help us understand better all right uh so we will learn how to code also but before that let us see the demonstration how exactly are uh how my project is going to look like all right just the pro just the demonstration i will be showing you first okay so i have given you the link you can please check it and now i'm gonna click on here i've got options of opening either from webcam or upload i will click on upload here okay you can open webcam and maybe you know you can take pictures from webcam as well i would prefer taking it from uh upload images okay so now if you see here uh let me just go to this i already should have the images okay i've got here lots of images of bikes can you see here in my uh say computer folder i already have lots of images of bikes so i'm gonna consider all of the images let me load all of them okay and then here there are 11 samples here let me type in the label as bikes okay please remember this in machine learning you will have to feed in input these are all my input 11 samples of input i am giving and then i am writing the output for that particular class label also and the output is bikes right i'm giving here let me scroll down i've got class 2 and in class 2 i will upload again few more images you can do the same from google or else you can do it by downloading it from the any of the uh specific site all right so i've got here say cars images i've got i think so 10 car samples here okay and then let me type in here cars okay i'm gonna type in here cars so i have got bikes images i have got cars images i will have to now click on train the model this is how it is going to happen all right here nothing no coding is being shown because everything is happening in the back end okay everything is happening in the back end here we are just i'm just trying to showcase you how exactly machine learning works okay so now you will be able to see that this particular thing is actually getting trained we will have to wait for some time it is getting trained on all the data here once it is trained it will actually open up okay it will let me just switch this webcam to save file it will actually open up the model here now my model is built if you see here once again we are using the input values okay and then these are this is the output value the first data the second data is input and then the output is car and then i'm training the model okay once my model is trained i'm training the machine and i get the model once my model is trained i'm checking the output so i will use an image which i have not shown it to the model all right i'm gonna show a new car image okay let me take a new car image and this a machine should actually tell me whether it is a car or a bike all right so let me just scroll down and you should be able to see that 100 it says that it is a car okay zero percent it is a bike hundred percent it is a car my model is trained now okay this is how we will be building all right so if i go to images here and if i select a bike can you see here it says hundred percent bike and zero percent car okay this is what we have here all right so this is how normal machine learning works and uh which modules are you using okay please so here i am using the normal data i have already downloaded here basically teachable machine is one of the product of google which you can actually use it's a completely open source free uh product which you can use for understanding or building simple machine learning model here we are using tensorflow okay uh this is based on one library called as tensorflow wherein we are creating this particular model but then the generalization is very well for any other machine learning model you can do the similar kind of analysis on what we will be building right now okay so that should not be a problem all right so this was a quick example for you in making you understand how exactly machine learning works and now we will be coming back to image classification wherein we will do exact same thing what we have done here okay uh when i say exact same thing will not be using tensorflow we will be using traditional machine learning library called a scikit learn and we will see how we can actually use this particular thing yes we can download the model to short if you click on this export model right you can download the model here you will have option for downloading model in three different types you can download it in tensorflow.js tensorflow you can download tensorflow lite also you can download so basically light is for uh android application all right so this is for a mobile application this one you can use it for maybe you know if you want to do something onto the cloud you can do that and this is for webpage all right tensorflow.js you have got that option as well okay and you can play around with it okay so all right what is the difference between tensorflow and pi prelim uh this is not the syllabus which we are talking about but anyways let me tell you both are the deep learning frameworks and both are from different companies that is what i would say you can't really differentiate between uh say dell and hp laptop right so it has got its own importance both are for now beginner friendly okay uh you can actually use tensorflow when it was only in the initial stage when it was uh having only tensorflow 1.0 that time tensorflow was supposed to be little difficult but right now with the help of uh evolution of tensorflow 2.0 it is very easy you can get started with the basics of deep learning at least in tensorflow 2.0 and pytorch is also pretty much on the same level both are being extensively used both are popular uh tensorflow is from google pytorch is from facebook all right okay so in which platform are we deploying the model i'll tell you that produce don't worry i'll tell you that okay so narayan i don't have the photo of taxi i have got the photo of truck if i want you to if you want me to add that i can add that and show you the moment i click your truck it will tell me that it is more of car and less of bike because the truck more or less looks like car and uh a little bit uh way lesser off buy okay that is why we get the output for truck as a 94 percent car and six percent bike okay since we have not trained on truck separately here it will tell me either of this these are the probabilities which are actually indicating it tells me that 94 percent it is a car and six percent it is a bike all right i hope that answers your question okay so now let's go back to our image classification all right right there is no prerequisite there is no prerequisite at all you just need to uh understand what exactly i'm telling and try to follow the same thing all right and if you didn't understand anything you can please ask me okay so let's uh get started with this particular thing now uh since we are working with data images as i have told you for taking the data there are a lot of things we might need to uh download manually the images okay from google okay this is one of the thing for our data or else download data set from say we have got kaggle.com okay kaggle is one of the uh most popular say website wherein you get a lot of data sets you can either download it from that or else the third option is web script let me type in like this build a web image web brawler okay you can build image web crawler here you might get this uh for this particular third option right you might need to have little bit of uh you know coding background in how you can type in web crawler how you can use web scraping and all of it okay but then there is one more fourth option use python libraries okay to scrape the images all right and we will be using the fourth one okay fourth one we will be using all right so fourth one is what we will be using right now now which python library can we use so i'm i will be using one specific library called as binge image downloader you might have definitely heard about bing okay so when i go to bing.com i think okay this is another search engine which we have okay just like how you have google and here i can specify anything say i right here bike and i will get lots of bikes here okay let me go to images and i will get lots of bikes okay it's showing cycle yeah whatever it is right so you will get all of this particular uh images here and we will be using this particular images itself all right we can use maybe you know this particular images to actually uh get started with our project all right so how do you scrape this how do you take it up from here see for building a machine learning model just like how we have built here we would need at least 11 or maybe consider 20 to 30 images so i can't always do right click and then save image as download and then uh properly keep it like that it will take a lot of time for me right so how do i automate the process i automate the process by using python library all right or else you can do any of the upper things whatever you have i will be using the bing image downloader so how do i do that i'm gonna type in here say trip install okay because i will have to install this particular library here i will type bing image downloader okay bing image and then i will type in here downloader all right this is the library which i'll be using now let me tell you what is this this is the place or this exclamatory mark actually makes sure that whatever you are writing in that particular cell of google collab it will be considered on a command prompt all right paper install it is the normal usual way of installation of any new library there are few libraries which are inbuilt in google collab but there are few which aren't okay so bing image downloader you should explicitly install it okay that is why i'm writing this particular thing let me run this and it will get started to uh it will get started to you know download and get installed all right now you will get the message successfully installed bing image downloaded now that you have downloaded this particular thing we can use to actually uh maybe you know put it up or download the images whatever images you want with one specific command all right so how do you do that first of all i will create one directory called as images let me just create a directory called as images here mkdir images is what i will write the folder name all right and if you see here on this file section by default there won't be anything all right by default you just have sample data okay these are few of the data sets which we have but then these are numbers and text we need images right so here i will be creating a directory called as mkdir images all right so mkdir is the uh say command which is telling us to make a directory or a folder by the name of images so let us see whether our images directory is ready or not can you see here images directory is now ready all right once we have got images directory inside that images directory we will have to download few of the uh say images right view of the categories of images so i'm gonna call from bing underscore image underscore downloader okay let me import downloader import downloader all right and then afterwards i will type here downloader dot download okay and then inside this i want to specify what do i need okay which category of image do i need so i will take the first category maybe you know i will take some flour okay i want to differentiate say a flower okay so i've got here sunflower let me make it much better let me type in pretty sunflower okay so i will take sunflower images here so let me type in pretty sunflower okay as my image which i want and then the next thing what it says is the limit okay how much limit do i need i'm gonna take totally 30 images all right now before i could go with the other parameters let me show you how you can actually learn about the parameters just go to website pypi.org and then here you can type say bing image thing image downloader okay just type in this and then you will be able to see bing image downloaded here just go inside this and here you should be able to see the usage of this can you see here all of the usage is given here query what is the first query you have written limit by default it is 100 we don't want let me keep it uh limited to say 30 then the next thing is output directory if you want to type in something you can just type in where you want it to be saved then uh say disable if you want to enable the disabling uh disabling of adult filtration you can do that then force replace by default it will be false uh you can just check what exactly you want to do with that and then timeout also by default it is 30 so i will just put say after limit let me put output directory okay and i don't also i will just turn it off so i will put say output underscore dir uh let me put images because directly it should go to the images folder all right and then after this is done comma let me press enter i will type in adult underscore filter so i will make sure that it is off okay so let me make it true all right now once this is done we can just run on this okay there's something wrong here all right i'll have to give underscore and let me run on this and it will take some time can you see here it will tell me that downloading image 1 image 2 okay it started downloading and if there are few files which might not set up which might not work out properly then it will retry for the different image all right but then yes all the 20 images should be downloaded can you see here now all the 20 images are downloaded from this particular thing indexing page one okay see here downloading image from this particular link file downloaded file downloaded all the 30 files are now downloaded all right once we know that the files are downloaded where can we actually check the output so you can go back to this and inside your images you should be able to see there should be one folder called as pretty sunflower and inside this you will have say 30 images let me just open up one image and show you uh how it looks like okay let me open up see here this is a sunflower which i am getting second one okay i can see here all the images of sunflower all right this is how we uh web scrape the data this is how we build a simple web crawler i have not built a web crawler i've used a library all right this is how we do it for sunflower i have just taken one specific this one for sunflower i have taken here now similarly i will take say for other things i would want some other uh say value or say some other category i'm gonna stop here and uh let me take few questions from you if you have and then we will move on okay so please asking sir some of the past modules is not supported with really uh i think so again this is not the right platform right now we are not discussing about tensorflow so if you could keep the questions limited to this particular session i will try answering you that sir whether we are importing some libraries there is an option that downloads from scratch what is that scratch sir okay i didn't get your question how to download images you will have to write a code ramesh maybe in the future i will uh upload one video regarding that web crawler for images okay yes ramesh uh you'll have to write in a code for that maybe in the future i will consider that and i will give back to you all right uh can you type in done if you are able to download the images guys can you type in done if you are able to download the images type in done i want you to type in done if you are able to download the images i'm gonna wait for you to tell yes okay until then i'm gonna go for the second this one also let me just copy this and paste it here okay people who are new to our channel please consider subscribing our channel and also like the video guys like the video people who are there please like the video can we download other images yes you can download any image whatever image you want i'm gonna download now another set of image uh let me download now now the next thing maybe you know i want to download say football let me check what do i get okay football i get images of people i don't want people okay i think so let me call rugby ball okay rugby ball leather let me check so i think so this should be a fair enough this one in actually understanding whether uh it is there or not so i'm gonna type in rugby ball leather here as the second uh value all right second value i'm gonna type rugby ball leather from bing so let me run this and it should actually start uh downloading the images so let us see uh it will take some okay because it has to download all of this right but then it is telling you where exactly what is happening so 24 images uh 25 see if there is some sort of ever error like this right it will actually neglect that particular image and it will go for the next one all right but then overall you will get 30 images okay overall downloaded 30 images that is what you should actually get here all right so now that you have got the 30 images uh let us check whether we are getting the output here in the images or not see a rugby ball leather and if i go inside this the first one okay hopefully that should be proper see here i am getting a rugby image okay so i'm getting a rugby ball here all right so it's a very big sized image but then yeah not to worry we are getting this particular thing all right i hope the uh plan whatever we wanted to do right it is actually successful all right now i'm gonna take one more uh maybe you know beta let me take for three categories if you want to play with two also you can do it but then i will take one more so i want something with ice cream cone okay so these are all the ice cream cones which we have right so let me type in here ice cream cone okay ice is cream cone all right and let me run this and again it is downloading all right there might be few again here giving you error forbidden and all of it that should not be a problem okay so let's wait and make sure that we have got our images ready okay uh so 17 images done it is still downloading all right let's wait for a while and hopefully it gets downloaded all right so now that you see here this particular thing is only uh rotating right that means it is actually loading and some other operation is actually happening here okay so now uh if you have got till here then uh if you want to understand what is the utilization time or what is the execution time of every cell you can actually use one specific magic command in google collab and understand how much time does it take to download this particular thing all right if you want to understand how much time does it take let me give you that small trick as well i'm gonna go to the first slide here and then here i will install a new library called as fifth install okay and then let me type i python uh auto time all right or to time okay now that i write this let me write percentage load underscore exp okay execution time is what uh we will now understand or we will come to know okay so now once this is done let me just run this and the moment i run this see here it is downloading and collecting and successfully installing right you can please note this okay please run this particular cell because the next time whenever you run any cell right it will actually tell you the execution time how much time does it take to actually execute one specific cell okay one specific cell how you can execute it you will be understanding all right i'm gonna show you that in the future this one now uh you can consider that your data is completely ready all right your data is completely ready we will have to build our project based on this three data itself we have got three different varieties one is of ice cream cone one more is of uh say sunflower one more is of rugby ball right i've got here and inside that i've got a lot of images right inside that i've got here say 30 30 30 images all right i've got here 30 30 30 images from this particular category all right now how can we create a data set for this how how can we actually build a machine learning model for this particular thing all right let us see that so tunji we are using google collab we are using google collab for uh writing the code okay so please check the heading we are using google collab for writing the code and that is what we will be actually uh using completely in our project all right and we are using python as a language okay so yes i'm gonna okay what is this sir once show the code of image download okay so let me scroll down here there you go this is the code which you will have to write let me close this this is the code which you will have to write for image download jarena okay so this forms the first part or let me call it as say data gathering part all right we have gathered the data right now now that we have gathered the data the next thing what we will have to do is use this particular data to actually perform few pre-processing if there are any okay if you don't have any pre-processing then build a machine learning model all right that is what we'll have to do so the first step is i think so pretty much clear in gathering of data this is how we gather the data we had used the fourth one here all right so let's move on okay what is this so please show the cell of comments which comments don't this cell okay there you go this is the one if you're talking about okay just type in ice cream just type in ice cream cone sriram see here just copy this completely and then you will have to type instead of pretty sunflower just type in ice cream cone if you want something else you can just type in here and you will get that particular thing but before you could run this i would suggest you to open bing.com and check which are the images which type of images will you get okay please check because uh as i had shown you when you type in only football you might be expecting a ball but then you will be able to see only people there okay see here only people will be shown all right so please make sure that you type it in binge uh being what you are getting and from that you will be uh you should be checking what output you are getting all right so let me scroll down now i would consider that our data set is now ready now the second thing is we will have to play around with the data set we will do pre-processing all right let me type in here pre processing okay now how do we play around with the data the first thing what i need here is import os because i will be using say operating system library apart from that i would need here import matplotlib dot pi plot as plp okay i will be using this to in case show the image all right and then i need numpy okay for normal this one i'm gonna use numpy as np okay is it compulsory to search in bing yes dhiraj because the library which i'm using is bing right the library which i'm using is bing because the bing uh search engine is completely different from google search engine the algorithms how they search is completely different okay so it's more obvious that you should select bing search engine to check what images you want to see rather than you seeing with google because google we are not using the library of google we are not scraping from google the images are not script from google it is scraped from bing right so it's better that you do it from that all right i hope that is clear okay so now i have got here numpy as np now apart from that i would also consider one more library to read the images and the library name is sk image okay sk image dot i o import i am read okay this is what i type in here and then afterwards i would need one more uh sk image library here sk image dot transform okay why do i need this i'm gonna tell you just in a while dot uh transform of resize all right so i've taken here five of the libraries now import operating system i need this operating system because i would be using lot of folders i would be going from one folder to another folder so to play around with the folders i need this okay matplotlib is for displaying the image numpy is for doing some numerical computing for reading an image i would need this okay you can uh alternatively go forward for opencv as well there is a very good library opencv in python which you can actually use but today we are not working on opencv okay so we will be using sk image.io for doing all of that task image processing task will be considered by sk image scikit image is the library name so for reading an image we will use this for resizing we know that our images they are not in one specific size and for building a machine learning model we want all of our images to be following one specific time frame sorry specific size all right all of them should be in one specific size say it we should be in 100 pixels versus 100 pixels or something like that if you see here in a model teachable machine you should be able to see all of the other thing is actually blocked here okay see this is your image all of the other pixels are blocked only the square pixel is kept out here similarly here also if you see in the truck okay so all of the other uh pixels are blocked only what can be handled in a space of square shape that is considered here all right so we will also do the same we will not be cropping all of the other things instead we will be following a method where in all of the values will be in the maybe you know lesser resolution but then it should fit properly all right i will try to display one or other images and i will show you the output as well okay so yes the language which we are using is python the software is google collab as i have specified here google call app collab.research.google.com okay this is the software serena which i am using all right so now what i'm gonna do is we know that we would need actually say the data in two different formats one is in the form of input and one more is in the form of output right we need the data in two different formats here now that uh we know what exactly is an image uh let us i identify the properties of images so whenever you consider any image we know that images consist of lot of pixels all right inside that you would have lots of pixels okay so pixels can be in the form of height as well as width all right so you will have pixels in the form of height you will have pixels in the form of width now if you are passing that particular pixel value into the machine learning model as an input we should flatten it out what do you mean by flattening it out that means whatever images you have whatever is represented in the form of say rows and columns it should be flattened out into a single dimension i'll give you an example for this okay so if i just add up a code here okay what i'm gonna do here is consider that i will be importing once again say numpy as np okay and now if i want to actually say type or create numpy array i will write a dot a is equal to np dot array off okay and inside this i can just specify say one comma two and this will be considered as a vector all right so now 1 comma 2 what i have written it is a vector which i am actually writing here all right now this particular vector uh it will be having how many dimensions one dimension all right so let me just run uh dot ending and it will tell me that it is having one dimension that means all of the values here are spread out in one single uh manner itself all right but then what if i create a matrix here okay i'm gonna create a simple matrix here let me write comma and then i will write say four comma five comma six comma seven comma eight comma nine okay and then i will just one two three four five i will just run this particular thing it will be considered as two dimension can you see here the output is two dimension here okay it will be considered as two dimension now how do i convert two dimension into one dimension that is the most important question okay so how do i convert how do i convert or else let me consider like this how do i convert say matrix to vector how do i do that for that we would be using something called as flatten all right the answer is pretty simple flatten method if you use flatten method then whatever two dimension it was there it will be converted into one dimension let me show you that i'm gonna write here a dot flatten okay a dot flatten and then let me run it i know it is a right but then see here a which was matrix now it is converted into vector okay this is how we actually flatten up all right we know that our images it will be in the form of matrix okay images are always represented in the form of matrix now that particular thing has to be flattened how do we flatten it we can flatten it very easily by using flatten option okay when we use flatten option we will actually flatten up our line all right so let's do the same thing here uh also okay i will be using this as one of my pre-processing technique now i would need here something uh maybe you know i would call output as target where in it will tell okay whether it is a sunflower or rugby ball or ice cream cone all right i will take an empty list here the next thing what i'll take is images okay this is my data all right this is my data as it is which i get but then there is one more thing which will be flattened data okay this flattened data should be passed to create a machine learning model images can't be passed right flattened data should be passed because this will be in the form of a vector this will be in the form of that straightened uh flattened value all right images will be in the form of 2d okay it will be in the form of a matrix okay which we can't pass we should pass this particular thing all right i hope this is clear in understanding so how do we actually examine this how do we actually take up the data so first thing is i'm gonna mention your data directory that means i will have to consider the path from where my images have to be considered so i will go back to this particular thing and i will select the images path here let me just copy it and let me paste it out here okay this is what i do content images all right this is the data directory which i have now the next thing what i need to do is take the categories let me call here categories and here i will have to name my categories properly all right which is the first one it is pretty sunflower okay the second thing is after this is done the second thing is rugby space ball space leather all right and then the third thing what we have here is ice cream cone okay i have taken here three things and once i have taken here the three things let me now uh say scroll or let me now iterate through them okay i will have to iterate through all of this so that i get the images correctly all right so let's start iterating i will type say for loop for category i will take one specific uh say term this is just like calling as i okay in the categories right in categories i will be collecting this that means it is spreading or it is moving around from pretty sunflower to rugby ball to ice cream cone i'll just print out and show you if i print here say category it will display me all the three values can you see here one after the other it will display me pretty sunflower rugby ball ice cream cone all right it will display me okay this is what we have now uh you will have to remember one very important thing the targets whatever you have right i know that categories are considered as targets but then i don't want to consider targets just like that okay i want it to be named one specific name let us rename it that means we will have to give it in the form of say numbers okay if it is in the form of numbers then the machine learning process will be very easier for us okay there is this concept of label encoding also which we can use later on but then we can directly use the index name number here instead of zero i'm gonna call it as pr sorry instead of pretty sunflower i will consider that particular thing to be zero okay what is for one rugby ball leather is for one all right and then ice cream cone will be for two okay this is zero this is one and this is two all right this is how we will consider right now okay so how do i consider that i'm gonna remove this okay i will type in here say class underscore num okay is equal to i will call for categories that worries okay dot index of category all right now if i print the value of say class underscore num and then run it you should be able to see 0 1 2 0 stands for pretty uh 1 stands for rugby and ice cream cone is for two okay we are changing here all right we are maybe you know let me type in here we are label encoding the values okay this will be easy for us because we have got a lot of images it might take some time right so that is why now let me remove this what i'm gonna do here is i will type in here path as the variable and then i will use os os is operating system dot paths dot join now why am i joining because i want one specific pathway right like imagine i want all the values from image cone if you see here the path of this copy path if i write in here let me just put up here say and you see your content images see your content images is nothing but data dir right ice cream cone is nothing but one of the category yes can we write something like os dot path dot join and inside this what if we write data dir a data directory first okay and then do comma category that means it will iterate through all of them without we mentioning it right so let me show you this now if i print the path value here let me just click on print off path it will print all the three values can you run and see here see here for the first time it is printing pretty sunflower second time it will print rugby ball third time it will print ice cream cone okay this is the best part of uh using os library all right this is why we will be using this particular thing okay now how we can iterate we will see here we have created path right let me mention in comments create say path or create path to use all the images okay now next thing is i will take another for loop okay i'm gonna write img in and then os dot list dir that means i am listing that particular thing from the path okay from this path from this part say from sunflower okay i will be using few values okay i will be reading out few values from here i will be reading out few a few or all the values okay that is what it means all right so now the path is now changing right for the first time this is the path from this path i will read up few values how do i read i will use i am read if you remember i am read i have used here above right i am read is what i am gonna use i am read off and then here i'm gonna mention os dot path okay dot join i want to join two things because not only path is necessary for me if you go back here okay i know path is there but then along with path here i need to mention the image name as well right so path is there let me type in here the first thing will be path but then along with that i need to mention img as well okay now that i have mentioned img here let me store it in say img underscore array okay one variable now if i print if i print the value of img underscore array it should print all the path names for me okay let us run this and check sorry it is printing me sorry it is not printing the path name it is printing me all the values okay all the values it is printing all right all the values because i have given your img right all the values which are red it is printing to me all right this is what it does now we can actually use this particular thing to maybe you know show if you want to see one or other one or two values right you can actually see that all right i'm gonna print one or two values and i'm gonna show you but then yes uh if you want to see the shape of this you can just type in shape and then run it you should be able to see all the values okay all the images shape is being shown here 720 720 540 and all of it and then you have got say all the uh values will be shown here what is this three this three actually tells you that it is rgb image this is the height this is the width of an image and this is the depth all right now if you want to see one specific image i'm going to show you one specific image okay i can't show all the 50 then it will take a longer time so if you want to see just one specific image i will just uh make sure that i write plt dot i am show okay off and then i am gonna type in here say img underscore array img underscore array and then afterwards i will just run this okay but before running it let me put a break and then break because if i don't put break and break then it will be actually printing again and again i just want one image to be seen okay see here one specific image is being shown let's forget about this okay can you see here one specific image is being shown here from the cone because the last one i am showing there all right so from the cone this particular thing is being shown here all right so there you go i'm gonna stop here and if you have any questions guys you can please ask me or else we will do the pre-processing in pre-processing uh let me type in here the first pre-processing which we will have to perform is actually the uh say resizing okay we will have to resize it let me type in here resize okay and then the second thing which we will be performing is uh after resize it should be flattening okay so these two things we will have to do and we will have to add up or create the data set all right you can just type in here and check uh how exactly this particular thing is working and i will take a small break now and if you have any questions please ask me or else we will continue okay type in done if you have understood till here guys type in done if you have understood okay okay what is this uh so sir it will join by path itself yes that is what it does uh please send mustafa we are here to learn don't worry about that for now concentrate on what i'm telling okay uh how do we know all these methods this is only by practice that is why we are taking some time in explaining you all of this all right why only one image is being displayed yes because i'm using the break statement here only the last one will be displayed for you all right so if you don't use the break statement here all the 50 images will be displayed for you which i don't want to do right now okay you can try it out all right it'll take a lot of time that is the whole point let me scroll up the code see here once again i have just imported your few libraries i have taken your target target is the output one then images ah these are the input ones flat data is also image but then this will be completely flattened all right these are the three things which i will be taking i have still not done flattening which i will do in a while okay can it be any image yes it can be any image it doesn't matter right so uh we are actually creating a say image classifier okay that is the whole point it can be anything generally because i don't want any unwanted images that is why we use adult filter okay so i don't want any unwanted uh images due to you know uh whatever we find all right so uh so that it is not spammed i have kept all of this all right so yeah let's continue uh once i have done till here i will now continue for this particular thing i would uh request everyone to again please subscribe to our channel and please like the video guys i can see a lot of people being online and uh i can't see a single person liking it properly please like our videos guys this will actually motivate us to keep you guys you know updated with the latest news please please like the video if you feel that what we are doing is uh good enough please like the video can i get a quick like from everyone okay so let's let's continue guys so i have taken till here all right what is this sir can you show the matrix code if you want the matrix code just type in image underscore array and you will get the matrix code see here i have written image underscore array remove that shape without removing the shape just write image underscore array and you should get the matrix code all right so if you want this particular matrix code then you can see here okay this is the one all right so i have just written here a matrix and then i'm just flattening it i'm converting it into one single dimension all right this is what i do now fine okay so the next thing is we will as i have told you we will have to go through uh with say pre-processing stage we will have to do two things one is resizing and one more is flattening right so let us resize it how do we resize this now so it is pretty simple i will uh put this particular thing also on say comment and then i will press enter here and now i will resize it so resize off okay and then here i will give input as say image array because that is what i have taken on top and then here i will have to specify what size do i want so i will consider 150 by 150 comma 3 why 150 it is just one arbitrary number if you want you can keep it more but then it will take longer time for you to actually go through that particular thing i am kept i have kept it at 150 okay so let it be 150 itself and after this is done i'm gonna type in img underscore resize okay let me store it here inside this and after this is done for every iteration it should actually go inside the data right so we will have to flatten it first so how do we flatten it img underscore resize okay img underscore resized then i will have to type in dot platinum because i am trying to flatten the value all right so now this particular thing i can maybe append it in flat data itself so i will write flat underscore data dot append all right is that correct so i will write here this particular thing okay hopefully this is right and i will have to do two more thing one is images uh dot append images although it is of uh no uh work for us but still i will just type in your image resized inside this okay and then one last thing what we have is target so i will write target dot append off class underscore num okay target i will be appending it to class underscore num okay this is what i do and just in case uh if our values are not converted into numpy arrays we will convert them into numpy arrays also by writing say flat data is equal to np dot array of flat data flat underscore data okay the next thing is target i'm gonna use the target np dot array of say target okay and then finally i will write for images also images is equal to np dot array of images okay this is what i write now why am i writing this particular thing as i have told you i don't want anything to be outside the uh value outside numpy this one so if it is in numpy it is very easy for us to iterate and go through it all right so this is what i write here here i am re-scaling or resizing it here i am flattening it these two are the most important lines of the code okay so please make sure that you write them all right so once it is done we can just run it it will take some time to actually go through this because it has to process out all of our data whatever it is there all right and since we have put the time also it will actually tell us what time it will take to uh you know go through this particular thing of resizing as well as flattening out of images all right so let's wait for a while and afterwards we will understand whether our flattening out as well as resizing is proper or not okay i think so it is done and it gives you the time frame here the time frame is 23.3 seconds that means it took totally 23 seconds for me to you know make sure that it is flattened out properly and it is resized to one specific value okay now that we have understood this uh we if we want we can check what is inside our flat data what is inside our target what is inside our images also okay let me just type in your flat underscore data and then let me run it and you should be able to see the output here can you see here it should be uh let me just type here flat data of 0 and you should be able to see the output here all right can you see here it is in one single dimension now okay the value whatever it is there it is in one single dimension these are all the pixel values okay now one point to be noted here the moment you resize right using sk image your sk image make sure that it normalizes okay there's something called as normalizes or oh yes let me type in normalizes the value from 0 to 1 that means your values the pixel values which were there from 0 to 255 it gets normalized to 0 to 1 okay can you see here your flat data will also have uh this particular kind of value how much values will this contain this will contain 150 into 150 values right 150 multiplied by 150 if you run this how much you will get 2 to 5 0 0 so if you just check this out length of this particular thing you should get similar amount of it i think so you are getting okay six seven five zero zero because multiplied by three right you are getting rgb here so the same thing okay this is the value which you will get okay this is the value which you will get i hope this is clear uh once we have flattened the image if you want to check the target target you should be able to see 0 1 2 0 50 times uh sorry 30 times 130 times and 230 times okay this is what we will get and let me quickly if i want to say plot a graph for this particular thing i will type in say np dot uh unique all right and then i'm gonna call here say the target value target comma return underscore counts okay and make it true and the moment i run this i should get here here 0 is 31 is 30 and 2 is also 30. so if i uh maybe you know store it in say unique comma count is equal to okay and then afterwards let me just plot a bar graph plt rod bar of say i want to give categories okay comma count categories have already taken up right what is it uh you will understand it much better so if you see here pretty sunflower rugby leather ice cream cone 30 30 30 is what we have here okay so i'm just plotting here to make sure that you know you understand uh what are the total values the data set what you have totally we have got 90 values here okay total values what we have here are 90 okay so we have got 90 values here of all the values and afterwards we will now use it for maybe you know creating a machine learning model okay so our data set is now ready next step is split data okay into say training and testing okay so we will need to split our data into training and testing and people who if you have attended my previous session you might understand uh which would be the method for splitting our data into training and testing so we will be using train test split from model selection of skl on okay so let me just go to say uh google here and type in train test split and you should be able to see this is the one which we'll be using all right sklearn dot model selection sk learn is the library for building a machine learning model and we will be using the same thing here all right so sk learn it actually splits your arrays or matrices whatever you have into random train and test sub subsets okay this is what it does why do we need to do this because our machine learning model as you remember it should be split up into training data as well as testing data only once it is split up into training as well as testing it will we will actually understand whether it is performing really well or not all right so that is the whole point of splitting up our data and we will be doing the same thing here all right so uh let me type in here say x underscore train okay wait before that we will have to call right so from sklearn all right dot model underscore selection okay and then let me import quickly train underscore test underscore split okay and then i will write here say x strain comma x underscore test okay these are the four things which we will get all right and then we will get say y underscore train comma y underscore test okay once we have got these four things we can just right here say train underscore test underscore split okay and inside this i will mention my x to be flat underscore data this is very important guys you should not mention other thing okay you should mention flat underscore data yes the validation data is what now i am taking here into consideration all right i have not considered separately i've considered here with this particular thing so that i can understand how exactly my training data is working okay my training data whether it is working properly or is it uh overfitting or not and all of it we can check it out all right so i'm gonna mention your output as target and then let me give test underscore size here okay is equal to say 0.3 30 percent i'll mention that particular thing and then random underscore state i will mention one specific value this is not uh exactly you know as what i have specified you can specify whatever value you want i'm gonna specify it as 1.9 just a random arbitrary number which i have specified all right so now that the data is splitted into two variants the next thing what we will do is we will now use actually uh to uh you know run a model we will be using an algorithm all right so since this is a classification algorithm or classification type because we will have to divide we will have to check whether our image is say this one that one or maybe you know some other uh value so for that particular thing we will have to use any of the classification algorithm in traditional machine learning in say scale and we have got a lot of classification algorithms if you just go to say sql on website here you will be able to see your classification we have got svm nearest neighbors random forest and lot of other things we will be using svm so basically svm stands for support vector machines so what exactly is this support vector machine it is again belonging to set of supervised learning method what do you mean by supervised learning method here the data whatever you feed in it is well labeled that means input and output will be clearly shown and clearly given all right that is what we do and we will be using classification uh which is using sve m itself okay or we call it as svc support vector classifier okay this is what we will be using and once we use svc uh svc or svm it will be actually helpful in generating a very good hyperplane all right so let's go ahead and create it now uh before running the svm model what i want to do is i want to actually run one specific selection of model called as grid search cv with the help of this grid search cv it will be really helpful for me in uh making sure that the parameters which i will be using in support vectors are proper now what are parameters see whenever you are importing any library right it is treated as an object object will have method in python all right and then that particular method say svc method we will have lot of parameters to vary there's something called as c there's something called as kernel there's something called as gamma and all of it we will have to learn how we can vary that particular thing so that we get the appropriate results all right in support vector machine you will have to worry about three important parameters let me go inside this and show you so okay uh one second okay there you go this is svc which we have and if you see your parameters the first one is called as regularization okay this is something very important now the strength of regularization is inversely proportional to c that is what it says right and it should be strictly cr positive all right that is what uh it is telling here here we will have to fix the value of c and the c value by default it is 1 we know that but then it can change from 1 to 10 to 100 to 1000 okay a lot of values can be changed but then which value will be specific for our data that is what we will have to determine okay this is the first thing which we will have to vary and check the second thing is the type of kernel do you need say linear kernel or rbf or poly or sigmoid which kernel do we need we will have to check that all right and apart from that the next thing we will have to check is again gamma what exactly is this gamma gamma is called as kernel coefficient if you are data kernel is not linear if it is say uh if your kernel is uh say rbf or poly or sigmoid then we will have to choose gamma value also all right so all of these three things if you want to identify properly that is where we will be using grid search cv okay how do we use grid search tv now anyways so i'm gonna call for from sklearn dot model selection okay this is again one of the model selection which we will have to perform and then let me import red search cv okay so more on grid search tv you can just check it out from here if you go back to say sk learn and then type in say grid search cv you should actually get the documentation purpose for this particular thing all right what in all are the best parameters which you can select so this will actually help you to select the best parameters and along with this i'm gonna import sql on uh import svm okay i'm gonna import the support vector machine also fine now that i've imported all of this let me type in param grid okay i will have to specify now which is the best uh value for my respective understanding of this so first thing is i will specify the value of c right see as i have told you one of the important parameter for regularization so i will type in here say 1 comma 10 comma i would consider that it can be varying in this particular region okay and then afterwards for the first this one i will give say kernel as let me give kernel let me give linear kernel here okay so linear as my kernel again i'm not going in depth uh inside this particular svm okay we will be having a tutorial on that also if you are uh if you want to learn more on this please let us know we will be creating something in depth of how we can create maybe you know uh svm what exactly is this c what exactly is this kernel and all of it we will see that but then for now i'm just using this grid search cv so that you know uh whatever we are doing it can be done very easily okay now here i will specify my kernel i don't want it to be say linear i will specify it to be say rbf for now and then let me specify when it is rbf i will have to specify the value of gamma also okay so the gamma value it is much less 0.001 is what i will give as my first gamma value and then the second gamma value will be 0.0001 all right there you go these are my gamma values which i am giving okay and after this is done uh hopefully everything is fine here there might be some problem with brackets we will see that later on anyways uh i have called here the best parameter out of the two if you want to give more here values you can give that as well okay but for now i'll give only two and then i'm gonna mention here svc is equal to say svm dot svc okay and i'll make sure that probability is open because i want to actually understand what exactly uh maybe you know if i'm giving one specific image it has to tell me along with this probability it has to tell me all the other probability also if you remember here in teachable machine uh it will tell you that so much of car is shown and so much of bike is shown if you want to see both of them then you will have to make sure that probability is actually true here by default this one will be false okay so make sure that it is true and after this is done you can write maybe you know run the code by just specifying grid search cv okay off take in svc as your input and then other extra parameters the best parameter as param grid okay this is what i have taken here and afterwards just fit the model just like how we do for normal machine learning okay so x underscore train comma y underscore train okay this is what we do and let us just run this okay what is this what is gamma kernel rbf okay so as i have told you that for any uh algorithm in machine learning you will have to learn about its specific parameters all right so in svm or in support vector machine when you are actually using it for classifying you need to get something called as hyper parameter which will separate between both the regions okay both the categories both three or four how much our categories we have and inside that there are few parameters which you'll have to learn the first one is called as cc is somewhat similar to a regularization parameter all right apart from that you have got a kernel how is your uh say data point varied from each other is it separated by a linear kernel or a poly kernel or rbf or sigmoid there are a lot of different types of kernels apart from that we also have gamma as the property or the kernel coefficient which is indeed uh which is actually dependent upon the kernel feature all right as i have told you i will not go deep inside svm if you want us to create a separate tutorial on svm please let us know wherein we'll be discussing in depth about all of this but for now you'll have to understand that this particular svm algorithm it contains few parameters which we will have to check and these are the parameters all right these are the parameters now with the help of grid search cv what we are doing is we are actually understanding whether that particular c it should be having the value from 1 to 100 or what what should be the value which is the best suitable for this okay and what is the best suitable kernel value from the for this what is the best suitable gamma value for this if the kernel is non-linear if it is say rbf what is the best suitable gamma value for this okay that is what uh we are using right now and with the help of that it will actually tell us the best particular variant for this the best particular variant out of the two variants which we have given and we will get the best value out of say 10 values select me the best one uh and give out the give me the output that is what we are doing here out of these two which is the best one please let me know and with the help of that only i will be fitting my model and i will be creating my machine learning model here okay that is what we do here and we get the output if you see here it has gone through grid search cv it has it has taken total a time of over say one minute and 49 seconds for doing all of this particular thing all right and okay what is this what can be given instead of svmc instead of svm there are a lot of algorithms as i have mentioned here lots of algorithms are there just go to scale on here and you will be able to see in classification you have got svm you have got nearest neighbors you have got random forest you have got lot of other things okay you can just check which and all algorithms you can use and how it performs okay math behind each and every algorithm is different you will have to understand that particular thing if you want to understand in depth how is it working for now we are taking svm i hope that is clear may manga all right so let's move on we know that we have got the correct uh we have built our model here now how do we evaluate it how do we check whether our accuracy is also working properly or not whether it is working fine or not so sorry for that why underscore pred is what i will write and then i will write say clf dot predict and i'm gonna predict for what i had taken for test okay and then i will type in your y underscore pred and run the code and the moment i run the code here i will get uh some one two three whatever values i have but then let us check whether it is correct or not if i type in y underscore test see this is our predictor output this is our real output and we don't know whether it is right or wrong there might uh there seems to be few errors here and there let us see how we can check that we can actually evaluate our model by typing say from sk learn okay dot uh metrics all right and then i can just import say accuracy score i will also import say classification not classification i don't want classification i'll just import say confusion matrix okay and now let me run this and let me take accuracy score here let me check whether the accuracy score is proper or not okay so why underscore test let me run this and i get the accuracy score of 96 percent that means out of the testing data whatever we have we will actually learn or we will actually get out of 100 values it will correctly classify 96 values maybe four values here and there it is predicting wrong that means whatever we have built is pretty good all right whatever we have built our model is performing pretty good here if i just type in your confusion matrix of y underscore pred comma y and score test it will act actually give us the output and it will tell us here uh i think so only one watching data i think so 10 plus uh 8 is 18 plus 9 okay so 18 plus 9 is 27 out of 27 values we had uh predicted all the values right except for one okay one value is predicted wrong so uh it's a very good uh project or it's a very good model which we have built for now that is what it actually tells us all right and definitely we can add up more data and we can check whether our model is performing good or not as well but then yes this is good uh enough for what we have done for a least amount of images obviously for machia building a machine learning model we need to train with thousands and thousands of data but then yes uh what we have done right now i would say that it is a pretty good uh job which we have done okay so if you see i just would let you know about confusion metrics confusion matrix is one of the uh evaluation metrics which we have where in all of our data points can be varied properly and checked upon whether we are getting proper output or not all right and if you see here the uh diagonal column from say top left to bottom right is what we will have to check right so if you see here eight values are predicted correctly ten values of second column second output are predicted correctly eight values of third column are predicted correctly although there is one specific uh image which is uh incorrectly predicted but then that should not be a problem right so in machine learning it's not always that you will get 100 accuracy what we have got till here is uh also fine i would say all right now uh how do we actually check whether our output is working or not okay so to check that we will have to use maybe you know real time images all right we will have to use real time images only when we use real-time images it will be all fine right so uh let us use the real-time image and check whether it is working properly or not for us what i'm gonna do is uh i will be see it took a little bit longer time for me to train the model so i will be saving save the model okay using pickle library all right so there's something called a pickle library which we can use to save our model so how do we save our model that i'm gonna import pickle and then i will type in say pickle dot dump all right and then clf whatever the model which i have taken right i will open and i am going to mention here say img underscore model dot p okay and then i will write say comma wb that means i am writing this particular model or i'm dumping this particular model now what exactly is pickle see i took a lot of time to train the model maybe you know gather the data train the model i'm saving this particular thing in my pickle file the moment i save this in pickle file what is going to happen it will be actually waiting for uh it will be actually making sure that all of the values or the model is actually stored inside it so that for the next time when we are using it will be really helpful for you okay so you can do that as well okay thundra uh we will not be talking about feedback link if you are here only for feedback link i would suggest you to please turn off the video and you can continue with your work okay we are here to learn something important and please don't spam okay you you are very well uh free to leave the uh say video and uh continue with your work please don't spam the uh comment section here all right i will be talking about video video feedback link at the end of the session only please don't spam here okay that's my humble request for you it is actually disturbing and annoying as well please don't spam it i would suggest you to please wait if you're waiting for feedback link more than feedback link i would consider you to pay attention to what exactly i am seeing all right okay so where is this pickle file and where it will be available if you see here you should be able to see in the left hand side there is something called as uh say img underscore model can you see your img underscore model dot p this is the picker link which we have here all right this is where i have dumped the value and with the help of this pickle link itself now i'm gonna actually address or i'm gonna actually load okay i will write model is equal to pickle dot load okay now one more thing why i am using pickle is because i will have to deploy this model so for deployment of my model also i can use this particular thing okay instead of re-running the code again and again i can just uh maybe you know write this particular statement okay and this will be really helpful and rb okay here i am writing the byte here i am reading the byte now that i have uh read the byte i will now load one model and let us check whether it is working or not so i will mention your flat underscore data because again the image whatever we are taking uh it should be actually going through the same procedure of what we had done before right so testing uh brand new image okay this is what i will write testing a brand new image is what i'm gonna write all right and then let me take image from say google all right url is equal to input is what i'm gonna write let me take your image from one specific this one it should not it's not necessary that i take from google i will is equal to binary values it will be 2 cross true okay we are doing it for multi-class right there are three values here one is of ice cream cone one is of rugby and one more is of sunflower so it is three cross three if you remember all right so yes true positive true negative false positive false negative what you're talking is absolutely correct but that is for binary classification but then we are doing it for the multi-class classification i hope you understand that okay so i am taking one url here i will read that the same thing i will do i will read that particular url and then after i read that url i will have to resize it first right so let me write resize resize is equal to resize off i mg comma and then i'm gonna mention here say same thing 150 comma 150 comma three okay and then afterwards i will have to flatten it so for flattening flat underscore data dot append okay and then i am gonna append the values whatever i get from img underscore resized dot flatten okay and after this is done let me type in here flat underscore data a flat underscore data fine so after this is done i will just print whether my value is converted or not so i'm gonna just type in your img dot image and if you want to check the output i am show plt dot im show of say img underscore resized okay i will show that one also and along with that now comes the output path right so y underscore out is equal to model dot predict okay off flat underscore beta flat underscore data and flat underscore data let me just type in here and afterwards okay wait sir your voice is not clear what happened one second okay i will show that one also and along with that no from my end everything seems to be fine please uh recheck your connection guys please reload it and uh let's see okay so why underscore out please check people finish internet connection seems to be fine please check okay let me type here categories because i want to do it with categories of y underscore out okay and if i type in here directly do not come because it will be in two dimensions so i will have to type here y of zero and then finally let me print okay so for printing i will use formatted string here and then let me type in here say predicted output okay so the predicted output whatever it is this will be in the form of y underscore out okay this is what i do and let me run guys let me run this okay what is this i have done something wrong here let me check all right it is asking me enter your url uh what i'm gonna do is i will open up say let me go to google and let me type in ice cream cone ice cream phone okay let me type in your ice cream cone let me go to images and okay there you go uh i will take say this particular image let me open it in new image and control c i will put it here okay i'm giving here dot jpg it will do all the pre-processing it should do and let me check so see here predicted output ice cream cone and we are getting it properly right this is actually an ice cream cone which we have this is the output thing which we have nathan i already answered your question i think so you're not paying attention to what i'm saying let me specify once again what exactly uh i mean when i say confusion matrix confusion matrix by default for binary classification it will be 2 cross 2 as you have mentioned but then for 3 values more than 3 values can you see here this is also a confusion matrix it's not necessary that it should be only 2 cross 2 it can be more than that also it is a square matrix that is the definition of confusion matrix if you are using for binary classification then you will have say 2 cross 2 values that means you will have true positive true negative false positive false negative value but then if it is for more than two classes see here this is for more than two classes say you have got three values here satosa versicolor virginica or in our case we have got three values right we have got ice cream cone we have got say uh rugby ball as well as sunflower so the confusion matrix is now changed it will become 3 cross 3 because it has to specify another few values right so it's not usually it is for binary classification where you get 2 cross 2 but then for this particular thing you have got 6 cross 6 i hope it is clear nitin sharma whatever you had asked me all right so yes this is what we get for ice cream cone i hope the ice cream cone is all uh fine so the next thing i'm gonna use maybe you know i will show you the output for rugby ball also let us see rugby rugby ball okay and then yes there you go let me take this and check whether it will come or not hopefully this comes copy and run this again okay rugby ball here rugby ball leather okay i am able to actually predict my output properly all right are you able to see that this is how we uh get the output all right so if you want to check for say sunflower sunflower i will take one sunflower value maybe this one let me check okay i think so this will not work because i would need jpg at the end let me check with this no this should also [Music] not work okay let me check with this no i want a value which can be actually secured okay so wikimedia let me just type in here media all right i think so this one let me check whether it is there or not yeah so let me check this one it is working fine or not pretty sunflower there you go and i get the output here right so pretty sunflower is the output which we are getting okay so it is predicting very well that is what i can say all right i'm taking live image here and it is in fact predicting very well for this all right so yes that was uh it about say the machine learning this one but then uh sir does it support only jpg no it supports any format okay but then you will have to take the image properly okay it doesn't matter which uh image you take at the end it is all normalized into that particular value so it shouldn't be a problem one last thing which i want to show you is the deployment so for deployment uh let me quickly write up the code here and show you okay so pip install i will be using streamlit for you know deploying my model and then for streamlit i should be using something called as pi ng rock okay and from pi n g rock import ng rock is what i will write okay because this will actually help me do all the categories of you know data what i want all right so now let it load all of the values if you have any questions guys you can please ask me and i will try answering your questions okay what is this one second azer we are getting some loading problems although reloaded it okay uh so please share the code notebook and data set pratyush please join our uh telegram group because the code will be shared only on telegram group so if you could join our telegram group then it will be really helpful please share the telegram group wherein we will be sharing the code okay are you going to share yes uh nathan you please join the telegram group i will be sharing the notebook link there all right attribute error yes yogesh i think so you have actually made some error uh in that particular thing see basically numpy doesn't have anything called as append you will have to check the code properly what you are doing you are actually appending it for a list okay append is the method for a list it is not for numpy array it is for a list all right so yes the telegram group link if you want you can please check it in the comment section uh or else let me post it out let me post it out i will be sending the telegram group link just give me a moment so if you go to say youtube uh if you go to our diazonic labs channel here one second okay just scroll down and you should it is not available inside this one second just so we'll be i'll be posting telegram grilling in just a moment uh so let me post the telegram link onto the group itself and it will be easy for you and yes uh so it should have been there okay it's not there in the description of our video not to worry but then yeah it will be there uh let me send you the link there i have posted the link onto the chat box so please check with that this is the link for telegram and uh please join our telegram group i will be posting the link of the notebook as well as the feedback link there itself okay please join our telegram group link and yes the link for feedback will be posted once the webinar ends it will not be posted right now okay it will be posted once the webinar ends okay and uh it will be open uh for quite some time you don't have to worry about it all right it will be posted exactly at say 1 30 so please make sure that you join the telegram group and i will be uh extending the session for some more time uh for showing you the deployment okay so the uh project actually ends here whatever we have done but then i will be extending maybe you know i will take another uh 15 20 minutes to actually show the deployment of model on streamlit if you are interested please do uh stay okay or else the feedback link will be shared with you exactly at 1 30 okay it will be shared in the comment section as well as in the say of telegram group okay so any other questions guys if you have any other questions regarding the project please ask me or else we will continue with our upcoming deployment okay so okay i want you guys to tell me if uh type in yes if you want the deployment if you want the deployment session deployment of uh you know this particular thing on streamlit type in yes just type in yes if you want the deployment if if you want me to cover deployment yes okay no problems risky no problem all right so let's go ahead and learn about deployment how this deployment thing works now first of all you'll have to understand the definition of deployment deployment is actually one specific term for making sure that your product is uh well built or whatever you have done the coding right it comes out in the form of a product all right so uh for deployment you have number of options all right i'm gonna mention a couple of them and i'll tell you which am i using okay so let me type in here deployment so for deployment you can have either a web page all right this is the first option the second option is web app all right and then the third option what you have usually is a mobile app all right these are the three options which you will have okay so with the help of this particular things you will be able to actually uh understand the whole concept of say deployment all right how one specific thing is actually uh understood or how it is deployed or how a product is created from this particular code whatever machine learning code we have built if you see here i have built here a machine learning code right and i've stored it in pickle file okay and i think so it is how much 25.75 mb okay so i have got here my pickle model i will reuse this pickle model and i am going to show you whether this particular thing is working or not okay so how do you do that now to do that uh we will be using web app here okay because streamlit is actually useful for building web apps uh here you can use say up for building a webpage you would need html you would need say css you would need say javascript along with that you would also need say flask in the backend flask or django in the back end all right now for creating a web app you can create web app using flask also but then uh the simple one is streamlit we can create using streamlate alright there is something called as dash there are a lot of things which you can use we are for creating mobile app you need to learn about kotlin or you need to learn at least about java all right but then the simplest one i would again recommend you to start with is web app of using streamlets so we will be building a streamlit application here all right so how do we build a streamlit application is now uh what we will see first thing is for streamlit you would need a separate python code that means whatever you will be writing you would be converting it into dot app dot py ap dot py is what you need and along with this you would need some other uh libraries you would need streamlet library along with that you would need say pi ng rock what is this pi ng rock i think so in the previous session i have specified if not you can please go back to my previous sessions video and you can please check it out it is already available here uh you can just check here okay so turn your data script into website using streamlid this is the this is the video which i had created i think so it was uh streamed on a month ago you can please check more on this anyway so uh i will be using or using a tunneling site called as pi ng rock for that particular thing all right okay now how do i create anything how do i let me create a simple stream late model here so i'm gonna import uh say streamlet as st okay this is what i will write and afterwards i will just write here say one specific statement st title okay and then here let me write say image classifier okay just let me write image classifier here okay i have not added anything because i will do this all of this thing whatever it is that little while later i'm just uh making sure that one particular uh file is created okay how do i create a py file from this we will be using magic commands percentage percentage all right and then afterwards we will have to use in here say right file okay and then you'll have to write say app dot py okay this is what we use write file app dot py i'm gonna write one specific file where in the name of the file is app dot py okay from this particular cell okay this is what is going to happen all right so let us see whether this is working or not let me just run it and the moment i run this see here writing i have dot py that means here you will actually get app.py as your file now how do you run this to run this particular thing okay you will have to perform a couple of things the first thing is you'll have to type in streamlit uh app sorry run app dot i want to run this in background so i'm gonna mention uh ampersand here so that it runs in background and then i will make sure that it is giving uh one specific command called as no hub what happens with the help of this is it will run in the background without any problem if you want to maybe you know change something here you can change it and you can retrieve it on the deployment page also all right and as i have told you you would need a url so url is taken through say ng rock tunnel okay so i'm gonna type in here ng rock dot connect okay and then i will mention here say port is equal to uh by default port number is 8501 and let me run the url here okay let me run this and with the help of this it will tell me that it is appending the output to no hub just wait for a while and it should actually give you ngrok.io terminal just copy this and open it up in your new file the moment you open this okay you should be able to see you should be able to see something like this all right uh see here image classifier the output is given here okay and if you want to change this guy see the problem with google collab is you can run only one specific uh say cell at a time but then since we are running this in the background right we can run it as much as uh we want so imagine i will write here image classifier using machine learning okay using machine learning okay and then let me run this here it says overwriting app.py reload this all right just reload it and it should actually give you the output can you see here this is how it comes now here we will actually put few things we will have to put few things uh first thing is maybe you know we will have to do all of the things whatever we want our image classifier to work upon right so let us see one by one of that particular thing no this particular thing is unique for ngrok server so it's better that you specify the same port number which i have told okay so yes avinash please fill the feedback form and you will get that okay so afterwards uh can't able to join telegram okay please check i have given the information for that all right so i will be posting the feedback link now but then as i have told you the feedback link will not open okay feedback link will not open up until the session end session will end after say 10-15 minutes so the feedback link will be just put up for your reference it will open up only after the session ends okay so please make sure that you wait and please don't ask the questions that this feedback link is not working it will work only after the session is over let me repeat feedback link will work only after the session is over okay so time for learning the deployment and i will not be answering anything related to feedback now okay i will answer that a while later even if you post questions i will not be answering let us complete this particular thing first all right so uh again the library is what we need here let me just go up and copy all the libraries from this particular thing i would need all these libraries i don't need matplotlib i believe okay i would need these three things let me copy it and paste it here okay i think so people don't pay attention to what i'm saying again the same reply is not opening yes yes the link will not work i think so you didn't listen to me and i would not answer that particular thing right now let me complete this guys guys please don't spam please don't spam uh you will have to concentrate first what i'm saying only then you will understand what exactly i'm telling okay uh numpy is there i am read is there and then resize is there uh okay so after that we would need to import pickle library so let me import pickle and i will import one more thing called as pil import image okay these are few of the libraries which i would need and afterwards here let me type in say st dot text all right uh upload image okay this is what i'm gonna write let me run this guys and check whether we are getting something or not okay so image classifier yeah upload the image we are getting okay now uh i am gonna put one option for uploading the image right so how do i put the option for uploading the image i'm going to copy say model dot uploaded file is equal to sd.file uploader choose an image and i'm for now selecting only jpg okay i don't want anything else and then let me type in here say model is equal to because i want to load the model uh all right so i'll just copy and paste this same thing from here let me go up okay so this same thing is pasted here fine so i'm pasting the same thing here and afterwards if the file is not uploaded what is going to happen let me just type in here now if uh uploaded underscore file okay is not none so if it is not none then what should happen then i am gonna call for img is equal to let it just image dot open that means it should open up one specific image of say uploaded underscore file okay this is what it will do and then it should just print out that image right so if you want to print out that image you can just type in say st dot image of uh maybe you know img as it is okay without any change in maybe you know size i'm putting here and then caption let me put say uploaded image okay i've uploaded whatever the image i want to upload it is uploaded all right this is what i'm gonna keep for now let us see whether we are able to upload the image or not let us see whether we are able to upload the image or not let me go back let me refresh this and okay here i get file uploader encoding warning this is just an encoding uh warning which we have we can just maybe you know copy and paste this and it will go all by itself this should not be a problem let me just copy this okay but then yeah if you scroll down here here you will get one specific image to be uploaded just go to browser and download maybe you know sunflower it is there let me check whether sunflower comes up or not okay uploaded image it says and see here the sunflower image is uploaded all right this is what we need to do and we have uh successfully done that particular thing all right but then now comes the prediction now comes the prediction also okay so let me check how we can actually predict it so i'm gonna give one specific say condition if ht dot button i'm gonna take a button here st dot button okay off let me type in here predict if i type in predict what is going to happen if i type in predict here uh i will have to do the same thing what i had done before here right so let me copy this again from here till here okay ctrl c copy down and paste here so i will have to make few changes here what are the changes let us see first thing is uh image dot resized is what i need but then from where do i get img img if you want i will have to type in img is equal to okay np dot okay i think so imv i have already taken let me convert it into array first img i have taken here here this is the img right imp value whatever i have taken okay np dot img uh np dot area of img i have taken okay but before that i will have to take flat array right so flat underscore beta is equal to open and close okay and let me mention here something neatly st dot write off okay i can maybe you know type in say result what is the result let me just type in here result okay uh this is fine the size has been done and then okay categories okay because here categories is missing i will have to specify categories from the beginning let me just go up and check for categories because i have missed categories there let me copy it since i'm writing it separately onto one cell it is just like writing a complete different program okay so let me type in here categories and uh model dot predict of categories hopefully this is fine uh okay model dot predict of flat data and then it will actually tell me what exactly is the output right so why of out it should be done okay this should be fine let me overwrite this and let me check run please wait okay and click on browser here let me put up this and okay click on predict it should give me okay what is this plt is not defined it is saying okay wait where have i written here prt now plt i don't want plt delete this we run it and let me check result okay let me rerun this browse files uh let me put ice cream cone for now okay uh scroll down predict okay wait it is just showing me predict it is not showing me the output of it i think so insta yes uh this is the problem right so here print will not work i should put st dot right just give me a moment st dot right and now it should work sd.write and predict there you go predicted output ice cream cone okay uh i can write it as title title okay hopefully now you should get the proper output okay see here uh predicted output ice cream cone whatever you put like maybe you know now you can use it for putting a sunflower and let us check whether it is giving us the output or not sunflower predict pretty sunflower okay so it is not uploaded but then yes i hope you understand the point what it is there okay so next thing i will put one ball rugby ball do i have a rugby ball here okay i can't see fine so let me download a rugby ball and save it let me check whether rugby ball is working or not browse and rugby ball okay i'm uploading here and there you go rugby ball predict rugby ball leather it is predicting properly all right you will get the output here and one last thing which i want you to understand is if you want the percentage also of say how much of percentage is this how much of percentage is that you can actually check it out for yourself okay so i have just added here a small code okay which will uh help you understand what exactly is the percentage of it okay so let me run this and let me show you so when i browse say the ball itself okay and when i click on predict see here it will tell me predicted output as rugby ball but then it will also tell me here 87 percent it thinks that it is rugby ball five percent it thinks that it is sunflower eight six percent it thinks that it is ice cream cone all right all the three things the probability i have used here and i'm getting the output all right if you want other this one let me go back to say sunflower here i will upload this sunflower okay wait let me re-run this and let me upload sunflower and let me check so sunflower i'll upload and see maybe the sunflower can look like uh say ice cream cone little bit let us see here the output what you are getting for sunflower is 54 percent it looks somewhat similar to ice cream cone right see here it is looking like a cone and all of it but then yeah it looks like that and 32 percent uh model things that it is this particular thing okay okay what will be the output if you have something else instead of this as i have told you it might give something else it might it will actually give the most familiar this one okay let me just run this and show you all right i will take something different for now okay so browse file is what i will do and uh let me take a ball okay let me take a ball let us see how does it look like all right does it look more of this one it will give you the percentage of how much this one is how much this one is and how much that one is so let me predict it see here it says 87 85 it looks like ice cream cone okay this looks like ice cream cone the machine learning model all right uh nine percent it looks like sunflower five percent it looks like rugby flower okay this is what it does all right i hope you are understanding pratik what exactly is this you can play around with this and definitely you can improvise on this particular thing as well okay you can build uh fundamentally a lot of other things as well whatever it is there so yes this was a quick exercise guys or a quick understanding of how you can take your model and how you can deploy it and uh this particular thing this app will stop working the moment you close your uh google collab so if you want to upload it on any of the cloud services you can do that you can feel free to do it on say aws uh or else you can do it on say microsoft azure or else you can do it on say google cloud platform or else these are all paid ones you can either do it on hiroku which is completely free uh web service for you okay so you get free hours of web service free uh web or let me call it as free platform service or deploying okay and it will work always and i've already shown you how you can deploy that on heroku also you can see our previous video for that particular thing and that should be really helpful all right so yes i am gonna stop the session right now and uh if you have any questions you can please ask me we have got up on our upcoming session okay uh we have got something called as image blurring app using opencv uh please register for this okay i have not put up the registration i will put up the registration link as well as soon as possible please register for this we will be learning something uh about opencv in our upcoming session okay we'll learn how you can uh use it for blurring we will see how we can blur one specific photo and all of it so if you are interested for this please do register for this subscribe to our channel and i'll see you guys in the upcoming session okay so is this session recorded yes the moment our uh training the moment i stop the live video the particular thing will be there and i will also post the link onto the telegram group if in case you want this particular thing okay increase your video quality it may work okay thank you for that uh what will be the output okay i think so i've already told you already liked your video uh the first lecture that follows the title thanks a lot yes it will work uh so can you demonstrate with a different image shape yes so i can do that also as i have told you okay let me take something different maybe let me check if i have anything okay i'll take up say maybe you know this people it will give you something uh outside like it will tell me that uh based on these three things how my model is predicting is what it will tell me see here 55 percent it thinks that it is ice cream because i think so of its round shape or whatever it is and then 33 did consider that it is a sunflower and 10 percent it considers that it is a rugby but then this doesn't matter right because we have not trained our model for all of this all right we have not trained our model for all of this we can make our uh machine learning code much more intelligent by using deep learning here all right if you use deep learning here then we can actually use that particular thing okay if we need to predict two things parallely yes we can do that ramesh as well uh whatever we want to do so that would be called as object detection what we are doing here is not object detection it is just an image classifier the complete image we are classifying we will have to learn about object detection wherein you know you will have to check how many objects you have and you will have to term what exactly is that particular object okay that would be a very good uh session also we can doing uh doing something on that as well okay that would be completely different i mean the uh concept what we will be using for object detection is completely different here we are just detecting the image what we have all right i hope they understand that okay guys uh thanks a lot and uh the feedback link will open up once i stop the live streaming and you can fill in the feedback form for this particular thing all right thanks a lot again and i'll see you guys in the upcoming session okay yeah bye you
Info
Channel: Diazonic Labs
Views: 62,011
Rating: undefined out of 5
Keywords: image classification in python, image classification using svm, svm algorithm in machine learning, svm machine learning, image classification using tensorflow, end to end data science project, image processing using python, grid search hyperparameter tuning, support vector machine algorithm, streamlit image classification, deployment of machine learning model, create webapp using streamlit, what is teachable machine, image classification using streamlit, deploying ml project
Id: dw96S_iFFbI
Channel Id: undefined
Length: 148min 42sec (8922 seconds)
Published: Sun Sep 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.