Data Science & Machine Learning Project - Part 4 Feature Engineering | Image Classification

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the last video we looked at data cleaning where we created this crop folder which has faces cropped from all the images in this video we are going to talk about feature engineering a technique called wavelet transform that can be used to extract the facial features such as eyes nose and lips etcetera at the end of this tutorial you will have X&Y data sets ready which you can use to train the model in the last tutorial we wrote the core till this point where we created this cropped folder which had all the cropped images so just to show you once again see lyonnel Messi's face similarly Mario's are opposed only faces and we also manually deleted bad images so what images are now all clean now we are going to do a wavelet transformation on these images now wavelet transformation allows you to extract the important features from your image there are other feature extraction techniques as well but if you read image processing literature wavelet transforms are often the most effective way of extracting features now I'm going to show you some functions so this is the wavelet transformation where you input an image and it will perform the wavelet transformation on top of it using P ywt pi wavelet transform library and it will return your new image that is your wavelet transform so the way it's going to look like is this so this is the original image so let me show you the original image which is this - our oppose image okay this is a colorful image when I do wavelet transformation it looks something like this now this for computer is a very important image because it shows lot of features you can see the area of I is differentiated from the area of the forehead the news is visible etcetera so this almost looks like a black-and-white image and those important features such as nose lips eyes are extracted using white and black color see for a computer this kind of detail is very very important for doing face detection because when you have image like this which is colorful it can have variety of shades and variety of colors and it becomes really difficult task for a classifier to identify such an image now when I threw in this function you might be thinking oh you are just showing us lot of complex code and we don't know what's going on look I understand that there is some math involved there is some signal processing involved and for that reason if you want to dig deeper you need to pause this video you need to get your concepts on signal processing clear you need to know what is frequency domain what is time domain what is Fourier transform for this I'm going to point you some resources the first Resource is Iman's YouTube channel Iman is a good friend of mine on my request he created this tutorial where he explains how you can represent image as a frequency when you talk about any signal less audio signal for example image can also be considered as a signal it can be presented in two type of domain right so image can be is presented in a spatial domain spit meaning like space you know x and y or it can be represented as a frequency domain if you're talking about audio signal it can be represented in a time to time domain or a frequency domain so you can go through Iman's channel he has some awesome tutorials he explains things in a very very simple way so try that here is another tutorial what is signal processing I'm going to provide all this links in the video description below another thing you need to have good understanding on is Fourier transform for that three blue one brown channel has an excellent tutorial so if you watch this you will understand how Fourier transform works just to give you an idea Fourier transform will take a complex signal and it will return you the basic signals which makes that complex signal just to give you an idea let's say you are eating some dish let's say you are eating pizza and if you do reverse engineering on Pizza what you find is a basic ingredients which is like cheese the base which is of made up of all-purpose flour the vegetables whatever it so similarly when let's say you have a complex signal let's say you have a signal where you have different instruments playing in and then you have also noise you know in we have many noise cancellation devices so how do they actually cancel the noise so that is something that you need to think about and that they do using Fourier transform because food--it transform can separate out the voice off let's say your Trump's voice the the voice of the vocal voice the noise it can separate out all these signals into different frequencies and using the frequency filters you can suppress some frequency or you can inter amplify certain frequencies you might have seen in audio audio devices where you can increase like treble or jazz you know all of this is possible because of Fourier transform and wavelet transform is kind of similar to Fourier transform it is little different I'm not going to go too much into detail because that's a huge subject on signal processing I might have to spend like six month you know just on that topic and for that reason we have Iman's amazing channel and you can refer to his tutorials okay so let's come back so just assume if you don't want to just worry too much about this just assume that by creating this black and white image you are extracting the important facial features which is going to be very useful to our classifier because when you think about - our APIs face how do you detect her face she has eyes at a certain location on her face her eye size is different than other players so when you detect if this is a - are Oppo or this is VR Kohli you use these features like how small or big the eyes are whether the person has a mustache or a beard what is the size of the lips the structure of the face and all of those fine details are given by this wavelet transform image to us okay so this I showed it for one image what we are going to do is now we are going to create this wavelet transform image for all the images on our craft folder now when we create these images we will vertically stack these two images so what we'll do is so just to give you an idea so we'll take this image - our pause image okay so let me just visually kind of show you because that might become useful so let's say I take this image here okay and I use for example - paint in ms paint I copy this image okay so I have this raw image now ROI image also has important features I am not saying it doesn't therefore we are using raw and the wavelet transform image both so this is the raw image and I have this available it transform image and just think that I am vertically stacking them so this will be the input of our classifier because a raw image can give certain information to your classifier at the same time wavelet transform image will have lot of meaningful important features and for that reason the next piece of code that I am writing what I am doing is I am vertically stacking these two images and I am doing going to do that for all the images in our craft folder okay so how do we do that so we saw that initially we created this particular dictionary so let's see what is this dictionary this dictionary is very important actually so this dictionary has a key which is a player name and the values are the cropped images okay so similarly you will see - our power and all the crop images of - our power now I'm going to I trade through this dictionary how do i trace through the dictionary it's a simple python thing you can use dot items function so see if i do this i am i treating to that and for each training file so training files is nothing but this list ok this list of images so i am now gonna go through all the training files ok so the first loop will eat it through my sports person second loop related through every image for that particular sports person alright so what do i do now is i first read an image because training image will be the path of the image and here i am reading the image using open CV or now I need to do scaling because the images could be of different size and we need to have same size when we are training our classifier so I'm just resizing it using open CV and I get now scaled a raw image okay so just just think that this is the scale image okay at the top 32 by okay let me put it here so this is that first time is 32 by 32 that is my scale image now the second thing I need is wavelet transform image but that has to be in the same dimension as well okay so alright so I'm this is how I get my wavelet transform image w2d is the function this is doing wavelet transformation i got this function from stack on flow i'm going to provide the credit thanks stack also you know like stack overflow we use all the time because we don't want to reno in the way then we can just get ready-made functions okay once I get this image I need to scale that image as well and now I scale this image called scale image hard okay both are 32 by 32 how do you vertically stack them well numpy has a function to vertically stack them so here I am saying numpy vertically stacked those images my scaled image and my scale wavelet transform image okay my scale image has 32 by 32 into 3 because it's a colorful image so RGB 3 channels this way 3 the wavelet transform image doesn't have collapses like a gray image so I'm gonna combine this into combined image let's call it combined image fine I'm fine with that and now I need to create X and Y's guys we are reaching an interesting stage because now we are creating x and y which means we are kind of ready for the model training so in the X which is a Python list simple Python list nothing fancy I'm going to put my combined image all right what is y everyone so Y is a name of the celebrity now I cannot put celebrating name here because X and y has to be number so somehow I need to generate a number some number for each of my celebrities so let's do that how did I do that okay so I'm gonna go through all my celebrities and generate a class did something like this so go through all celebrities and start with count just assign them some number you know just random it doesn't matter which number you assign you need just some some class number and once you have this dictionary now this dictionary can be used to return a number for a celebrity name so now I'm getting a number for each of these celebrities I am going to execute this so this error apparently it's happening because we had all these images in this dictionary but we manually deleted some images so some of the images are not available so one thing we can do is we cannot gain height rate through all the folders and get the new images or we can just say if image so if [Music] image so if the image is not present the CV - I am read will return in none so I just added if image is none then you continue and when I executed it I have my X&Y ready and let's see what is x and y really so if you look at X shape ok X is a list so it doesn't have a shape really but if you look at the length of the X it is 162 if you go and count the images in your folder like all the images in this 5 folder it will be 162 so each element in X is an image and the size of each image is 4 0 9 6 so 4 0 9 6 is what so you see here 32 into 32 into 3 so that is our rock pixel like raw image the x and y is 32 32 3 is 4 RGB and then 4 wavelet transform image another 32 into 32 so you get 4 0 96 and if you want to just look at like the first image for curiosity it's nothing but the you know some number which is representing the color or like the shade of M of an image because machine learning model can only understand numbers so that's why we are doing this and I'm gonna do one more thing - axe I will convert things to float okay and I'm just recapping it just to make sure the shape is 162 by 4 0 9 6 ok and now these images are convert are now represented as a float number you see like dot after that and that float number later on when we train the model you know we might get some errors that's why I have converted that as a float if it is in digital still work but the S Kalani PS will give you a lot of warnings so just to avoid that I'm converting it to float all right so that's I think all we had for this video now we have X & Y ready to begin our model training in the next video we are going to do model training and then in a video after that we will do fine tuning or hyper parameter tuning using grid sir CV and we will select the best model of for our image classification thank you bye
Info
Channel: codebasics
Views: 13,712
Rating: undefined out of 5
Keywords: feature engineering, image classification machine learning project, complete machine learing project, complete data science project data science project step by step, data science project for beginners, data science project in python, machine learning project python, machine learning project in python step-by-step, machine learning projects in python with code, machine learning projects with source code, machine learning projects for beginners in python
Id: sWAPtaBZKBQ
Channel Id: undefined
Length: 18min 23sec (1103 seconds)
Published: Sun Jun 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.