Image Classification Project in Python | Deep Learning Neural Network Model Project in Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi all welcome to kite Channel let's take a look at the image classification model which we are going to build from scratch so here is our final project of image classification model so here it takes the image name as an input which are there in this folder here and it will identify whether it is a fruit or vegetable with the here it is saying V of fruit in images apple with an accuracy of 99.95 and let's go here copy for banana and go here and change the name banana so it is displaying the banana image yeah fru in image is banana with an accuracy of 46.9 one let's take another one chili okay Center yeah so vent fruit images paprika with an accuracy of 100% accuracy okay that's cool let's go to Google and search for cabbage some other things yeah images cabbage cabage and I'm saving this image cabbage just have to Cabbage changing home copying this image and coming here and yeah imagees Cabas with an accuracy of 8.46 so this is our I classification model works first things first we are going to build image classification your network with the help of the tensorflow caras so tensorflow python library is developed by the Google it will work like a AP interface we just have to pass the valid arguments to the functions of the tensorflow that's it it will take care the rest of the business usual stuff every model needs the training data set and test data set in addition to that this tensorflow model which we are going to build here is sequential model for this one we are going to give another data set which is called the validation data set so why we are giving this validation data set is sometimes what will happen is when we train the model on the training data set it will be fitting the only particularly based upon the values and the training data set in real time it may not give the accurate results because training data set and reality data set might get differ so our model completely relies upon the training data set So to avoid that issues in the real time what we are doing here is we are caring another data set which is called the validation data set so here we are giving the validation data set as well to the model when it is getting trained right so what exactly happens is when model is getting trained based upon the training data set at each and every step it will validate its results again it's this validation data set as well so that our model accuracy will be increased when the model is creating itself so that will give the highly accurate results in the real time so once we train our model then we'll be doing the testing so testing will be done with the completely new images which we found it in the Google here so we will try we will test our model with the Google Images so once we do the testing of our model then we'll be deploying it as a web publication as you guys seen in the earlier video so now let's start with the coding so here I have created a project called image classification folder here inside this we have the folder name called fruits and vegetables inside that we have three data sets one is test data set and another one is train data set and another one is validation data set so each and every folder inside this folder we having the subfolders with the name of the fruit or vegetable which we are going to have so let's take an example of Apple so inside of this Apple folder it contains the images of the apples and cabbage same thing similar to that so we have eggplant garlic ginger grapes kiwi lemon mango onion orange so similarly if you have 36 36 items total here so 36 items of fruits or vegetables we have taken it as a test data set and similarly we have the training data set and here we have the validation data set as well here okay so don't worry about this guys this data set I will be giving this data set link to the in the description box you guys can download it there and now let's start with the coding uh opening my Jupiter lab command. exe and typing Jupiter lab so our jupyter load book is ready now let me create new one and let me rename it as image classification model okay here we need couple of python libraries which you want to install when you are running it for the first time in your system so open command prompt and type in PIP install we need tensor flow here and tensor flow and stream L to defy as a web application and M plotly to draw the some charts and n and pandas as usual so if you're running if you're using these libraries for the first time in your system just type in PIP install on the python Library names and hit enter so these python libraries will automatically install in your system I'm not going to installing here because I already have them now let's start with the coding okay import nay as NP and import pandas s SPD and import M plotly do pip plot as plot and what else we need we need Tor FL as well right import tensor flow SDF and from tensor flow import caras okay from tensor flow. caras we are going to import layers okay from tensor flow what else we need we have layers and um K us I think we should be good now okay let me import okay it's getting imported so now the next important challenging part here is so we have the data set in the form of the folders right so we have to load this data into array right so we have to let's do that into n array so what I'm going to do is we have a built-in function in the tens of flow which will do the needful for us okay what we have to do is we have to pass this folder names then it will automatically create a data set on top of that okay so let's take some parts here to be created and first is data uncope training path and what is this training path let me go here this is training copy path simp similarly data uncore train uncore test data is equals to same path just changing it here as test and data uncore train uncore validation data set is equals to same thing and I'm renaming it as validation okay now we have the paths and the next step we have what we have to do here is we have to set our images in a similar size okay so it's image will be having in different dimensions right so but here we are going to fit all those images into in a fixed fth okay and fixed height so image width is equals to 180 and image height is equals to 180 okay we have said that now so so now we have the data set but data set is in the form of images and that images are there in the inside the folders We cannot try our model from the dis right so what we have to do is we have to bring the data set into the form of arrays so what we are going to do here is so we are going to use the one of the functionality which has provided by the tensor flow load from the disk okay so let's do that data uncore train is equals to TF do K so I already explained right so tensor flow works in the APM interface right so we have to identify the our job here is to identify the proper function and we have to pass the proper arguments to that function then it will do the needful for us okay so here we have to pass TF k. utilities do oh sorrys dot you see here these are the list of the functions so but for us we need image data set from the directory so what it does is it will lead the data from the disk and then it will load it into the form of this data and scorr array okay so first argument that we have to pass it here is the path of the data set so here is data planning path and next one is Shuffle yes I wanted to shuffle my data set true okay and we have to recycle images right so image size is equals to image width comma image height right so then we have to pass the path we are shuffling our data set from the directly and image set we recycling all the images to 180 versus 180 and then batch size is equals to and yeah Comm is equals to 32 images and the other one we have to do is validation spit so why the validation split what it does is so if you're giving if you're having only one data set it will split the data set into two parts one is the training data set and another one is the validation data set here we have already split the test data set and validation data sets right so I'm passing it as a false otherwise we have to pass it as a true so press enter so it gives a message that it had rate 3,115 files which are belonging to 36 classes so we have 36 types of the fruits and vegetables in the folders and out of those it found 3,115 files okay now let's see type that what are the different types of fruits and vegetables which we have okay let go train T here class names okay so these are the different types of fruits and vegetables okay which we have so I'm loading it into one data set data uncore category okay now we have done it for the training data set now we have to do it for the test data set and validation data sets okay okay let's do it then again data and score validation is equals to TF K start start image data set from directory data and score validation and score path and image size is equals to image height image width and and bat size is equals to 32 and Shuffle I'm passing it as false because it is validation not it and finally validation split is equals to [Music] false data okay I made a mistake here what I have to do is training test okay data on scope okay okay I made mistake here data and scope test path and data score validation path given the wrong names re executing all the steps okay here yeah it's done so it found 351 files which are belonging to 36 different classes in the validation data set okay so now we have the validation data set and we have the training data set now what we have to do is let's do same for the validation sorry test data set as well data on score test is equals to TF K utilities so what we are doing here is uh again path data uncore test uncore path comma and image size is equals to image height and image width okay and Shuffle is equals to false and what else batch size is equals to 32 images per batch now validation split is equals to false so even here also we have 359 files which belongs to 36 different classes now we have read the data from the disk to data sets into the arrays okay training data set and validation data set and test data set now we have the three data sets okay now what I'm going to do is let's print some images from the training data set okay and what I'm going to do here is plot. figure of fix size is equals to 10 comma 10 okay and for image comma labels in data and score trying dot take of one okay and for I in range of n okay and what we have to do is let will sub we be printing nine images right subplot of 3 comma 3 comma I + 1 now plot dot image show okay uh image of I do npay do as type of type of an identified integer okay now plot. title of data and scope category of labels of I so we are printing the images along with this labels okay something is wrong NP throwing error message let's check it out what is the issue tensor flow. python framework option hm okay uh let's off the AIS so here we have nine images right so sweet corn grapes cabbage and ginger orange pineapple chili peer jalapeno and banana so this is how the images along with the labels okay now we have the data set is ready now what we have to do is we have to create a model first right so here we are going to build the sequential model okay and model is equals to sequential and okay and what we have to do is we have to pass the layers we have to create the layers right so layers start first I have to do is recycle I will do so every image will be stored in the form of data set in the sense it will be divided into three colors one is R GB red green and blue so every color in the world is a combination of the colors of RGB red and green and blue so these images will be stored in the data set in the form of RGB so each and every color will be stored in the from red green and blue in the form of right so the maximum value for the each color red and green and blue is 0 to 255 so maximum value is 255 so I'm going to divide this with the 255 so everything will be between the values of the colors will be zero and one okay that's what I'm doing here uh it is not showing let me do one thing I have to import this uh model as well uh let me do that first so whenever it is not giving any suggestions means you have to go through that and you might be missing some variables input okay from TF do gas. models import sequen sh okay uh T of FL right TF okay uh let me in here t okay we have the sequential now yeah if you see here race scaling have to do that and like to divide each and every color with the divided by 255 that is the maximum number right so I have create I'm doing the recycling now in the model and Next Step I'm going to do is let me add 2 come 2D so it's a 2d will convert that so we have having three colors right 180 by 180 right so it will be converted into only 1D okay and image width and height right so before that let me show you something here okay let me print data scope TR if you see here it is 180 180 and 3 so this 180 is a pixel of the height and 180 pixels of the width and this three is RGB red and green and blue right so what I'm doing here is this Con will do that this Con will convert this 180 into 18 single one and then the next one will be the combination of RGB okay so for this one and then this will be layer as well okay and I'm creating 16 units neurons and Canal size will be three and padding is equals to same and we need for every here we need the activation right so your activation is relo okay so don't worry about this terminologist guys I'll be making a video in my channel on this caras models and how to do this passing of activation and everything so completely I'm making a video on this uh how to make the CNN models with the caras okay stay tuned for my channel if you haven't subscribe please subscribe to my channel and please enable the notification as well so you will be getting the notification whenever I upload any videos and here we have created con Tod now we have be doing maximum ping right Max poing 3D Max poing 2D and what else we have layers do so we have to create multiple layers right so I'm doing that 2D and here we have given there 16 right so here I'm going to give 32 neur and three same and padding is equals to same and is equals to re okay it is very difficult to remember all these things so that's the reason I'll be going with the suggestions okay if you get if you click on the tab in the notebook it will be showing the suggestions okay and Max Ping 2 okay now layers dot this com 2D uh layer output will be input to the max pooling 2D okay and again this is one layer and here we building another second layer okay con 2D and here I would like to have three more three sorry 60 count to and 64 three and padding is equals to same oh oh and activation is equals to Rel okay now we have to close this layer with Max po right exping so now we have created three layers and what I'm going to do is I'll be flattening my data set okay flattening my layer next what I'll be doing is I'll be having the drop out so 0.2 and I'll be having my dense layer dense 128 units and layer dot dens of units equals to so we are going to have 36 units here right so 36 different types of categories are there okay so length of data score category okay rescaling is done drop out is done flattening is done dens is done maximum pulling is done so pressing enter layer not found okay I just typ it as layer have to change it to layers okay our model had been created now we have to do the compiling of model right so model dot compile of compiling we have to pass three arguments one is Optimizer and here I'm going to have Adam and L is equals to DF do K start it start oh where guess loses Dot here we have to choose category class entropy [Music] from is equals to correct true and Matrix I would like to have is a accuracy accuracy okay so compilation of our model also done now let me print the summary of the model oh it is telling model as in buil so we have to pass the variables first right so let me pass the variables first uh model do fit off and here how many box I would like to have 25 box okay and history is equals to model. fit of um data uncope training data set and here we have option of validation data is equals to data Val and epox is equals to epox and batch size we can give here batch size is equals to 32 and webos I can give S one okay let me remove this one have to pass units here and here should be category okay PA category CR entropy changing them okay and yeah maybe just ring them B say anyway we have given here let me remove that stuff over here okay and let me do shift enter OKAY model is done compile is done now fix it yeah now it's working so maybe I should not be giving units here so we have to just pass the length that's the mistake I have done and I'm removing this so so let's see what we have done so far so we have imported necessary libraries here and we have created a parts for the each and every data set train data set test data set and validation data set and we have scaled all the images to the width of 180 and height is equals to 180 and we have read the data from the directory to the data sets training data set so in training data set we have 3,115 files which belongs to the 36 classes and category here we have taken it into one list and same for the validation and same for the test and here we have printed the random nine images from the training data set and we have created the sequential model here so with the rescaling so as I said earlier each and every image will be stored in the form of the data set with the combination of RGB colors and maximum of color from 0 to 255 the range so I'm rescaling that every color to in between 0 and one so that's the reason I'm dividing it with the 255 which is a maximum number and I'm creating the layers three layers with the combination of con to and maximum pull maximum pulling of 2D and one with the 16 neurons and another one is 32 and another one is 64 and activation is Rao I'm using here and I'm flattening the data here and drport is 0.2 so drop will be used to uh make that model is not overfitting and we have the dense okay dense with the 128 layers and here we are passing the 36 categories right so we are passing that length of 36 so we have to have the data will be classified in the 36 categories and here we are using the optimizer as ad and loss is equals to K Los passal entropy and we are printing the accuracy as well so if You observe carefully here so this 98 will be batches right so if you divide this 3,00 115 divid by 32 it will be coming around 37 batches 37 point something so it has taken 38 batches so for every EPO so for the 25 EPO so it will be running for the 98 batches and it is nearly taking one one and half minute 1 minute closely 1 minute for the chok and if you see here the loss is 3 3.47 and accuracy is 0.09 which is for the training data set and for the validation data set the loss is 2.4 and the accuracy is 0.3 okay so if you see here closely this accuracy and validation accuracy both are getting inre increasing for each and every EP so it has to repeat for the 25 box right so let's wait for some more time okay finally our final epoke is also completed so total 25 oks are completed and if you see here the accuracy in the first the first oke was 0.098 for the training data set and for the validation data set it is 0.34 just 34% if you see here it's keep on increasing based upon for every EPO and finally it had reached the maximum of 95% and the accuracy is around 98% of the training data set okay let's draw some charts between the training accuracy versus the validation data set accuracy okay for that um aox range is equals to range of equals to range of um epox size okay and now let's try a graph plot dot figure off fix size is equals to let's take it Comm eight that should be fine now plot. subplot of and let's try subplot now and comma 2 comma 2 plot Dot Plot of um plot. plot of a box range and um [Music] [Applause] oh history of um accuracy right so make accuracy okay and label is equals [Music] to this is training accuracy okay and plot. plot of box range comma history dot history of validation data sety and um label is equals to validation accuracy okay now do show wait plot. title we have to give it as um accuracy okay let's draw same for the last as well okay I'm just copy pasting okay comma 2 comma [Music] one plus okay okay find plot here if you see here so initially it started around 0.04 but it now finally reached almost 97 98% that is fine and even though if you see the loss here ear it was 3.5% 35% at least it had been reduced to at least 0.0 to 0.05 so that is fine okay our model is doing fine now let's take one sample of example of images and then let's see whether the model is predicting properly or not okay first I'm going to the here test data set I'm copying um yeah let's take this apple image classification here I just rename it as apple and test data set let's copy con copy this one okay con and um yeah this two and let's go to Google and then take some pictures over there let's take banana okay just okay okay let me take these ones okay save image python IM classification okay this is a VP file no okay we need JPC files yeah Pon image classification okay banana okay we have banana now now what [Music] else paa paa let's take some pepper okay so now we have enough images now let's start with one image at it okay image is equals to I'm going back copying Apple firsty part okay we have taken image PA now okay so once we take the image we have to print it as a image equals to TF do k. till start load image okay we are pausing the image path and Target size is equals to image height comma image width okay Mage is ready now we have to convert it into array okay TF do k. sorry image array let's PA this image and image dimension image batch right we have to create batches right so TF GF let me just check it out c yeah expand dimensions image array comma zero okay it's ready oh showing some error has no attribute [Music] image AR to image okay to image image okay that is fine now we have to pass it to our model right so predict is equals to model dot predict of image and B final image so our mod had predicted it in 117 milliseconds really fast now we have to find the score score is equals to TF do NN dot um soft Max of credit okay let's print printable R in images okay with accuracy of okay format of let's format it up uh data uncope data uncope category of uh np. argument Max of the highest one right SC and comma um MP do Max of score into 100 okay should work parenthesis does not match incomplete input okay format closed print and should be closed field value [Music] error h v of routin image is apple with accuracy of 99.95 yes it is Apple Man correct model is predicting now let's set for banana oh banana with accuracy of just 46 seems like our model got confused let's check for chile CH L paprika correct with 100% accuracy that's cool maybe this image might be part of our training at validation data set that's what I'm suspecting oh con sweet con with 78.9 that is also cool let's build the web application so to build the web application we have to save our model right so let's save our model model. save of what we have to do um image classify do Kos this is the model name and I'm saving this model if you see that our model had been created now we are done with the Jupiter lab now let's move on to the visual studio for the web application okay okay now here we are with the digal Studio opening the folder yes this is the folder python image classification selecting the folder okay now here we are let's create the app appp okay now let's spell the application import t as TF import from tensor flow. k. model inut from kasas Str of FL input kasas from pens fl. caras do models import models import model okay now what we have to do is um stream lit right import stream lit will import it later so now let's import the rest of the model and everything okay model is equals to what we have the [Music] model load model here is the model copy path okay we have p model some typos now have to read the image right so image is equals to just copying this image by default okay copy the path and here we have the rest of the code right let me copy from here to [Music] there okay and anded it okay prediction is [Music] done okay now we have everything so we don't have data category so this is what we have to do that we have to copy the complete category so so we cannot get those class names from the model here now so we have to cap it manually so I have printed it somewhere in the starting okay here let me data scope C so here is the list just copy pasting okay data categor is done image withd and height have to give Min image score height 180 and image we is equals to 180 turn and here is the image is equals to image okay and and uh H print now let's take stream lit import stream lit as SD okay and here what we have to do is SD do image of image image load okay changing it okay here we are printing the image and instead of here St do right okay saving it and yeah run in Python dedicated terminal see for any er something is coming load model is coming as a unable to find file oh sorry just copy here to copy this one closing itting okay okay it's running fine NP okay as import NP okay we are done now should be good okay now I'm just taking stream rate run app. okay our model is running NP is not defined let me go here I have defined it same okay okay uh here we have printed let me just tweak this code little bit okay let see if I can do this okay let me run okay it's coming image is not printing because it is taking whole image here s right just with accuracy of accurac [Music] of Max score okay here [Music] rerun Max score 200 [Music] okay is it Apple np. Max of score into 100 that's what we have been using here [Music] right saving it rerunning it okay it's a string I have to convert it into string so now run so now our model is ready so it's printing the nums and yeah Ed fruit and image is apple with the accuracy of this one so I have to print this image right let me do one thing if I take only apple is it working H okay it's simply working we just take the image name here okay apple.jpg banana. jpg it will be working so what I'll do is um instead of here st. text input enter image M name comma and so by default it will be having apple. jpj okay so here is the final project looks like so uh just add one thing here s. header okay uh header as um st. header image classification mod okay I'm just saving it so coming here I'm just going here [Music] run okay just putting it top so here is our final project of image classification model so here it takes the image name as an input which are there in this folder here and it will identify whether it is a fruit or vegetable with the here it is saying V of fruit in image is apple with an accuracy of 99.95 and let's go here copy for banana and go here and change the name banana so it is displaying the banana image yeah fru in image is banana with an accuracy of 46.9 one let's take another one chili okay Center yeah so V fruit imagees paprika with an accuracy of 100% accuracy okay that's cool let's go to Google and search for cabbage some other things yeah images cabbage and I'm saving this image cabbage just have to Cabbage sanging home copying this image and coming here and yeah images Cabas with an accur of 8.46 so this is our R classification model works thanks guys thanks for watching this video if you guys have any questions please do comment in the comment section if you like this video please do like and subscribe to our Channel
Info
Channel: KothaEd
Views: 21,732
Rating: undefined out of 5
Keywords: Image classification project in python, Image classification deep learning Neural network model project in python, image classification using cnn tensorflow project, deep learning projects in python, machine learning projects in python, Fruits image classification project in python, Vegetables image classification in python, python deep learning projects, python machine learning projects, deep learning, machine learning, python, cnn models in python, python web projects
Id: V61xy1ZnVTM
Channel Id: undefined
Length: 54min 0sec (3240 seconds)
Published: Tue Oct 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.