Data Science & Machine Learning Project - Part 4 Feature Engineering | Image Classification
Key Takeaways
This video demonstrates feature engineering for image classification using wavelet transform and Fourier transform, applying tools like OpenCV and NumPy to prepare images for a machine learning model.
Full Transcript
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
Original Description
In this video, we will use cropped images and apply wavelet transform to extract meaning features that can help with image identification. You need to understand many important concepts such as time vs frequency domain, fourier transform, representing images as frequency etc. You will find below resources to understand these concepts. USing wavelet transform and a raw pixel image we will create our X and use class labels as y. These X and y will be used for model training. Feature engineering techniques in this tutorial will enhance your understanding on how they can be used to create powerful prediction function.
Code: https://github.com/codebasics/py/blob/master/DataScience/CelebrityFaceRecognition/model/sports_celebrity_classification.ipynb
Resources to understand signal processing concepts:
My friend Iman's youtube channel: https://www.youtube.com/channel/UCVkatNMgkEdpWLhH0kBqqLw
Representing image as a frequency: https://www.youtube.com/watch?v=xrTor1uw5iI
Fourier transform: https://www.youtube.com/watch?v=spUNpyF58BY&t=423s
Special thanks to,
Debjyoti Paul (Amazon Data Scientist): For help with entire project
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Website: http://codebasics.io/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from codebasics · codebasics · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Python Tutorial - 1. Install python on windows
codebasics
Python Tutorial - 2. Variables
codebasics
Python Tutorial - 3. Numbers
codebasics
Python Tutorial - 4. Strings
codebasics
Python Tutorial - 5. Lists
codebasics
Python Tutorial - 6. Install PyCharm on Windows
codebasics
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
Python Tutorial - 8. If Statement
codebasics
Python Tutorial - 9. For loop
codebasics
Python Tutorial - 10. Functions
codebasics
Python Tutorial - 11. Dictionaries and Tuples
codebasics
Python Tutorial - 12. Modules
codebasics
Python Tutorial - 13. Reading/Writing Files
codebasics
How to install Julia on Windows
codebasics
Python Tutorial - 14. Working With JSON
codebasics
Julia Tutorial - 1. Variables
codebasics
Julia Tutorial - 2. Numbers
codebasics
Python Tutorial - 15. if __name__ == "__main__"
codebasics
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
Julia Tutorial - 4. Strings
codebasics
Python Tutorial - 17. Class and Objects
codebasics
Julia Tutorial - 5. Functions
codebasics
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
codebasics
Python Tutorial - 18. Inheritance
codebasics
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
Julia Tutorial - 10. Exception Handling
codebasics
Python Tutorial - 19. Multiple Inheritance
codebasics
Python Tutorial - 20. Raise Exception And Finally
codebasics
Python Tutorial - 21. Iterators
codebasics
Python Tutorial - 22. Generators
codebasics
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
Python Tutorial - 24. Sets and Frozen Sets
codebasics
Python Tutorial - 25. Command line argument processing using argparse
codebasics
Debugging Tips - What is bug and debugging?
codebasics
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
codebasics
Python Tutorial - 26. Multithreading - Introduction
codebasics
Git Tutorial 3: How To Install Git
codebasics
Git Tutorial 1: What is git / What is version control system?
codebasics
Git Tutorial 2 : What is Github? | github tutorial
codebasics
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
codebasics
Git Tutorial 9: Diff and Merge using meld
codebasics
Difference between Multiprocessing and Multithreading
codebasics
Python Tutorial - 27. Multiprocessing Introduction
codebasics
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
Git Tutorial 8 - .gitignore file
codebasics
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
Python Tutorial - 30. Multiprocessing Lock
codebasics
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
What is code?
codebasics
Python unit testing - pytest introduction
codebasics
More on: ML Maths Basics
View skill →Related Reads
📰
📰
📰
📰
Statistical Estimation — Deep Dive + Problem: Longest Consecutive Sequence
Dev.to AI
I Thought I Was Learning. Turns Out, I Was Just Compressing PDFs Into My Brain.
Medium · Machine Learning
Deep Dive: Why Post-LayerNorm Crashes Big Models (And the Bare-Metal Math of Pre-LN Identity Highways)
Reddit r/deeplearning
The Efficiency Revolution: Why Smaller AI Models Are Winning
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI