Kickstart Your AI Journey: From Zero to Real-World Projects | Eduversity | Skillshare
Search

Playback Speed


1.0x


  • 0.5x
  • 0.75x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 1.75x
  • 2x

Kickstart Your AI Journey: From Zero to Real-World Projects

teacher avatar Eduversity, Where Future Skills Begin!

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Introduction to Artificial Intelligence

      9:23

    • 2.

      Introduction to Data Science

      8:19

    • 3.

      Hierarchy in Artificial Intelligence

      8:31

    • 4.

      Supervised vs Unsupervised Learning

      4:36

    • 5.

      Introduction to Machine Learning

      6:12

    • 6.

      Introduction to Deep Learning

      4:54

    • 7.

      Machine Learning vs Deep Learning

      5:52

    • 8.

      Data Preprocessing

      14:51

    • 9.

      Encoding Categorical Data

      8:32

    • 10.

      Feature Scaling

      11:30

    • 11.

      Linear Regression

      19:16

    • 12.

      Multiple Linear Regression

      16:43

    • 13.

      Logistic Regression

      21:39

    • 14.

      Support Vector Machine

      7:34

    • 15.

      K-Means Clustering

      21:11

    • 16.

      Project 1: Breast Cancer Prediction

    • 17.

      Project 2: Spam News Detection

      57:16

    • 18.

      Project 3: Handwritten Digit Recognition

      40:22

    • 19.

      Project 4: Automatic Licence Plate Detection

      59:26

    • 20.

      Project 4.1: TensorflowObject Detection Setup Installing Verifying Packages

      56:57

    • 21.

      Project 4.2: Create Label Map TF Records Model Configuration Pipeline

      29:53

    • 22.

      Project 4.3: Updating Configuration file Training the Model

      31:25

    • 23.

      Project 4.4: Evaluating model Detecting License Plate trained model

      33:49

    • 24.

      Project 4.5: Applying OCR Detected Plates filtering Saving Results

      51:50

    • 25.

      Project 5: Covid 19 Detection using Neural Networks

      37:18

    • 26.

      Project 5.1: Transfer learning Building Model Architecture Training

      45:51

    • 27.

      Project 5.2: Evaluating Model Testing on Real Images Plotting Curves

      40:11

    • 28.

      Project 5.3: Confusion Matrix Classification AUC ROC

      27:09

    • 29.

      Project 5.4: Web Application Flask Deployment COVID 19 Detector Web App

      46:36

    • 30.

      Project 5.6: Bonus Video Custom CNN Architecture

      19:10

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

3

Students

--

Projects

About This Class

Unlock the exciting world of Artificial Intelligence with this beginner-friendly, hands-on course designed to take you from zero to real-world mastery. Across 15 expertly crafted modules, you’ll explore Python, machine learning, deep learning, data preprocessing, regression, classification, and much more — all explained in clear, practical terms.

With over 13 hours of engaging video lectures, you’ll not only learn the theory but also apply it through advanced industry projects like breast cancer prediction, spam news detection, handwritten digit recognition, automatic license plate detection, and COVID-19 detection using neural networks.

By the end, you’ll have a portfolio of real-world projects and the technical skills needed to pursue exciting careers as a machine learning engineer, data scientist, research scientist, or AI developer.

Whether you’re just starting out or looking to upskill, this course is your gateway to the future of AI.

Meet Your Teacher

Teacher Profile Image

Eduversity

Where Future Skills Begin!

Teacher


At Eduversity, we make cutting-edge topics like Artificial Intelligence, machine learning, and data science easy and accessible for beginners. Our hands-on, project-based classes help you move from zero knowledge to real-world mastery -- with clear, practical lessons designed to build your confidence and skills. Whether you're looking to break into tech or sharpen your expertise, Eduversity is here to guide your learning journey. Join us and start transforming your future today!

See full profile

Level: Beginner

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction to Artificial Intelligence: Hello, everyone. My name is Corof. So today in collaboration with Adiorsity, I brought a course on artificial intelligence, and to introduce myself, I have a six years of experience in the field of artificial intelligence, machine learning, and deep learning. I have several publications in quartile world journals. I published several research papers on the field deep learning, and currently I'm working as a data science and automation engineer in dial technologies. So what is this course about? In this course, like the artificial intelligence domain is itself a very broad domain. And obviously, it cannot be covered. It can't be covered in just one course. But in this video, in this series of videos and in this course, I'll give you the complete overview of what what are the different fields in this domain? And what are the different things we do in this domain, and what are the different requirements? I'll also get to familiarize you with the industry standards, what an industry today demands and what they are looking for an artificial intelligence engineer. And also, in the end of this course, I'll cover will do some of the projects in this artificial intelligence domain. And in this, I'll try to cover everything which will get you started in this domain. The core algos, decor projects, the code, everything about AI. And step by step, as you will move further, you will get an institution about what this overall field is. And see in this current scenario in today's world, the demand of an AI engineer, a machine learning engineer or deep learning engineer, or you have heard of a data scientist. This is like these engineers and the job profiles are very demanding. And the future is AI. Like, everything in today's world, it is getting automated, and the future is A. And so after this video, after this course, you will get familiarized with every tools and technologies we use in this artificial intelligence domain. And step by step, I'll brief you with everything. So let's start with our first chapter, which is introduction to Artificial Intelligence. Now, what is actually an AI? In the traditional programming, where you have done, I'm assuming you have done some programming. Suppose you are writing a program to just check whether a number is odd or even. Now, you are doing like you are hard coding that and you are implementing some of the rules. Like if I mod a number by two and it will give a remainder at zero, then it is divisible by two, otherwise it is not. And if it is divisible by two, it is an even number, otherwise, it is an odd number. So you are defining a rule. You are defining set of rules here. And what is now, what is the meaning of AI? AI is anything which you train the computer to do, and the computer will do it itself. A simple ten lines of codes with F and L can also be called as AI, like you have heard a TikTok AI, where Tita too OI, A. And in this game, basically Tita too, you have scene that we'll write see if you search for the code of TiktatoGame in Decoogle, you'll get somewhere around 15 to 16 lines of IL condition, and when you start run the code, like when you run the code, you'll simply play and the computer will play with you the Tiktato. And these are the rules we have initially defined and the computer is interacting with you. There is no human intervention here. So this is which we call as AI. Anything which the computer can do it by itself doesn't require any human to interfere in that thing that is called a AI. Now AI is a very broad field. I'll show you why. So this is a given digram of an artificial intelligence domain. See, in this AI domain, machine learning comes and basically machine learning is a subset of AI, AI is itself a complete domain, and inside that machine learning comes and inside that deep learning comes. This is not a complete domain actually. Like this is not a complete diagram, actually. This is the complete digram. The AI is a complete field in that machine learning comes in that deep learning comes, and data science is also a part of AI. Some part of data science is a part of AI and some part is not. In this video, I'm going to teach you those data science concept, which is a part of artificial intelligence. You will see in this for the videos. So type some part of data science. I'll explain to you in more depth in the data science video data science chapter, but I'll give you a gt here. In the data science, many things like many things come, there are data science engineers and data science researchers who collect the data, who acquire data from various resources, and then do the processing in that. So acquiring data and collecting data and generating data or like these are things, this doesn't come in the field of artificial intelligence because what I have told you, artificial intelligence is anything which a machine can do it itself. And here the data cleaning and data gathering part. These are the manual man persons are assigned to this task and they are doing. Machine is not doing that. In some part, machine also do that I suppose we have written a script where we are scraping a lot of data from Internet. That part is automated, this comes under AI, but some part of that data science doesn't come in under AI. This is the whole ven diagram for artificial intelligence in that I've told you, machine learning comes and the deep learning comes. What is exactly machine learning, deep learning, and data science, you will learn solely, solely in this course as we move forward. Now, these are some features of AI, and in today's world, many of things, these are implemented using the AI, suppose deep learning, as I've told you, automate tasks. Many companies nowadays doesn't do manual coding. They are simply automating those tasks. Like, suppose if a company suppose a company is task is to collect some data from the net. And initially before ten years, what they are doing is that they hire some of the engineers, suppose ten to 15 engineers, and they are simply those engineers are directed to collect manually collect the data from Internet. But nowadays, what they are doing, they're hiring AI engineers, and they are telling to automate those stuff so that the machine could itself scrape the data from the Internet. So this is what the automation is doing in this current scenario. Facial recognition, you might have seen in your phone, your laptop, where you have today's a feature known as face unlock, which you might have seen in your mobiles. Then cloud computing, chatbard, data injection, quantum computing. These are all come under AI. Chat booards you have seen in Amazon and any of the website there's chatboard which is interacting to you all the time. So these all comes under AI. Chat booard comes under natural language processing. So you'll see what all these are in for the video. But this is overall the artificial intelligence domain. In this, this is a very broad domain. This covers a lot of things and why you have to why you should know everything. Like, I'm not saying that you should know everything in detail, but the birds eye view, the gist of every domain, machine learning, deep learning, and data science, you should have a knowledge. Why? Because then only after you can decide whether you should go into the domain of whether you are a good, whether you are liking data science, whether you're liking machine learning, whether you were liking deep learning. Then you can decide when you have a brief knowledge of everything. So that's this is what this course is for. And after this course, you will be deciding in which domain you have to move and you want to move. And of every domain data, science, machine learning, deep learning, every domain, you have a brief knowledge about what is exactly happening in this domain and what exactly people do in this domain. So this is what course is all about, and this is the end of the first chapter artificial integs. In the further videos, we'll see some more part about what is data science, what is machine learning, what is deep learning, everything we'll see in further videos. Till then. 2. Introduction to Data Science: Hello. Welcome back, guys. So in the last video, we have seen what an AI artificial intelligence is and what it actually covers and what people generally do in this domain. Now, in this video, we'll be seeing what is, like, data science, what exactly it is. So Data science is itself a very broad field which comes under artificial intelligence. So part of it, which I've explained to you in previous videos. So part of it comes under artificial intelligence. So part of it doesn't cover the AI twos, which we don't generally count in artificial intelligence domain. So what exactly is data science? Like the name itself can explain to you what is data science? Anything which we are doing with data. This comes under data science. Like, I'll explain you more in more detail. Suppose you are gathering some data for an industrial use. Suppose a company has given you a problem statement. Suppose you are working in let's say Netflix, you might have heard about Netflix. So you are working in Netflix. So in that Netflix, you have assigned a task to build a movie recommender system. And what exactly this do? Like, you might have seen that in Netflix when you will hover over any movie like after or let's say you have watched a movie, suppose Dark Night. Let's say Dark Night. You have watched a movie called Dark Night. Now, as soon as you have completed this movie, you might have seen some of the recommendations below. Like you are seeing Batman Begins, you are seeing other Christopher Nolan movies and like, a lot of movies. So what is that? This is your recommender system, which is an application of machine learning or you can say it application of AI. So first, you have assigned a task to build a recommendation system for a company. Now, what is the first step you will do? In the first step, you will gather the data. Like, you have to create a database where you should have all those movies names, all those director name, the cast, the crew, and everything, the date of release of Man, everything about. So you will gather those data. If you do not have any data, then you can't simply build an AI. So you require data. So the task doesn't end here. Once firstly you will gather the data, then you will clean the data. Like when you are gathering the data, some of my let's say, if any movie, you have got the movie name, but you don't have date of release or any parameters. So you simply might have to assume that parameter or you have to clean that you have to clean the complete data or any like many of the things you require. So that complete thing, gathering data, preprocessing data, getting the data ready for the model, everything comes under data science. And this is what a data scientists do in a company. I'll try to explain you in more clarity with the help of image. Let's see that. Here you can see, this all comes under the data science. You can ignore communication skills, real world project because these are soft kills. Basically mass and stat this image I have downloaded from a portal where it is claiming, these are the qualities which are data scientists minimum should have. The mass and statistics knowledge. The mass and statistics knowledge is very necessary when you enter into the field of data science because every game is about a statistics. Suppose you are gathering a data in which there is 100 row and suppose the 50th row value is missing. Now, what you can do here, you can simply mean all those values and put it into the 50th value. We will see in further videos how we'll do that. But here you can see the mean median mode, variant, this all concepts come. So this is like this comes under statistics. So you have a strong foundation in the field of statistics and mass. The generally 11 and 12 foundation is more than sufficient. And if anything else is required, that is, you will learn in the data science. When you're learning completely going into the data science, like deep diving into the data sciene domain, then you will learn so Python and R, these are the two languages generally which generally people use in this data science. Generally, people more use R in the data science domain. But if you are not completely into data science, you are into you want to learn some part of it, data science, some part of data science, and then you want to dive more into machine learning and creating models and artificial complete co deep learning and everything, then you should choose Python because Python is more like versatile and generally people prefer to use that only. And community support of Python is also, great. So yeah. Now data wrangling and preprocessing. This is another thing which I've explained to you previously. This comes under data science. Now data visualization. This is a very important skill which a data scientist should have. Now, if there is 100 data, then you can see it on a CSV or 100, suppose 100 rows, then you can see it on a CSV or an A. But if suppose there is 1,000, 1 million, 2 million, 2 billion data data points, then you have to visualize all those data to get a clear idea. So data visualization skills are also very necessary in the data sien. There are a lot of libraries like CBO, Matplot Lab, and everything, which comes under Python, which we use to visualize the data. Then after data visualization, the machine learning skills. Machine learning skills a data scientists should have because if he doesn't know what is an appropriate model for this particular dataset, then he might not be perfect in clearing those data and getting getting ready with that data. So machine learning skills is also required for data scientists, and these are the things, basically. So in data science, there is a part called EDA, exploratory data analysis. So this part is generally a very important and a crucial part when you are creating you are deep diving into machine learning and deep learning, then this part is very important, which we'll see in Chapter two, the data pre processing part, and so the step by step procedure, when you are working on a problem statement, firstly, you will gather the data. Then you will analyze the data, then you will clean the data by using the data pre processing tools. Then you will visualize those data, and then finally, you will get your data ready to be feed into the model. And suppose if you are working in any company or working under any manager, then after applying all these steps, you will report to your manager or your company that you are ready with the data. Now, you can also do the modeling part and you can simply forward those data into another machine learning engineer to another machine learning engineer, and he'll simply do the modeling part. The data science and see machine learning fields overlap somewhere because in some startups, if there is not there are not any machine learning engineers, then the modeling part I have told you, machine learning skills. This part the data scientists would only do, and this all comes under data science. So in the next video, we'll be seeing the different industry standards and different industry hierarchy, basically. Like in what hierarchical order the industry works and what are the different positions in the industry and how the work basically go on. Because if you understand how the work in industry go on, then the better you will get an idea is a different purpose of domain. So all that we'll see in the next video, then goodbye. 3. Hierarchy in Artificial Intelligence: Hello. Welcome back, guys. So in this video, I'll be telling you what is the different industry standards and what are the different hierarchy we get in the industry and how the work is done in any industry or what is the standard procedure for that? And you might have seen the different, you will also get to know what are the different roles a company need and what are the different job profiles a company need when a project comes when a company plan to work on a project. All the things we are going to see in this video. So I'll explain you everything with the help of a diagram. This is a really nice diagram. So this is the data science hierarchy needs. This is not exactly any data science, but it is not particularly related to data science. I can also be extended to AI, deep learning, machine learning, and everything. I'll explain to you what that is. So suppose you have got a project to work on, you are suppose a company program manager and you need you want to work on and I suppose you are required to work on a project. So in that first, you will collect the data. For that, you will have a team of, let's say, data collector, data researcher, and everything. So these all the data collector team will do and collect the data and give it back to you, that will collect the data from different sources and give it back to you. Now, sometimes you have seen on the job profiles and job openings. They have a job profile for data collector, data researcher, data analyst, data engineer, data scientist, senior data scientists, machine learning engineer, everything is there. So for data collector, this is the first step. Now, when you have the data, the unstructured data, then you have to move, you have to store, you have to pipeline those data. You have to build pipeline tool for that data and everything. So for that, you have move and store part. This is your second step. The unstructured and structured data storage, ETL, export, transform load, ETL fulf basically export, transform load. So all that comes into this. Now, this is your third step where you have to explore and transform your data. This is a very crucial part. This comes under from here, some part of core data science, a scientist is starting the data cleaning, the analomy detection and preparation of data. Like in the data cleaning, suppose suppose you have a record and in that many of the things you are not requiring here, and those are all those information. So you will basically clean those data. And anomaly detection is basically suppose you are receiving a set of data points or records. And in that, any record is missing or any change or any sort of discrepancies you have, like, notice. So these all things you have to complete in this step. Now, fourth step is aggregating those data and labeling those data. Now, this is very important step is the labeling. In the next video, which is our supervised and unsupervised learning, here you will get to know better this step, what is labeling. Now, I'll explain you here also. Suppose you are gathering a data and suppose you are building image classifier to classify between cat and dog. Let's say a simple example, cat and dog. Now, in that, you suppose you have clicked ten or 15 images of a cat and ten to 15 images of a dog. Now, the model in the model when you are providing the data, suppose you are providing this data to a data scientist. Now, these all data should be labeled. Like the cat image is labeled as the data scientists to know what this image is about. Like you should know that you are providing me this image. This image is of a cat. This image is of a dog, so you have to label those data. This is a very important step. Now the step five will come learning and optimizing. Now, the complete data is ready. The data scientist has completed all those steps and the complete data we have. And now the ML engineer work is come. Now the data scientists or the SNR data scientists, they will provide those data to an ML engineer. And now what ML engineer will do, he will simply model, the modeling part. And also sometimes the data scientists also need to sometimes this work is also done by the Senor data scientist. Like he'll only model the data. Like he'll train the model which will make some meaningful insights out of the data, and you will provide those to ML engineer, and ML engineer will deploy that data into the server and optimize that data and everything will come. Now, at the top of the industry, the AI deep learning, you can see the AI and deep learning. This is basically not a necessary domain in every company. I small small starter, you might have not heard about the R&D team, the research and development team. So the topmost field in an industry, the research and development, the R&D team, this consists of an AI and deep learning researchers. You have created and you have deployed the whole model. Now that model needs to be optimized and the accuracy needs to be improved. Now, that can only be done by the person which is having a core knowledge of every mathematics and every depth knowledge of every algorithms, and he has great experience, five to ten years of experience, 15 years of experience. So that can only be done by that person. So in that R&D and code deep learning team, the person who is having like a greater, highest experience in the company, like, not in the company in deep learning and artificial inte domain. He's having ten, 15 years of experience. He's having a PhD degree, and he has completed everything. So that team will analyze the model performance and it will improve that performance. So the role of R NA team is that. Now, this is what a company hierarchy generally consists of. Like, quickly, I will brief you again. Like for the data, data will be collected, then it will be moved and stored, the unstructured data, then it will be transformed and cleaned. Then it will be labeled, and then it will be optimized. Like the appropriate model for that data is like which the machine learning and data scientists will tell us, and they will implement those models. They will train those models, then the machine learning engineer will simply deploy it on a server, and then the AI and De learning researchers and the R& team will optimize those models further. Like, this work never ends. This work this work is never ending because accuracy you cannot achieve 100% accuracy. You will app suppose 96%, then it can be improved. Then I still have a scope of improving it to 96.1, 96.2. Even if you are claiming an accuracy of 99 point, suppose 8%. Then also, it has a scope of improving it to 98.99 0.81 99.82. So it is a never ending profre. And 100% accuracy is not like feasible or we can say not ideal in the real world because no one is 100% perfect, right? So this is a never ending field. So this is what an industry and what is the hierarchy of an industry needs. Then you might have heard of several positions like the data scientist, the data researcher, data analyst, data engineer, machine learning engineer, core R&D, every post you might have heard. So these are all things. In the next video, we'll be seeing what is an unsupervised and supervised learning. Till then prepare. 4. Supervised vs Unsupervised Learning: Hello. Welcome back, guys. So in this video, we'll be seeing what is unsupervised learning and what is unsupervised learning, and what is the difference between that? So in the FEF five you have seen in industry, we need the labeled data. This is a data labeling part. And if we are labeling a data and you are providing it to a machine learning engineer, that comes under simply supervised learning. And if we are not labeling the data, if we are simply providing the data for a modeling, but we are not providing its label, then it comes under unsupervised learning. Now, I'll explain you with an image in more clarity. So see this, the classification machine learning is divided into two parts test driven task driven task and a data driven task. In task driven, it comes like supervised learning, and it is it is broadly classified into supervised learning and unsupervised learning. Now, supervised learning, we have the labels, the pre categorized data we call it as. Now, Suppose we are building a classification model. You will understand slowly solely how we build a model and what is the classification model in much more detail for the videos. But for now, just understand if you are building a classification model in which your task is to simply classify between two data points. Now, the model, as I've told you, what is a machine learning exactly? Like a model needs the output value also. So you have to provide. Suppose you are building a model which will simply recognize that the image you are providing is image of cat or a dog. So you are providing the data scientists, the data, the images of a cat and also providing the label that this image I'm providing you is of a cat. This image I'm providing you is of a dog. So this is basically your supervised learning. The machine learning engineer or a senior data scientist, they will know that this data, what this data is all about. And in the other part, the unsupervised learning, we do not provide label through the data, suppose you might have a doubt like how this is going to work if you are not providing the data. Suppose you are targeting like you are building a customer market segmentation model. Now, basically you want to segment those persons which will have a different liking. Suppose you have provided the data and you simply want your model to segment all those persons, which will have a similar type of liking. Now, what your model will do it will form the clusters. Like suppose your group, in your friends group, you have total three type of people like one type of people who likes movies, enjoying and everything, one type of people who is very focused toward academics and whole day studying and one type of people, who is balanced, like, he'll study also, he'll enjoy also, like everything he's going to do. So these are the three categories of your friends group. Now, if you want to create a machine learning model in which you will simply want to know that which of these qualities this person is belonging to. Now, this modeling you just have to provide all those data to the model, not the labels. And here your model, what we'll be doing is forming clusters. You will like one group of people is clustered into separate cluster, and another group is clustered into separate cluster, and the three clusters are forming. Now, this is what generally we do in unlabeled data. The pattern and structure recognition pattern we are using here. So this is what is unsupervised learning. The supervised learning and unsupervised learning, you will get more clarity when we deep dive into the machine learning algos and we'll see there, you will see regression and classification and clustering and everything. The word I am again and again telling you cluster, cluster, cluster. So all that you will get to know in much more clarity in that further video. So for now, just understand the labeled data modeling part with the labeled data is known as supervised learning. The modeling part with unlabeled data is known as unsupervised learning. That's and in for the video, we'll be seeing, like, more and more depth. So yeah, till then. 5. Introduction to Machine Learning: Hello, and welcome back, guys. So in this video, we'll be looking at what a machine learning is exactly. Now, see, there is a classical programming which we do by simply writing a program or a code in any language, and there is a machine learning. So what exactly is the difference between two? Like, I'll show you with the help of an image. See. In the classical programming, we generally provide the data and the rules, and we get answers. Like, suppose you let me explain you with an example. Suppose you are writing a code for you just want to check if a number is odd or even. So basically, you are writing two lines of code. If a number modulus two equal equals zero, then it will be an even number because modeling, like when you are applying mode to any number with two, then the remainder it will have zero if it divisible by two, four mod two is zero, and yeah. So you are providing the data, the numbers, the four, two, five, six, any number, and you are providing the set of rules. If it is mode two equal equal zero, then it is even number and mode two equal not equal zero is odd number. So you are providing those rules, and the computer is simply computing and giving you an answer. It is an even or an odd. Now, what I want is I'll provide the data and the model itself will tell that without providing any rules, without providing any rules, the model will itself tell me that it is even number or an odd number. Now, how it will. There the machine learning rules will come. We'll train our model, we'll train our computer in such a way that we'll be providing the data, the two, four, five, six, any number, and we'll be providing the answers. Now, this is the answer that this comes under this supervised learning. Suppose let's understand by this way, you are providing two and you are telling your computer that this is an even number. You are providing four, you are telling your computer that is an even number. You are providing five, then you are telling it is an odd number. You are providing seven, you are telling your computer that is an odd number. Now, here, like 100 or 150 sample points you will provide to your computer, like the dataset which we call. Now, what your computer, what your model will do, it will simply learn to classify whenever it will be given a number, it will classify those numbers in either even or odd. This is a classification problem. So now what will be the model be doing is learning when a number is even, when a number is odd, and how it will learn it will generate its own rules. Now, these rules are generated by a machine learning model. Now, in future, you have the rules. I future, whenever you will provide those data, it will automatically classify it as even or an odd number. This is basically the task of machine learning. You are providing the input, you are providing the output, and you are generating those rules. Now this is a very simple task. You might be worrying, you might be wondering why we are doing that, if we can do with just two lines of code, why we are doing this much of stuff. Now, let's understand with another example, you are basically building a classifier model in which you want your model to recognize to classify between a cat and a dog. Now what you would do? You will provide data a cat image if your data. You will provide the answers that label which we have, which I have told you in previous video, the labels, the cat label, then you will provide a dog image, then we will provide label as dog. Now you will provide 100 hundred images and your model will be trained based on that images, and then you will get some ruse which you don't know, which will never know what that ruse your machine learning is generating. You'll never know. But next time you only have to provide your image, the cat image, you don't have to tell model that you just want to know that this image the image I'm seeing is of a cat or a dog. You'll just provide the image and your model will itself return you back with an answer that this image which you have provided to me is an image of cat. And this image you have provided to me is an image of dog. So this is the use of machine learning that you are training a computer or a model to work in such a way that you are not providing any output and not answers, and you are getting an answer from machine learning. This is what the machine learning definition is. And if you simply search on Google that what is machine learning then you'll get this type of answer. Machine learning is an type of AI that allows software application to become more accurate at predicting outcome without being explicitly programmed. This is a very important word. Like, generally, people do not understand this word. So without being explicitly programmed means you are not defining any rules. Your model itself is defining a set of rules and itself is computing based on that ruse. You are not providing any rules. So again, the machine learning is a part of AI. This is a subset of AI, which train the software application to become more accurate at predicting outcomes. And the machine will learn machine learning, you can split in these two words machine and learning. And you can understand in this way that machine is learning itself to give you a better output and improve your accuracy, and it will predict for you. So this is what machine learning is. In the next video, we will also see what is deep learning. Till then, goodbye. 6. Introduction to Deep Learning: Hello. Welcome back, guys. So in this video, we'll be seeing what is deep learning. Now, deep learning is a subset of machine learning which comes under machine learning, and it is inspired with the working of our human brain, our human neurons. Now, what exactly it is? Like in childhood, when you are seeing, suppose a cat image for the first time, then you are seeing a cat and you are asking your mom or any relative or any family that what is it exactly? Then your mom is telling, Oh, this is a cat, then you are learning those things. You are feed you are training inside your brain consists of several neurons, and the neurons are training based on this data. Then you are seeing a dog and you are asking again, your family, what is it? Then your family is telling Oh, this is a dog. Now at this age, your brain is completely trained. Whenever it will see a cat or a dog image, it will automatically classify between those images, and it will automatically recognize those images. Now, what is that? Like, this is sounding more like a machine learning. This is not sounding like a deep learning. So what is a deep learning? So in machine learning, basically, it is defining set of rule the model is outputting you set of res. And in the deep learning, the model is outputting you a set of weights and biases. Now, what are those weights? What are those biases you will understand more when you go to the deep learning chapter. Right now, I'm just giving you an overview of what is deep learning. So the model will output you the set of weights, the set of bias. I'll explain you more clearly with the help of image. So wait what is when in the Google will search for what is deep learning. So here you can see, deep learning is a type of machine learning and artificial intelligence that imitates the way human gains certain types of knowledge. How we are learning is replicated in this deep learning, how generally we used to learn anything that is the concept is derived from that only. The deep learning is deep learning also works like that only. We are training our model in such a way our human brain is trained. So here, like you said, see this is basically a neural network, and these the arrows you are seeing this arrow, every arrow is assigned a way W one, W two. These are all those neurons connected inside. This is a very simple form of neural network. The complex neural network will have, suppose 1024 neurons here, 512 neurons here, and all those connected. So 1024 into 5112. So it is a very complex structure. The network is really, really complex. So this is like every weight and after training of our complete network, we'll have to find W W two in such a way that it will be like outputting us the correct value. Now, here you can see with an image in machine learning, the feature extraction and classification, firstly, you are providing your model the dataset and your model will extract some of the features. Now, what is the feature? Like suppose if you are working on an image classification problem, then in an image, suppose you are providing a CAT image, then in a CAT image, there are several features like an image is having several features. Like suppose a cat is having its eyes, nose, mouth, the edges, the contras, the contrast, the brightness, everything is counted as a feature. And the model will learn those features and then it will classify those features. In the deep learning, overall, everything, the feature extraction part and the classification part is completely done by the hidden neurons. The neurons I have visualize you here is the complete working part. And in the deep learning simply you have to provide your input and the model will train and you will get the output. And every learning will be done by the hidden neurons. And in the machine learning, the separates steps have to be followed. So this is machine, this is a definition of deep learning, it is a subset of machine learning which work on how our human brain works. You will get to understand in more detail for the videos then don't worry just follow up with me. Yeah. In the next video, we'll be seeing the difference, the main difference between the machine learning and deep learning. Okay. Till then 7. Machine Learning vs Deep Learning: Hello, and welcome back, guys. So in last two videos, you have seen what is machine learning and what is deep learning. Now, you might be wondering, like if we have to perform any particular task and we can perform it with both the methods, the machine learning method and the deep learning method, then why even we are learning deep learning? Why even we are considering deep learning when we can perform the same task with the help of machine learning also, the feature extraction, just the method, the procedure is different, but we can perform both the algorithms, like the machine learning algorithms or the deep learning algorithm, then why deep learning is coming into picture. Now, I'll quickly show you some of the difference between deep learning and machine learning first. Then I'll explain to that. See, these are some of the difference between deep learning and machine learning. Deep learning requires a larger data to train. Obviously, it will require large data because in the complete network, it will have to adjust the weights and biases of every neuron and every complete network has to be trained. So deep learning is data driven approach which require a lot of data to properly train the model. As large data is having if we are having as larger data we have, then the model will train more and give us more accuracy. The model will train better. And machine learning can be trained on a lesser data. If we are having some suppose if we are working on a problem treatment and very less amount of data we have, there deep learning will simply fail, and we have to use machine learning approach. And the deep learning, if we are providing it a larger accuracy, it will definitely if we are providing a larger data set, then it will definitely provide us with a greater accuracy than machine learning. Deep learning takes very long time to train and not even long time, it requires GPU. Like you might have heard GPU in your laptop, the graphical processing unit. So deep learning generally, obviously deep learning can also be trained on machine learning on CPU also, but GPU will fasten up this process. GPU consists of many, many courses which are, and in the GPU, we can also do the panel processing. So this trains your model faster. In machine learning, when we have built the model and we have to tune the model, the hyperparameters tuning, you will get to understand it for the videos, but simply just know for that. In machine learning, you have a very limited options to tune your model, and in deep learning, you have various options to tune your model. Now, the question still remains. Like, if we have to do the same if we can do the same task with deep learning, then, machine learning, then even we are considering deep learning. So there are some tasks, like, which requires you to work on images and videos. Those task is it is if possible with machine learning, then it will require very long time because it is running on a CPU, then it will require very long time. And at some tasks like the natural language processing, the computer vision, which is the code subset, the code domains, like subdomains of deep learning, those tasks are not performed, those are not possible with machine arn. So you'll have to use deep learning approach where images will come. You will have your computer vision domain, the sounds will come or the textual data will come. There you have natural language processing domain so for some tasks, like, you have to consider deep planning. And today, like, the whole world is moving. In the older times, we do not have this much like hardware availabilities. We do not have those, like, very high GPUs and very faster GPUs. So older times we generally use machine learning, the classical machine learning approach. But now, since we have the hardware requirements we want, so everyone is switching to deep learning because deep learning will provide us the greater accuracy. The same model if we are trading with machine learning will provide some around it is providing around 90% accuracy, then deep learning will definitely improve that accuracy if we have the abundant data we want. Like if we have sufficient amount of data, then it will definitely provide us with the getter accuracy. So this is why we are using deep learning. And any a the problem statement, the initial problem statements which you'll be encountering it in AI, suppose you are building a classification model of a CSV, the dataset dataset is having data set you are having is on a CSV, then you can apply both the approach. You can apply machine learning also, you can apply deep learning also. But later and later on as you move, when you will encounter with the image data set, then you encounter with the sound dataset or even in CSV also if you are having a lot of data points, then eventually you deep learning. And some tasks like computer vision, natural language processing, everything comes under deep learning. So you will have to learn deep learning also. So yes, this is the major difference between deep learning and machine learning. And in the next video, firstly, we'll be like this is the end of this chapter, the intro to AI chapter. And in the next chapter, firstly, we'll be seeing what is like data pre processing thing. The data code, data scientists work, like the data scientists, the data engineering work and data analyze and everything. Like we'll see in this chapter. And in the further chapters, then we will be seeing machine learning, deep learning, and everything. So stay tuned, we'll see you in next video. Okay. 8. Data Preprocessing: Hello. Welcome back, guys. So welcome to the Chapter two of this course, data preprocessing. Now in the Chapter one, you have already saw what is data science? What is AI? What is machine learning? What is deep learning? You are already familiar with those things. Now, in the data science, as I've told you, the first step is the data pre processing stage, or you can see somewhere EDA, the word EDA. This is the full form is exploratory data analysis. So in this procedure, you will get some raw data by a data engineer, and you have to pre process that data. You have to take care of those missing values. You have to categorize, you have to convert those some categorical variable to a numeric value. I'll show you what it is exactly. And then you have to scale the features and then you have to create a training data. You have to split between training and testing set. So after creating a training and testing set, then you will provide those data to a machine learning engineer or a senior data scientist, then he will be doing the modeling part. So in this chapter, we are going to see that. When, suppose you are receiving very raw data from a data engineer, and at the end of this video, you are ready with your training and testing set. Now, what is training set and what is testing setFirst of all? So training set is the data in which your model is being trained. The model is trained on that data, and the testing set is like we keep a separate testing set in which your model will be tested. Like after the completion of the training part, your model will be tested on some new data so that we can report its accuracy in the real world scenario. So suppose you are training your model, like you are getting 100 data points and you are training your model on, let's say, 80 data points. So on the rest 20 data points, you will have to test your model. So on those 20 data points, whatever the accuracy of your model is, you will report that accuracy because in the training, the accuracy will be high. But when the training part, the accuracy you get in the training, you cannot report that accuracy because the model is still training. So whatever the train model is, you have to test on a separate data, and you have to report that data to, like, engineer or, like, D company. So that accuracy we have to get. So it is necessary necessary for us to divide the data into the training and testing part. And what split we have to choose, like how we have to, like what values, how much data we have to separate for training and testing. Those all things we'll be seeing in for the videos. For now, just let's get started with the loading the data set. And for this whole data science and whole machine learning and this course, we'll be using Jupiter notebook. So you have to install Jupiter notebook into your systems. You can do it in two ways, either you can install Anaconda distribution and it will automatically install the Jupiter notebook for you, or you can simply install the Python into your PC, and then you can simply do PIP install Jupiter, then it will install the Jupiter Notebook. And how we are going to start that notebook, how we are going to start a server that I'll be telling you. Don't worry about that. And in this video, let's see how to load the data first into Jupiter notebook and how to take care of the missing values. Now, what is missing values, let me show you. So first of all, uh, Suppose this is our data. This is your data you'll be getting. So this is a sample data. This is very small data I have taken to explain you those concepts. But in the real world, Sandy will get much larger dataset. So in this, you can see some of the values are missing and everything. This is the country column, a, salary. And based on these three feature, you have to decide that it is the customer is purchasing or not. So this is the dataset. Now let's start my ubeter notebook. So to start Jupiter Notebook, you have to simply write Jupiter space notebook into your command prom. This will be working when you will install Jupiter Notebook into your system. So after PIP install Jupiter, then you will be seeing this. Now, let me create a new notebook here. So, let us name this notebook as data preprocessing. To convert a cell into a code column, you have to press Escape under cape and M. So this will convert into a markdown. So firstly, we'll be starting with data preprocessing. Now, first we have to import some libraries. So I'll just make a cell here. Import libraries. Now, what are libraries we need? So to load our data, you will need Pandas, which is a data science library, which is used to work with your dataset. Like the loading and everything you see, it is because of, we use pandas for that. And you'll also have to load NumPi. You'll need somewhere Numpi. Like Numbi is a scientific mathematical library in the Python in which you can perform all those mathematical calculations and everything. So I'll just import these two libraries. Now as these libities are imported, let me import my dataset now. So first thing is you have to import your dataset. Now to import your dataset, I'll create a variable in which you want to store your dataset. Now there's a function called Read CSV inside the Pandas library. Now why we are using this Read CSV Because here you can see this dataset we are having is a Microsoft CSV file, the comma separated value. So it is a CSV file, so we have to use Read underscore CSV function. We already have in built in the Pandas library. So we just have to use that Uh, okay. My bad. Sorry, read spelling is wrong. So here, here you can see the CSV is already loaded in the dataset. So here you can see. So this is our dataset. Now, here you can see this is the missing value, so it is redeted as NAN. So how we are going to fix that we'll be seeing. Don't worry about that. Now, we have to create our X and Y variable. Firstly, I'll create this X and Y, then I'll explain what exactly it is. I'll just remove the last column here and the values. Similarly, for the Y variable, I'll just take the column, last column, complete column here. These values in that. So now what exactly it is? See, in the supervised learning video, I have told you that in machine learning or deep learning, we have a set of features, and we have a target variable. Like in this dataset, we have our features as country is a feature, age is a feature, salary is a feature, and based on these three features, we have to predict this purchase column. Now in the X value, we have our features. And in the Y variable, we have our target value, whatever we have to predict. So this. And in the dataset ILogFunction, it will just simply take all the rows and all the columns, except the last one. This minus one is for last one. All the rows. This colon is starting from the zero through, I will count all the columns, except the last one. And this Y is we have to take all the rows, but only the last column here, column is not there, only the last column minus one basically in Python represent as the last value. So if you want to visualize this data, so sorry. Here you can see the X variable. And here if you want to visualize Y, small Y. So yeah, here is your target variable. And this is our X and Y variable ready. Now. Next step is what we have to do with this missing data because in machine learning, we cannot provide a data to be empty. The model will simply give an error because it is expecting some value there and you are not providing that value. So how do we fill this missing value? In the real world data set, we gather those dataset, you'll get a lot of missing values. So how exactly you are going to tackle with that? Now I'll create one more. Taking care of missing data. Now, this value we can suppose in this column 44, 27, 30, 38, 40, 35, and then an empty value, then 48, 50, 37. So you can replace this by the mean of this complete column. Like, suppose I'm starting from here 44 until 37, so I'm calvating the mean of all those values, and I'm simply replacing this NAN with that mean. We can do that because that is average value we are taking so how to do that? So in Python library named as SCLon. EC Larn is basically your psychic learn. This is a very important library which consists of all your machine learning tools. Every tools you're going to use in machine learning will be available in this library, SCLarn. And for deep learning, when you further see it is sensor flow. So in machine learning, this library consists of all those important, algos and all those important functions you are going to need. So you will get this in Sklearn library. So we'll be importing simple imputer from this library. Now what it is. Like, firstly, I'll create instance of this variable, simple imputer which we have imported. And firstly, we have to provide the missing values name. And that will denote NP NAN. Num Pi is basically it is a Numpi variable, and NAN value we are considering it as in the dataset, wherever it is NAN, then it is a value missing because as I've seen you, as you have seen C, as I've shown you here, the values are missing, but in the Panda, that is giving at a NAN because it cannot be simply missing there. And the strategy in the strategy variable, we are going to put mean what we have to do with the data set. So we are creating an instance of the simple imputer object. Now since our instance is created, we simply have to fit. This word is very important in machine learning. Fit. All and all in machine learning, you have to do this fit. So Imputer the object is created where we are seeing that missing values is N, and we have to replace it by a mean of those values. So in fit, we are basically providing our X. We are providing our X variable. We will be considering all the rows and one, two, three column, one, two, three, or even zero, one, two column. Now, here you can see the function ran successfully. Now if we want to visualize, if we want to see equal to imputer now dot transform. And here you will pass your dataset in which you want to. Like what this function did is it simply calculate the mean and it is you can consider this as a small model. This model is now trained in this complete dataset. So now you have to simply pass your convert your dataset, here you can see. Now if we visualize data set, so here you can see this NAN value, here you have seen this NA and value. And that NA N value is simply replaced by the mean of that value. So this is the simple imputer function, and with the help of that, you can take care of all those missing values. Now our dataset doesn't contain any of those missing values. So now our dataset is complete. Now in the next video, here you can see in the next video, I'll be showing you about something about this column. This column is like a ni country name here, but the machine learning model cannot accept that. So how we are going to tackle this, we are going to see in the next video. So till then, good man. 9. Encoding Categorical Data: Hello. Welcome back, guys. So in the last video, you have seen that how to load a dataset with the help of Pandas ad, and how to take care of the missing values. Now how to fill those values. There are different strategies, mean median mode, any of the strategy you can apply, all the things you have gone through. Now the next issue in the dataset which arises generally is the categorical variable, and we have to encode that categorical variable. Now, firstly, with the help of real data example, I'll explain you what exactly is a categorical variable and how with the help of code, I'm going to explain you how we have to encode that. So firstly, let's see what is a categorical variable and how you can find it. So let's jump into our dataset. So this was the sample dataset we are considering, and we have already filled these values with the help of fandom libraries. And in the last video, you have seen this. So now, what you can, like, guess here, what exactly is a categorical valuable? Like, can you guess so if you have guess right, this complete column and this complete column, these are your categorical variable. Now, what is exactly categorical variable? See, in machine learning in deep learning neural networks, they accept only numeric values, only numeric values, not any keyword or anything. They only understand numbers. So this country, this France, Spain, Germany, Spain, these are all keywords. So this is a categorical variable in there. So we have to convert this into some form of numbers, which is, like, converted into a number, and then machinery model will accept that. And this same the target variable, yes or no, we can this is relatively easy to convert. Suppose if we are putting no as a zero and yes as one, then this is zero, zero, one, one, zero, and this is all easy. But this France, Spain, Germany, Spain, Germany. So this is relatively typical work. So how we can do this with the help of Panda and with the help of Python. So let's jump into our code. Now I'll name this column as encoding the variables. Including categorical variable. Let me convert this into a markdown. So yeah, encoding categorical. Now, firstly, we'll be encoding our independent variable. So let me write independent variable. Okay, let me convert it into markdown first. Yeah. Now, for that independent variable, we have two libraries in our Python. In our SC basically, we have two packages which we have to import first. First is in the SCLarn library only, we have column transformer and another one basically we have is one hot encoder. And this comes under your sklearn dot preprocessing. We'll be importing one hot encoder. And let's create a variable CD in which I'll call this column transformer function, which we have. I'll create an instance of that. And the transformers. Firstly, I'll define it as the first able I'll giving is encoder. Then I'll pass this function. We have to pass this function in one hot encoder. How it will encode, you will see this. Don't worry. You will understand you'll be seeing this other working. How I'll pass this as zero and this is I'll passing. You don't need to understand all this code part. Just get what is categorical variable and how I have to encode that. I'll just run this piece of code and I'll get my categorical variable encoding. In the company, they'll be asking you what is this encoder, what is this one hot encoder? They'll not be asking you. They'll be simply giving you a data and you have to encode that. So just understand this thing. So I've created an instance, and now let's modify my X data. Currently, my X data is something like this in which this is a categorical variable. And now, if I process my X data, np dot AF sill convert this why I'm doing this because the output will not be a Numpi array, but I have to convert every processing in the machine. So inside this NP array will create the CT variable, the CT instance we have created, we apply the function fit transform to it. Simply fit under score transform. As I've told you, this fit is very important term in machine learning, and we'll simply apply this complete column transformation to this X array. And when I run this, it is already applied. Now let me show you X, yeah. So here you can see this column, the categorical column is converted to a categorical variable, one, zero, zero, three columns. Now, you will be wondering what it is, what is the categorical variable. So France, as you can see, France is converted to 100. Spain is converted to 001, and Germany is converted to 010. Now, next time you will see France, it is 100, 100. So with the help of these three variables, we can determine the unique value, France, Spain and Germany. These are the three unique values we have. So we can determine that. Now since we have encoded the independent variable, now just encode, let's just encode the dependent variable two. Now our dependent variable will be let me try this as dependent variable. And so from again in Library, escalon dot preprocessing, we have a library known as label encoder, because as I've told you, this target variables is simply the labels of our dataset. Now to encode this label, we simply have to firstly create instance of this class. Here you can see the instance. And now, I hope you are guessing what we are doing right now. Like we are going to do simply dot Fit. Again, same thing. Fit transform we will be doing, and then we'll simply pass the variable Y in it, and when we see the Y here, so here you can see it is converted to an array. Like before doing that, the Y is just like here, no, yes, no yes. So no is converted to here you can see zero and yes is to one. So zero, one, zero, zero, here you can see. Now, if we print our data like here you can see, the variable is converted to the dependent variable. So we have successfully converted our independent variable and dependent variable to the categorical variables in which format in which the machine can expect the machine learning model can expect. So this is all it. Now in the next video, we'll be seeing the splitting of data and the feature scaling method. What is exactly feature scaling and why we need to do that. All that we'll be seeing in the next video. Then pupa. 10. Feature Scaling: Hello. Welcome back, guys. So till then, we have seen that how to import the dataset, how to load the dataset into the Pandas library, and how to take care of the missing values, how to encode the categorical variable and how to encode the independent and dependent categorical variable. Now in this video, firstly we'll see how to split our dataset, like how to create training and testing set, which I've told you, training set is used to train our model and testing set is to just evaluate the model. And then we'll see into a very important feature, it's a very important concept, which is called feature scaling. Now, you must be wondering what is feature scaling. See, I'll show you with the help of the dataset we have. Uh, so here I'll show you. So here you can see this dataset. Like some of the features, these are the features which is having a value of zero, one, one, these are the values of having in the range of zero to 50, you can say you have a range of values 0-50. This complete column has a range. This complete column has a range of let's say zero to, I guess, one lack let's say one lack this is 83,000, the max value I can see. So one lag so this value is 72,000, and this value is 44. Now, what happens when you train a machine learning model that your model will eventually focus more on this feature. Why? Because it has a much larger value. Now, this is not the right way because all the features should have given equal weightage. Now you can see, if we train the model with this dataset only, then it will focus on this feature more because model will think that, Oh, this has a very high value, so this feature, this particular column might have a greater weightage on the outcome. So I'll focus more on that, but this shouldn't happen. Like, you should give weightage, like equal weightage to all the columns. So this is what we called as feature scaling, and this is the concept of the feature scaling. So we'll look into that with the help of Python code, how you can scale your features. And firstly, before that, we'll be generating training and testing set, we'll be splitting the data into training and testing set. So let's do first that. Dataset split, I'll name it as. Now, in the Ecalon Library, scale under model selection, you have a function named as train test split. So we have inputed that. Now you will create four variables. One is Xtrain. I'll explain to you what are these. One is X test. Another one is Y train and the Y test. So the first two variables, training set and the testing set. Now what is this X train and Y tran then? Like why are there four variables? Because in the X, we will have these five columns, and in the Y train, we'll be having the target values with the help of the five values, what we are getting in our target. That value will be having in Y variable and the training and testing those sets will be having. So how to split that we'll call that function train test split. And here we provide here will be pass of parameter, known as test size. Now, what is this test size equals 0.2. So this is basically your testing set size. Now in this as if you will see, let me show you here. The length of X variable. So we are having ten rows in our data sets, like ten data points basically we are having. So out of that, we want 0.2, basically 20% of the data in our testing set. And the remaining we want it as our training set. So when we'll be executing that, this particular function, we'll be having two values in our testing data and eight values in our training data. Now we'll pass Mar phone variable, which is called as random state. You can pass here any number, generally look like people pass it as 42. You can also pass it as one, two, three, any number. Like this is basically when you will split your data with a particular random state like random state, 42, then every time it will be splitted as same. And if you will pass a random stata different, then it will shuffle the data in a different way. Like you will see that let me show you here. When you see that Um, so here you can see the data is basically shuffled. Like 58 is here, but it comes here. So it is shuffled. Now, when you will pass the random state, again, if I execute this code, the data set is same. But if I pass the random set as one, then it will be different. Like C 58 is here. So this is what again, if I pass it as 42, then it will again be spreading at that way. So this is the concept of random set. Now this is your training set. This is your testing set. And this is the training target values, sorry, yeah. And this is your testing target value. So you have successfully generated your train and test set split. Now we'll be looking at how to basically scale these features. Like, these are the features we want to scale. Now I'll name it as feature scaling. Now, we have a library known as standard scalar in our Eklan dot pre processing. See, I told you that all those important functions we'll be using in our machine learning will be our Eklan library contains that. So in this we are having standard scaler and firstly, we'll be creating an instance of that. Standard scaler. Now we'll fit our data to the training variable first. Only we are applying to the training set. We are not modifying our testing set at all. Sorry, only we are applying this to this particular thing. We don't want to scale that because it is a target variable. We don't want to scale that. We just want to scale this so that our model can fit better. Now extrane you'll see we want all the rules and we want freeze column. Now I'll apply the St fit underscore transform train, all the rows again and the three columns we want. Yeah, it is done. Now, same we'll be doing for X test also. For all the rows again and S dot fit, underscore transform. We'll pass test here and same thing again, all the rows and only three columns. So yeah. Now if we see our feature will be scaled. Here you can see. So here is our scaled feature. This whole particular column is like these two columns, these are scaled into the value of minus one to one. So you're not exactly minus one to one, minus one, you can say minus two to zero or any value, but it is scaled. Now, the model will equally priatize all this similarly you can check for Xtexs also. Okay. Okay. I might have scale like this only. So this is what? Like your standard scale just scaled your values and you have now the model when you will train your machine learning or deep learning model, your model will equally weight all features. Like it will not give more weightage to this partular columns instead having a higher value. It will give equal weightage to all the columns. So this is a very good practice and it's very important when you train and when you will create your model of yourself, when you train a model, then these are very important steps that you should take, taking an appropriate training and testing set and training and also, one thing I forgot. So what value should be ideal here? You can take 0.3, also, you can take 0.1 also, any value you can take. So what should be the ideal value? Let's say, like, here, I have taken 20%. Like, see, when you have a very high range of value, suppose in your data points, you are having let's say 1,000 data points. Then you can take 70% of training data, 30% of testing data, it should be fine. But since suppose if you are having 1 billion data points, then it is ideal to take 98 or 99%, you can take 98% data in your training and one or 2% data in your testing set. Like testing value, you only require some values to test not a very big amount. So it's not fixed that you should have to take 0.2 every time you can vary all this thing based on your data set. So this is your data pre processing chapter is completed. Firstly, we have loaded the data set. Then we have fill like we have filled the dataset with the missing values, the appropriate mean values. Then we have seen how to encode the data, the categorical variable, what are the categorical variables and how we have to encode those categorical variables in both dependent and dependent variables. Now we have seen like how to train and test like how to create a split between training and testing data, how to scale your features so that your model doesn't overfit. Now in the next chapter, we'll be deep diving into the machine learning. What exactly like since till now you know what is machine learning, you might have some understanding what is machine learning. In next video, when you work with the dataset in the real time, then you'll get a better understanding about what is machine learning and how we are creating our models. And in the next video, we are going to create a lot of models in classification and regression and everything. So till then, see you in next video next chapter. 11. Linear Regression: Hello. Welcome back, guys. So in the last chapter you have seen the data pre processing steps, all the steps we have to follow first loading the data, then preparing your data, then encoding your categorical variable, then training and testing split, and then feature scaling everything, all that thing you have seen in your last video, last chapter. Now in this chapter, we are starting with machine learning. Now, you already know what is exactly machine learning. Now in the machine learning, it is you can divide it as four subparts. First part is your regression, then your classification, then your clustering, and then you hyperparameter tuning and regulation, hyperparameter tuning, basically. Now, as I've already told you, there are two type of learning, unsupervised learning methods and supervised learning methods. Now in supervised learning method where you have the labels already, that regression and classification comes under it. Where you have the labels, in your training data, you'll have your labels. But in unsupervised learning methods like clustering, you do not have your labels. Now regression is first machine learning algorithm which we study. Now, in simple terms, what is exactly linear regression? Now linear regression as the name suggests it is one variable. First of all, it is of one variable only. It is linear regreon. And secondly, it is a supervised learning method which finds you the best fit line between the independent and dependent variable. Now, what exactly it is? Let me explain to you with the help of any figure. So this is a figure. Like here you can see in your high school mathematics, you must have heard about Y equals to MX plus C, the straight line equation where Y is the dependent variable. X is the independent variable. C is your intercept and M is your slope. Now this particular thing is called your intercept. This is your slope, which basically the straight line angle from the XX is, it is called your slope. Why is your dependent variable? Why it is dependent because it is depending upon X and X user independent variable. Now, in linear regression, we have a value of Y and X in our dataset. Now, what exactly are those values? I'll tell you. Don't worry. So in linear regreon problems, you already have the values of Y and X, and you just have to find the best fit line, best fit line. This line you have to find out. And basically in simple words, if you see at the equation, this M and C value you have to find out. That's it. This is all like linear regression. And once you have this line, the value of M and X MNC, then in future, any value, like any value of X you will provide, the model will automatically calculate this Y value. This is all about machine learning. Now, in general terms, if we have to calculate the Y, we have to provide the value of M X and C, all that three values we have to provide. But simply if we provide a dataset and we train our model to determine the values of MNC by itself, then in future, only X value we will provide, then Y will be automatically calculated by the model. So this is your general intuition behind the linear regression. Now let's jump into the code to see this in more clear way. Now, this is the dataset we are going to use in this linear regression. This is the years of experience versus salary dataset. So here, this is your X variable, which we'll be putting in the model and this is your Y variable. Now, the person which is having an experience of 1.1 year is having a salary of 39,343. And a person who is having years of experience of two, which he'll be having 43,000 salary. So this is all our data point. 31 is for headers. So 30 data points we are having, let's train our model on that. Let us train our model on 20 data points, and the rest ten data points we'll be using to validate our model, how well our model is performing, like how accurate our model is. So let's jump into the code. Let me start the Jupiter notebook. This salaries data dot CSV, this will be using in our linear regressi while building the linear regression model. Let's create another notebook. So let me name it as linear regression. So first thing first come, we'll be importing some of the libraries, first of all. This is the first step. Now, let's import Numpi because this is the very basic library. Let's import Pandas. Let's import only these two first. This is enough to load our dataset. Second step, as you already know, which I have taught you in the data pre processing chapter, first thing is your data loading, importing your dataset. Now importing dataset, the dataset, let create a valuable dataset, p dot read CSV as you are already aware of these functions. You have seen in your last video. So if you want to visualize this, so here you can see this is our dataset. You can see here also, yeah. So this is your dataset. The head is basically your first five values. I will show you can pass here like ten also. So it will show the ten values, yeah. Now, let's create two variables. One is X. This is this column, and one is your Y, which is your salary column. So let's create that. Again, you are aware of all these I log functions. I've already taught you you will be selecting Oh sorry. You'll be selecting all your rows and your first column, basically the column except the last one the values here. In your basically, you will have the last column, all your rows first of all, and then the last column. Sorry. So yeah, I X, you want to visualize. So here you can see X. This is your first column, and the Y basically is your second column. So yes. Now we have our dataset ready. Now we have to split our dataset into training and testing set. So you already know how to do that. We'll be importing Ski learnt model selection. From that we'll be importing the train test and split function test split function. Now we'll be creating four variables X train, X test, Y train test. Now, you already know what all these four variables will contain. The X train will contain basically this value and y train will contain this value. So yes, your split. Now I will be passing X and Y here and the test size. Let's take test size this time as one by 330 3%. Let's take. Why? Because we have 30 data points. As you have already seen, we have 30 data points. So you can check here also, like data set. So yeah, you can check by this thing. Data set taught in four, I guess. So yeah, 30 entries here you can see. So 30 entries. So that's why I'm selecting one by three because the ten entries will be allotted to the testing set, and 20 entries will our model be using to train it. And random state. Let's provide random state this time zero. So that the first ten values will be coming to us. So basically what we are doing is we are training our model on the first 20 entries, and then we will predict by only giving our model these ten values, we'll be predicting this value and we'll match with the original data set that how accurate is our model. So let's do that. Side by side, you will also see that how accurate is our model. I'll write here splitting data sets so that it is not confusing. Creating data set. Now we have split it. So let's let's create our model. Creating our model. Now again, Scale learn how to create a linear model like linear regulation model, from sklearn dot linear model, you will import linear regulation. Now, firstly, you will create Firstly, you will create a variable here. Yeah, so instance of the class first you will create. Then you will simply call that fit function, and in the fit function, what you will pass is your training data, the X train and your train. This is your training data. So, our model is fitted. Now, if you want to see this, this is your model fitted. Now, let's predict the result. Sorry, this is take we have converted to So yeah. Now, let me predict now the results. And in your suppose let's create a variable Y pread where the model, this is REG is your model. I'll call a function predict. And as I've told you, I'll simply pass this test function. So let me show you what is that sorry test variable. And I'm not passing Y test because that is what we have to predict. So I'm passing this value 1.5 10.3 here you can see, Okay, this is like 1.3. This is 10.3. So these are all values we are passing, and we want to predict on that. So yeah, it has predicted. Now, let's jump into pipe pred. So for 1.5 years of experience, it is predicting 40,008 35. This is the predicted value of our model. This is not your basically the original value. This is the predicted value. If you also want to compare it side by side with the original value, so, here you can see. The original value was 37.37731, but the model is predating 40,000. It is almost close to it. See, the original value is one AC 22,000 and the R model is petting one c 23. It is almost close, our model is doing good. R model is working fine. Now that line I have showed you the line, the best fit line here, you can see this line. Let's try to generate this line also. For both the training set and the testing set, let's try to generate. I'll show you how to do that. We'll be using matplotlib library for that. So visualizing training set, let me write first. Now I'll be importing mat plot lip Pyplot as PLC. So Matlotip is basically your plotting library. Any type of graph, any type of figure, anything you want to plot in Python in data science, that you will provide like that you will be plotting using this Matplotlib library. There's also a library named as CBO. So that is also a visualizing library, which will help you create beautiful plots. So these two libraries are basically your visualizing library in data science. So let's do that. Let's write a quote for that. Scatter plot, I'll be creating BLD dot scatter. In that, I'll be passing a train variable and train and the color, I'll provide it as red. So yeah, here you can see, all those data points are plotted here. Now, this is not enough. So I'll be plotting that line basically. Train I'll provide and this regression to predict So yeah, up or line. So see here is our line. Firstly, we have plotted this data points, the X value, and then we have trained this REG on this model, on this dataset, and we have plotted a line based on that. So here you can see these data points are very close to line, but these data signs are very far. So the line will be generated in such a way that it is basically closest to all of the data points, like the best line. Like basically what I'll explain you just see. So what a linear eation actually do is how it is training the model? Like, let's go inside some however you do not need this much of that knowledge, but let's see them. For one linear euation I'm expedingRst, you can skip it. So suppose you how the model is training basically, how it is training itself to perform the best calculations. So basically, this is your data point, this is your data point, this is your data point, and this is your line. So it will generate a in line. Let's say it is generating a line like this, like here it is gene now it will calculate this distance, this perpendicular distance from all the data points, and it will now minimize this distance. It will adjust the line in such a way that it is minimizing the distance. So in that way, if we proceed in that direction, we'll be getting a line somewhere at a point somewhere a unique line. Obviously, a unique line, you'll be getting a unique line which is minimum, which is having a minimum perpendicular distance from all the data points. So this is how the calculations or it is the training inside the model. Inside this escalon, you have seen this linear regression model. How this is how the training is done. Now, let's also generate the scatter plot for our testing set also. Because in company if you are submitting, you have to submit as testing set only. You will not be providing the training set. Training set is only used for the model for use, train the model, not to evaluate. So yeah, this is a testing set. Now, let's plot that same line again. In this we'll be passing test and regressor or predict. Okay, the line here it is training sets because we are training the model on that training set, not on the testing set. Testing set is just for the evaluation. Here I'll be passing the training only. Wait, sorry, this passing testing only. All right, right, right, sorry. Now color is blue. So yeah. Sorry. So yeah. Here you can see this is our best fit line. Let's visualize it. So here is our best fit line. So this is almost on the point. So here you can see also some value. So value, some value, yeah one lack 16,537, it is almost same which what our model is predicted, our model has predicted. So it is almost same. That's why it is almost overlapping in the pointer. Next data point also. The next data point is your one, this one, I guess, right? 108, and this is 0109, it is almost similar. So here you can see, and this is your best fit line. So that's how you can create a linear simple linear regression model. Now suppose in your feature you have only one column. Suppose what will happen if multiple column will come. Now from that, the concept of multiple linear regreation will come, which I'll be telling you, which I'll be teaching you in the next video. So let's let's get done for that and let's see the multiple linear gation in our next video. He then prepare 12. Multiple Linear Regression: Okay. Come back, guys. So in the last video, you saw linear regression, simple linear regression. Now in this video, we'll be seeing multiple linear greation. As I've already told you in the last video, the dataset we are having is the number of feature column is only one. The number of independent variable X, the number of independent variable is only one. So here where the concept of linear simple linear giation will be applied. Now, if we have more than one feature column or you can see the more than one independent variable, we are not having the equation as Y equals to mx plus C. Instead, we are having x1x2, X three and till N. So what will be doing in that case? So let's look at the dataset first, then we'll understand better like this 50 startups dataset we are using. Now in this dataset, first column is the R&D spend, the second column is the administration, the second third column is the marketing spend, and third, fourth is the state. Now, this time, I have taken a dataset which is a little bit challenging than previous one because here we are also having each categorical variable. Now, this state is a categorical variable. You are not seeing any numbers here, so you have to basically encode this data first in order to fit in a machine many model. And the profit value we have to calculate. We will train our model on this complete data, not complete, basically. We'll be training this data on this model on 80% data, let's take 40 data points to train our model and then in the end, on ten data points, we'll be evaluating our complete model. Now, let's jump into our code and firstly, we'll preprocess the data, the conversion of this encoding and the conversion of this categorical variable into the numeric value, the encoding of our categorical variable, basically. Then we'll be creating our training and testing set. Then we'll be implementing multiple linear regulation model here. In multiple iteration model, like in the linear eeration you have seen we have only one best fit line here. You will have multiple best fit lines. And the equation is somewhat look like this. In the simple linear iteration, we have equation of Y equals to one plus B naught B node is basically your intercept, and this is your slope. And here, basically you will have b1x1, b2x to tell B&X one, the number of features. Here the X value N value is four. Like in R d doesn't, the N value is four, four feature columns we are having. So we will be having b1x1, b2x 2b3x3, and b4x4 plus B not Bauer intercept. So the equation will somewhat look like this. Now let's jump into the code. Let's create another notebook let's name it as multiple linear regression. Now, let's first of all, import some of the libraries, which we do in every video importing libraries. Here also we'll be importing Numbi pandas. Now let's import our dataset first. Importing data set. Now, import let's read a variable of named as dataset, p dot Red CS here. The dataset name was 50 startups dot CSV. And again, let's visualize this dataset first. Again, we'll be Sorry. Oh. This scroll is not working. Leave it. So this is our dataset. So this four column will be using at as our variable and this profit column is Y variable. So let's create that variable first. The set dotiLg will be selecting complete row of four columns, excluding the last one. This we are doing in a very that now Dataset dialog sorry, I'll be only using the last value sorry. Now let's specialize our X variable first. So here you can see X variable, and let's size or Y. So here you can see Y variable also. Now, let's jump into encoding categorical data. This is very important. Without that, the model will simply fail to train because the model cannot accept any non numeric values. It has to be numerical data only. So the two functions which we are using column transformer and one hot encoder, you have already seen those. So let's fit our model first, then we'll transform those columns. Column transformer and another o, let me input in cell only. Another one is ECLar dot pre processing. From that, library, we'll be inputting the function one hot encoder. Now let's create instance of this class this column trans former class where we'll be passing this transformer. This you have already seen. First, we'll be passing encoder. This we have discussed in the data science chapter, the module encoder, this function will be passing and the number of which is three. Now the remainder is the pass through only. Uh, this is not transformed. This transform. Now the variable ingredient let's fit our let's fit our instance into our data. Ct dot fit transform. And what we'll be transforming is our X. Now, let's see our X variable. So yeah, it is converted to a categorical variable. Now our X is not containing any non numeric values. Now we can do our modeling part. Now the next step of modeling is the data splitting first of all, split the data. So let's import from Skill Lar dot model selection. Let's import train test split. From this train X test, y train and test, we will import train test split. And let's take the test size this time as 20%. Basically we have 50 data points and on the 40 data points, we'll be training our model and on the remaining ten data points we'll be evaluating our trained model. Let's put random states 42. So yeah now let's see our train variable. So yeah, this is here it is and the Y train it is like you can see the length of the Y also. It will be 40 only. Yeah, it is 40. And if you will see the length of your Y test one, is ten. So yeah. On the 40 data points, we'll be training our model and the ten data points we'll be using to evaluate model. Now let's train our multiple linear regulation model. Model will be from again, sklearn linear model, it comes under linear regression only. So in my model, let's import linear regression. It is the same function will work for both one variable and two variable and one variable and more than one variable create an instance of the class first. Now let's fit our model into this training set. Now the model is fitted. Now let's predict our values. I'll put one mark down here so that it is clearly visible. Now let's predict test. Now let's see the Y pred. Original let's compare it with the original Y plus also. So yeah, here you can see the predicted value is 1926000. The original value was 1934000 so it is almost close. It is 84, it is 81. It is 9900099000699900. Wow, it is almost similar. This is 46, this is 64 so This is a little bit of difference we are getting here. This is 128, 145, 50, 35 also. So this is your basically the predicted result. Now to visualize it more clearly, let me set a print option here. I'll be printing it here you are getting this much of float value, so I'll be rounding off it to two v two precision. And let me print here. Combine the two the predicted value. The white test. As I reshape it as yeah. Here you can visualize it side by side. So these are the results. These are basically your predicted results, the first column is containing the predicted result and the second column is containing Original results. So here you are seeing apart from some data point this or this, we are getting almost similar results. We are not getting much difference. So our model is working fine only. So this is what this is how we train our multip linear regation model here. And if you want to create a regression model and you have more than one feature columns, then you can use this multiple linear regation. And basically, this will work for both the multiple columns and the single columns. Now, there are a lot of more like regression models also. Like there only in linear regression, only simple linear regression and the multiple g are not there. They are all multiple models. Like some of the models, I'll name it here so that you can. So some of the models like polynomial regression, we are having the one more I name it support vector regression. As we are it is named as there is one more called as decision tree regression. One more it is random for S regulation. So these are all more, some of the more regression models. So I'm not going to teach you all of them in this single course. So the format is same. Like here, the format is almost same, some of the bit theoretical concepts are involved. And then firstly, you have to whenever you create the dataset, you will have to pre process the dataset, you have to check whether I have missing values or not, you have to rectify those corrections and rectify the problems and you have to fill in that missing values with either me median or mode, and then you have to create your training and testing set, then you have to scale your features. I also, if any, variable is non numeric, then you have to convert it into the categorical variable. An categorical variable then then you have to encode that, and then you have to get ready with your training and testing set, then you have to choose the test size, and then you have to apply the model. So Suppose you are getting a dataset like this 50 startup dataset on and you can what a company expects you as a machine learning engineer or a data scientist to apply all those models, like simple multiple linear regression, polynomial regression, support vector regression, dicigent reregreson and random por, all these five models you will be applying. And after that, you will compare the results and see. Like in some dataset, you are seeing that Oh, support vector regression is performing the best accuracy or this difference between the data points. I'm getting very less. So you will report to your company Hello, sir, I have performed all these five models. I have implemented all these five models and I've checked the accuracies. And I found that the support vector regression works best for our model, for our data set. And here, take your trained model. You will provide the train model. So you can use that, sir. You can use that model. So this is what a company expects from you as a data scientist. So you can study those further models also, and in the next video, we'll be looking at the classification algo. Like, what is exactly the classification and how we are performing? And what are the algorithms for that? So till then, see you in next video. 13. Logistic Regression: Hello. Welcome back, guys. So in the last video, you have seen the multiple linear regression. So you have completed the regression part of the machine learning. And I have also told you that we don't have only two algorithms in, like, linear regression, the simple linear regression and multiple linear regression. We have some more algos also, and you can look them by searching Internet, Internet. And if you want to look at in much deeper detail, you can also just some minor changes you have to do with your code, and then you'll be ready with your another model. All those models are pre implemented in your R skill down library. So you just have to learn the basic procedure then you are good too. Now our regression part is completed, we'll be moving to the classification. Now, as you have seen, what the problem statement we are getting till now is that we have to calculate a continuous value, continuous value. Let's say, 40,500 this type of value these are called continuous values. So these are all values you have to calculate. Now in classification, you have to classify those features into a particular target label, the given target label. Now I'll show you first the dataset, what exactly our dataset looks like. Then you'll understand better here you can see the social networks add a dataset. This dataset we are considering. The first feature column is your age. The second feature column is your estimated salary, these both are given and based on these two features, you have to classify whether a person will purchase it or not. Like the age is given, the salary is given. And based on this, you have to classify it between the two target variables. Either the output should be zero or the output should be one. This is called as binary classification where we have the two output label. And there is also in your further data future data set which you'll be working on, you will see there are multi classes like zero, one, two, three, or let's say cat dog, grab it. These multiple classes can be there. So there, that procedure is different. That is multi class classification. But here we are just using a binary classification. Now, what exactly is logistic regression? Now in linear regression, you have seen that you have to generate this best fit line, and based on that, you have to classify based on that, you have to calculate the data points. Now suppose this is your data points you have plotted is like this. Now, the best fit line is like here you can see data this distance is too much high. This is too much high. So best fit line is correct, but still it will still give us a lot of error. Now, in logistic regression, here you can see the curve of logistic duration is somewhat like this. Now it is more perfectly balanced. So in the logistic regression, basically, we have our data points like this, and this curve, basically we called it as a sigmoid function. Now you can see here. So this is your sigmoid function one by one plus E p minus X. So this is your sigmoid function which will give us an output minus 0-1. And in Sigmoid function, basically, how we are classifying those data, you can divide here in this middle part. You can divide it as a two part. And if the output is greater than 0.5, then you will classify it as one class, and if it is less than 0.5, then then you will classify it as 00 class. So by this, the classification will be performing now you have to train your model in such a way that based on your input feature, the model will output any value 0-1, and now on that zero to one based on that zero to one value you are getting, you can classify your data points. Now, let's train let's create our logistic relation model on this dataset, then you will understand more better what I'm trying to say. Let's create our very first classification model. Let me open my Jupiter notebook. This is our first classification model which we are working on and understand this logiton very carefully because this is the base of your deep learning. Like, you will understand what I'm trying to say later on when you study deep learning, but this is your base of deep learning. From here, only the journey, like the path of deep learning starts. So see this way very carefully. Let me name it as logistic regression. Now, first thing, first, we have to import our dataset. So I'll impo sorry, first thing is not importing data set, importing libraries, my bad. So let's import Numbi and pandas. And now let us import our dataset. Sorry. Now let us import our dataset. Importing the. And let me create a variable name as dataset in which, again, this pd dot read CSV. And in that, we have our data named as Social Network Ads. Pandas read CSV we are having. Now, if we visualize our dataset, you can see here. So yeah, this 400 data points we are having in this dataset where your age is your first feature vector feature column and estimated salary is another feature column. And based on that, you have to classify, you have to predict this third column, basically. You have to predict this. Either it is zero or it is one. Now, let's create our X and Y variable in which already you are already familiar with this, where we are taking all the rows and all the columns except the last one because last one is our target value in unsuper learning, okay? Sorry, colon my bed. Now, you can see X here. So in X, your first column, your second column. Now, similarly, same thing we'll do for Y also in which we are only taking our last column, not all the rows of the last column. Dot values. Now if we see Y, so here you can see. This is your output level. Either it will be zero or it would be one. Now let's split our data. Split our dataset. This is a second, third step. Gain from kilon dot model selection, we'll be putting train tests and split. And we'll be creating this four variables White test one. And I'll simply use this function which we have imported faint split. Now let's do one thing. Let's train model on the 300 data points and let's evaluate model on rest hundred data points. Let's do that. So we'll be passing X and Y, and the test size for 300, we have to divide our dataset into 2321. So basically, 300 data points, that means 75% of the data should be in training. So the test chits should be 200.25, 25%. Now I'll provide random state as zero. So yeah. By this, if you will see the Xtrain, so yeah, it is 300 and if you will see the X test. So it is 100. So yeah, we are good to go now. And the training and testing is ready. Now the next step in the next step, we have to scale our features here. This is very important because here you can see the first feature column and the second feature column. The first feature column is ranging somewhere between zero, 200 and the second feature column is ranging between 02, let's say one lack. So a lot of there is a lot of difference between the range of these features. So we should scale that. If we do not scale that, then also the accuracy will be okay. But if we are scaling it, the accuracies will further improve. So let's do that escalon. Let me write this as feature scaling. Now, let me import those standard scalar variable from Eklon dot preprocessing. And let me create an instance of this variable standard scaler. Now, the instance let me fit this model in this variable into our X training and testing. X variable, we want to scale the data. Why we do not want to scale. So this is your fit transform in which I'll be passing X tran. Similarly, we'll do it for X test also. S dot fit transform where I'll be passing T. So yeah, our feature is scaled now, if you will see. So yeah. The initial X features were this 19, 19,035, 20,000, and now it is scaled between near values. So yes, the scaling is done for our model. Now our training and testing set is ready to be input into the model to feed into the model. Now let's create our model. From klar dot linear model, Import logistic regression. There you have seen from the linear model, we were importing linear regression. Here we are importing logistic regreon. All those packages are in this library only. So I'll name it as classifier and I'll create the instance of this first logistic regression. And here we have to provide a random seat variable. Zero we have provided. Now this classifiers the logistic regression instance is created. Now let me fit our data points into that. Fire dot fit, X train comma Y train. Variable is created. Now the model is ready. So to predict those results, let us predict some of the results so that you can get better idea. So let us do one thing. Let us create let us predict for any particular value. Let let us open that Excel sheet first. We'll be predicting a class for a particular value. Let's say we want to predict for this class, let's say. See if our model is working good or not. Okay, so this class, I've just copied it down here. Now what you will do is you do classify dot predict and you will pass ac dot. Okay. Now one more thing. Here you are passing this value. Again, it is non skilled feature. Your model is trained on the scaled feature, but here you are passing simply your non skilled feature. The model will be giving us the wrong value. So you have to scale those features first, then you'll be passing these values. Now let's do that. Again, I'll be doing ac dot transform. Because essays are like class, I'll create one array between I'll pass 32 and 154 times zero. So it is done. Now let's predict that. So yeah, array is one. So it is giving us the correct. Let me write it down insider print statements. So yeah, it is giving us the result as one. If you want to write this, sorry. Yeah, it is giving us the credit result. One. Now let's print for another. Let's say this value 20 and 86,000. Let me print, again, what was that? 20 and 86,000? 6,000, so the value we are getting is zero. It is predicting correctly. Now let's predict for all the testing set. Let us predict the values for all those testing set. We'll be passing ClassifitPredt, and we'll be passing the complete testing set. Now if we see the Ypread, so yeah, this is the complete prediction. So let me print it so that you can visualize side by side.com. I pad why bread. Underscore hit test. Again, I'll be reshaping that. I'll reshape my length only. That is correct. Right. I think it is right. Okay, here, that's what I was wondering. So here I miss one para. And after that, here also, I put one. So yeah. Now, see. These are your prediction and these are your original value. Here, somewhere it must be meting. Here it is making a mistake. The prediction was zero, but the original value was one. Let's create an accuracy for that. How you will know how well your model is performing. So let me create a confuser. In machine learning, you often use this as a very primary evaluation matrix, let us generate both the confuson matrix and your accuracy also. Sorry. I'll say confusion matrix and accuracy. So from Sklearn matrix, you will be importing these two things. First, the confusion matrix and second, the accuracy score. It is not metrics matrix. Now, you will create an instance for this confused matrix class and you will pass firstly your original value, then your predict test set. Why test, and I piled. If I print this confusion matrix, so yeah here this is what your confuser met. I'll brief you that. Let us calculate accuracy score also. Let us see how well our model is performing first. So yeah. Accuracy we are getting here is 87%. So 87% accuracy we are getting with the logistic regression model on this particular dataset. Now, what is this confused and matrice? So in confuser matrix, let me show you here. So let me like this. So Yeah. So basically, this particular column is your basically like this are your, let me 1 second. So yeah, this is your basically the actual value versus preted value. Now, 123 data points are those where you actually it was yes and your model is predicting also the yes. And this is your basically false positive because the actual actually the model was telling it as yes, but the model is patted no. And here, actual it was no, but the model has petted yes, and here actually it was no and the model has patted no. So these two, 123 and 161, these two diagonal are basically your correct prediction, and these two are wrong prediction. So here what is happening? 63 is your correct prediction. That means social network add, the value was actually zero, and your model is also preting zero. Here the value was one and your model also was predating 24 values. But here, the value originally was zero, and your model is telling no it is one, so this is your false positive. Now, this is what a confusion matrix is. By the help of confusion matrix, you can evaluate your model. We use this to evaluate our model. So this is your accuracy, and with the help of logistic regression on this social network a dataset, you have achieved an accuracy of 87%. So this was your classification problem. Now, I hope you get to know what is exactly how you do in classification, what is exactly a classification problem. And this is a different problem from linear regression because in regression, you have to calculate a continuous value, but in classification, you have to give your output into yes or no or zero or one or any particular target variables. So this is it. Now in the next video, I'll be creating an SVM model, we'll be working on the same dataset, we'll be creating a classification model, but we'll be creating and we'll be training an SVA model. Let's see if the SVA model can perform better or even worse. Let's see all that in next video. There are multiple classification models basically, and in the next video, we are going to cover the SVM. So let's see all that in next video and then good bye. 14. Support Vector Machine: Hello. Welcome back, guys. So in the last video, you have trained your first classification model in machine learning with the help of logistic regression. And in this video, we'll be training an SVM model. We'll be using the same dataset. We'll be using the same procedure. But this time we are using another model, which we called as SVM, support Wester machine model. So let's jump into our code. This same dataset, the social network ad which we used in last video, the same dataset we are using, but I'm changing here, the model. All the procedure will remain same. I'm changing the model. So let's create another let's not create a separate notebook for that. Let let us create a clone for that notebook on. So it will save us, I'm not going to bore you with writing the same code again and again, which is of no point. So, let us move that notebook and let us copy one notebook logistic relation here also. Now, here if you see logistic regulation here. So I'll name it as SVM now. And you see in this video, you'll also learn that if we want to change only some part of, if we just want to change the model, like in the start of the video only, I've told you when I was explaining how the industry works, then in the industry, if you will work as a machine learning engineer, then you will be provided with a data set. You will have to if your role is only as a machine machine learning engineer, then you if you are only modeling that, then you will be getting your data cleaned data. This is your basically, I can call it as clean data. Like, there is no missing values, or the features are scaled, the training and testing set, everything you have done, the complete EDA part. So this data you'll be getting and you have to simply apply the model. Now if you are working as a data scientist, let's say, then you have to manually clean, then you have to use your data science knowledge and you have to clean and process the data also, then you have to train the model. Now, what your manager will ask you to do is he'll provide you a dataset, and he'll ask that which of the classification model works best on this supposed let's social network at it'll ask you, we should use a logistic relation model or we should use SVA model. So what you can do is you cannot directly tell. A lot of after gaining a lot of theoretical knowledge, you can guess also which model can work best. But this will come after a great experience. You cannot directly tell, and neither anyone cannot directly tell even I cannot tell that this model is perfect for this data. I'll have to train that model and evaluate the accuracy I have to see, then only I can comment that this model is great. So let us first import our library that'll just run the cell here. Let us again input the dataset. Our dataset has this much column, let us create X variables. Now, Y variable, now our X and Y is created. Let us split the dataset. I'm just re running those codes because we have already written those codes, so it's a wastage of time if I write the same code again and again and show you. Now, yeah, here you will be changing. Now in SKLarn you have, firstly, you have to import here, I'll write SVM model. Let me write here SVM model. Now from sklearn dot SVM, you have to import SVC and the classifier you will be creating as not your logistic, you will create as SVC classifier. Now, kernel, you will set as kernel. Also here are a lot of options like RBS kernel, linear kernel. This dataset will be using linear kernel. You can explore the documentation also to know about more kernels. Random set. So here, the classifier is the instance is created. Now if I fit this classifier into the dataset, yeah, the SVC model is now trained. Now, if I predict our same thing I'm writing with the SVM model. Now, bred so here it is giving us the correct output again. Here also it is giving the correct output, one and zero. Now if I predict all those values. So yeah. Now let us see the accuracy here. With the logistic, we were getting an accuracy of 87. With the SVM, we were getting an accuracy of 88%. So there is 1% jump in the accuracy. So you can see when, if your manager is asking that which model will work better for this social network at dataset, then you will simply report that, sir, I have tried logistic regulation and SVM, and the SVM worked better than logistic region in this particular dataset. Now you do not have only this logistic regression and SVM model. We have some more models. I'll name it as here, LR and R is basically a logistic regression and SVM is your support Vtor machine. These two we have explored. Now there are some more models like KNN K nearest neighbor. I'll write it like this. K nearest neighbors, which is your KNN model. This is also a classifier. Then you have your kernel SVM. This is also a different type of classifier. Then you have your very famous naive bias, which works on binom the base theorem. I hope you have studied base theorem in your high school 12th mathematics. So that same base theorem is the central concept of this naive bias algorithm. So this is also very famous. Then your decision tree decision tree. Generally, the model in which the fraud detection and that the Indian bank fraud detection, those are all model is created with the decision tree. So this is also your classifier. If you want to deep dive into machine learning, then you definitely you have to learn all these, you should know all these algorithms. Suppose if your manager is asking that which algo is best for my dataset, then you will not simply say, D, sir, I've tried LR and SVM, you have to try these also. You have to implement these algos also. And then after this six elbow you will report that, okay, sir, suppose naive bias about bison you will say, sir, I have tried the six algos and naive bias is the best one. The accuracy with the naive bias I got is the best. So this is your classification. This is your end of the classification chapter. And now, in the next video, we'll be seeing clustering. Now what is clustering and how we implement that we'll again, consider a dataset and we'll be implementing those in Python. So yeah, see you in next video. 15. K-Means Clustering: Welcome back, guys. So till now, you have seen you have learned about regression and classification. And in this video, we are going to see clustering. Now, till then, basically you are working on supervised learning where you have your target variables, your target column. And from now, in this unsupervised learning, the clustering comes under unsupervised learning. So in this unsupervised learning, you do not have any target labels. You will understand this in more clear way when you will work on a problem statement, and I'll show you the dataset. Then we'll be learning more. Like, I'll try to explain you with the help of a figure first. So here in this figure, you can see, we are having if we plot all through data points in a XY plane. So suppose don't ignore the colors. Suppose all of them are one, all of them are data points plotted on a XY plane. Now, you have to cluster. You have to form a cluster. You have to segment this dataset in such a way that these features are similar to each other. These features are similar to each other, and these features are similar to each other. And you have to cluster like that. So in this, we are not providing any target labels. The target labels the model will identify by itself. Not exactly the target labels, but the cluster, the similarity between those features, the model will identify by itself. So and another picture, yeah, here you can see this green cluster is a separate cluster. This blue color points, data points are separate cluster, and the red color points are a separate cluster. Similarly, if you can see here, like here if we want to. So you must be wondering that what is our model C. Here you can form a cluster like this also. You can form this two circle as a complete cluster and one is. So if we take the value of K, in this K means clustering, basically, if we take the value as K goes to two, then it will form a cluster somewhat like this or any type this or anything. Like suppose this whole cumulative this collective value is very similar to suppose let's say this, then it will form a cluster like this and how it is forming this cluster. Now, if we go deep into its mathematics, you will see that it is forming a cluster based on the euclidean distance. So Euclidean distance is basically all those data points, it will have a centroid. Now, from that centroid, it will find a distance euclidean distance like Euridan distance you must be aware of in your high school mathematics, the X two minus X one hole square plus the y two minus y one hole square and the underroot of hole that thing. So that is your Euclidean distance in Xi plane. You will calbate that euclidean distance, and if the euclidean distance is smaller than the previous one, then you'll update your centroid and you cluster moves here. So by this a general rough idea, the clustering algorithm is actually working. K means clustering actually works. Now let's jump into let's visualize our dataset first. So in this, I'm taking more customers data set. So here you can see. So yeah, this is your dataset which we will be working on in this video. Now, you can see we have four feature columns, basically. This customer ID, we can ignore because it's just an ID, so we can ignore that is not a feature. Male, female is the feature, A is the feature, annual income is a feature, and spending score is a feature. So these are features, basically, these are all customers. So we have to form the clusters between the customer who is having the similar type of, like, you know, features, like similar type of suppose any type of feature that the model any type of set of rules the model will identify, we have to form simply cluster. We have to segment our customer in this dataset. So this is our problem statement. Let's jump into the Jupiter Notebook to perform clustering. Let's see how to do clustering in Python and how to get data ready for that. So I'll quickly open my Jupiter notebook. So yeah, there it is. Now, let me create another notebook named as K means clustering. I'll name it as K means clustering. So I'll name it as K means clustering. Now, first thing first, we want to import some of the libraries. Import NumPi as N P. Sorry, importing importing libraries. Now let's import Nampai and Pandas first. Now we have imported our library. Now let's load the dataset. Now, let's create a variable just like we were doing in the past, red dot CSV, and in that I'll pass mall underscore customers dot CSV. Pandas library readad sorry, this is read CSV. Now, if we look into the dataset, so yeah, here you have. These are 200 data points we are having and like five feature vector we are having. Now let's create our X variable. So in this X variable, basically, you will be including iloc and you'll be selecting all your rows and only three to four columns. Now I'll show you what it is. Sorry. This is a column. S. So here, basically, we have discarded all these features. Only first, we are considering these two features. This can also be a feature, but I'm considering here only two features, annual income and spending score. Based on this two feature, we are clustering our customers. So let's try to do that. Now, how to form a cluster. There is a method called as Elbow method. Like, based on, you must be wondering that how many clusters we have to form, how will we identifying that? Like, how can I identify how many clusters I have to form? Like, suppose in this video, it is clear from the dataset. Like if I remove the arrow from here, then it might not be clear that much that how many clusters you have to form. Here you can simply see there are three clusters, but how to identify this number? This K value, basically. So for that, we have a method called as Elbow method. Now, I'll import first the clustering library from Sk dot clusters, I'll import K means. Now, I'll create one empty A list. Okay, it's not clusters, it's cluster. Now I loop it through from I in. So I'm considering values 1-11. We can find it from more larger values, but here, I'm considering only one to ten, basically. Either clusters, number of clusters will be one, either it will be two, three, or it will four till ten, we are considering. Now, for each value, I'll be forming clusters. Let's do that. Means here, I have to pass the number of clusters. Number of clusters is equal to I and in it, I have to pass here K means. And I'll put it as random sits. Let's say 42. Okay, sorry. So yeah. So after creating an instance of that, when the first time the loop will run, it will be forming one cluster, then the second time it will form two clusters. So every time we are wearing that. Now let's fit our model for each time for each time we are fitting our model. And in that WC SS which we have dated first, I'll simply uppend that. You thought it is giving an error. Why it is giving an error. X, we are taking it correct. I guess I should work fine. Let's go that error. By Googling, we get sorry. K means luster in item fit method. Yeah, so documentation, I'll be seeing. In this innate K means plus plus or random, we are number of clusters parameter, we are putting it as right. We are doing it correct, right? He means outfit, we are doing right. If I let me do this way first. Let's see if it run. Still giving an error. No attribute split. We are not passing any attribute a split. Here it is passing number of clusters and random state. Let me remove this in it. Let's see. Still, it is giving an error. Let me pass here. Oh. Let's say I'm giving cluster as four. Yeah, it is running perfectly. Then why it is not running here? If I pass one Yep. Okay. Okay, so for the value one, it is not running. Okay, okay, okay. Okay. So let me pass it as from two here and let me do all the things that we only. So yeah, it ran. For one, it is not running because the cluster should be minimum two. Okay. Yeah. My bad. So see from here, basically starting from cluster two to ten, we are having all the value. If you see WCSS, you can see all these clusters value you have. Now, you will not understand what it is exactly. Now, you will understand when we'll plot this. Let's plot this first with the help of MD plot Lib. Let's plot PLT dot plot. Let's plot those values first. From range, sorry, again, two to 11. And I'll simply plot this WCSS. Yeah. So this is what your elbow method is. Now, let me start my two. Let me do it till let's say 31. So, it will take some time to run. Yeah, it is run. Now let me plot. He also 31. Um Okay, sorry, I have to re initialize this. It is basically appending that in previous one itself. Like in the previous WCSS it was having the value of 99 values, and it is just appending that. So yeah, now it will be running fine. Yeah. So here you can see it is forming an elbow. It is forming an elbow. If for more data points, I'll be doing this, suppose I'll do it for 51. Let's run it for 51 and let's see the results. Like, basically what it is doing is it is initializing with the cluster, it is model we are giving model that will take the dataset and form two clusters for me. So it is forming two clusters. Then I'm saying, take this dataset and form five clusters from me. Till 50, we are telling him to do. Now here you can see the elbow is formed. Which is the appropriate value for our cluster? Like, which is the appropriate value? How many clusters we should take. So basically from where, like, here you are unable to initialize because, like, from this point, if you see from this point, the curve is almost similar. Like same. The curve is stagnant here. So this value is your the elbow is basically the corner of your elbow. That is your K value. So if I'll run this for only just let's say ten and I file plot for ten. So here you can see after fifth value, it is almost same. It is almost same. You are not getting any corner edges after fifth. So let us take the appropriate clusters. The appropriate clusters, which is this dataset is perfect for is the five clusters. So now, we'll be creating our final model as K means number of clusters as five. Then in it equals K means plus plus. Then I'll pass random Street as 42. Now I have created my model now two wife let me do some predictions with this trained model and fit underscore predict. So yeah, these are my results. Basically, what it has done, it has basically the whole data points. The first customer is cluster is thrown into the second cluster. The zero, one, two, three, and four cluster, a total of five clusters are formed, and these customers have categorized into the zero cluster. This has categorized into the fourth cluster. So all these customers you have segmented. Now to visualize this in a perfect way, let's visualize this more beautifully. Now it's time four visualizing. Then you will get better understanding. So let me create a scatter plot of variable 1 second. Yeah. The Y means we were having is equal equals zero. Again, Y means is like here. Let's take zero comma one. And here S equal 100. Let's take it as 100 and color, let me give it as red. Label will be providing us. This is the cluster one, so let me provide the label as cluster one here. Now, similarly, we'll form total of five cluster. We'll create scatterplot full of five clusters. Now here, this is the one value, two, three, and four. Here, also, we have to change one, two, three, four. Yeah. Now, color also we have to vary. Let's give it as a blue color. Let's give it as something else red green color, sons and just give it as magenta. Cluster two, cluster three, cluster four, cluster five. Now if we plot this C, this is what I'm trying to show you. So basically, your first cluster, your first segment is your red. This is your cluster one. Blue is your cluster two, green is your cluster three. This color is your cluster four, and this is your cluster magenta cluster five. So yeah, like this, now you can see all those data points which we are having in our datasets, we have clustered them. We have successfully applied the clustering algorithm to it. So this is what your K means clustering is, and this is what you unsupervised learning here, you will see we have not created any Y variable because we do not require Y target variable here. So this is basically unsupervised learning because we are not providing any data, like any target variable here, any labels. Now there is one more clustering algorithm, which is named as hierarchical clustering. So you can read that also, and you can go through that. Now you are familiar with overall machine learning, what we do in machine learning and how we are creating the models, the regression models you have seen, the classification model you have seen, the clustering models you have seen, both supervised and unsupervised learning, everything you saw. So by this video with this video, we came to an end of the machine learning chapter. Now pretty much you know, I'll not say everything, but some sort of things in machine learning. Now you can proceed with your machine learning things. So tell like this is the end of the chapter, and yeah, all the best. 16. Project 1: Breast Cancer Prediction: Hello. Welcome, guys to the first project we have in this artificial intelligence course. So you have already learned about different machine learning classification algorithms and regression and clustering and everything, and you already know how to preprocess the data first and then model it and then do the prediction out of it. So now, as much as theory, you will learn, as like too much of theory is not like what I used to explain. Like, I have explained to you the basic theory, and now we learn more from the projects. And in my like what I believe is due to theory, like, with the help of theory, theoretical part, you cannot learn that much with the help of projects and the live like the practical implementation. When you will encounter any real world data set and you will have to you have to process that and you have to create model for that, then you will learn more. So that's the main purpose of this project. So let's find a real world dataset, and it will be an impactful dataset because as you can see the title, it is breast cancer prediction. So this is also an impactful project. And with this dataset is also cleaned before only this is available on UCI repository. I'll show you that. So it is cleaned already, so you have to, like, select the feature, the important features out of it, and then you have to model it. So let's do that. We'll be using machine learning for this approach and we'll work on Wisconsin dataset. Like, let me show you the first dataset also. So this is your breast cancer Wisconsin diagnostic data set, and it is available on UCI Machine and repository. So see this repository is basically it contains many machine learning datasets, many. Like any datasets you want to work on, suppose you want to work on any particular, like, let's say, regression data set. So you can find it here. This is a very good website for all the types of datasets. So this is your breast cancer Wisconsin dataset, and in this, we have a number of instances. This means the number of data points. That means the number of rows we have in this dataset. L 569 data points we have, number of attributes, that means number of features are 32. Not all features are important. So we'll select some of the features and we'll try to predict. Like, obviously, if you have to if your model needs 50 features for classification, and one model need only five to ten features for classification. Obviously, five to ten features, classification will be more good because your model is needing less information to predict. But the more number of features like the 50 number of features model will be more robust. Like, what is the meaning of robust your model your model is more prone to any type of changes in dataset. Like, your model will be more strong enough to encounter any type of prediction through any type of prediction. So more number of features if we are available, if we have more number of features, we can definitely consider all the features, but if we don't have, then there's no option. So we have to consider the words like features only. So in this dataset, we'll see what features we are selecting. Let's select some of the features and let's try to do prediction. Also, we'll be implementing multiple models here, not just one model. So let's also see that. And let's jump into the bra notebook and we'll start the project. Let me open my children notebook. So this is our dataset. I'll show you in that pandas only. So title for this project, I'll give it a simply name it as Project one. And let's import some of the libraries first. As you know, the first step we do this importing libraries. Let's import Pandas and Numpi for now. If we require any more libraries, we'll input that. Let us create a data frame. This is a CSV file. So I'll write p Reads under CSV. Let's see our dataset. So yeah, this is our dataset. Now it has ID, diagnosis, radiant. These all are your features. Radian perimeter mean mean area mean, these are all your features. Like, these all things like these values are your features. And yeah. This ID is of no use. This is not a feature. We can remove that, and we'll select only five feature for now to do our prediction. And this is what is our target value. This M and B. M is basically your malignant and B is your benign. Malignant means the data points are basically this patient is affected with the breast cancer, and benign means it is not affected. So yeah, let's select those. Let's first of all, try to see how many columns, how many data points and total number of columns we have. Let's see that. That we can see info. Yeah. So total 569 entries, it is mentioned on the UAU CI repository also. And these are all your features. These are float values, and this is diagnosis. So this is our target value. You have to identify your target value by yourself only, or you can identify that obviously. But yeah. Now, let us clean the dataset first so that we can we can model it. Data cleaning, I'll say. And let me drop this column. This unique ID column. You can drop it like this tf dot columns, and for that, you can drop it like minus one. First column, basically. Make this one equals. Place equals true. Okay. Okay. So yeah, the column has been dropped. So here you can see, we have dropped the unique ID, the first column basically because it is of no use. It is just a unique patient number. Also, let's try to see how many dataset we have for malignant and how many we have for benign. Let's try to see that. We can see this by TF diagnosis. So yeah, here is it and we'll do simply value counts. Okay. Yeah. So benign B value, benign, that means that data points is not affected by breast cancer. We have total 357 and malignant, we have 212. That means 212 data points we have four, which is affected with the breast cancer and rest we have, which are not affected by breast cancer, the benign. Now let's select all those features first and then we'll be modeling that Let us write it as feature selection. Okay. Yeah. Now, first, let us import this train test split also. Eklont selection. From that, we'll be imputing train test and split. But and also for this value, we have to convert it into the categorical variable. And here we are only two variables, so we do not require any simple like one hot encoder or anything. We can do it by ourselves only. Just we have to replace M with some value like let's say one value and B with zero value. So I'll create that d map. You can do this with the help of Panda I'll show you how.Fly I'll create a dictionary where M belongs to Ls one and B belongs to Ls zero. So this is our diagnostic map, and let us apply that into this column diagnosis. You can do this by a This is basically we are saving into this diagnosis column also. Like what we are applying, what we are changing into the column, we are saving that also. Dot map is a function where you can provide a dictionary, and this will simply map your complete data frame. Now, if you'll see your dataset, so here you can see all the M has been replaced with the value one, and all the B has been replaced with the value zero. So you have converted this non numeric value into the categorical variable. Now let's select, let's say, five features for our modeling purpose. Let's select all that. I'll see this radius. I'll select this radius mean as one value, the perimeter mean as second value, area mean our third value. I'm just selecting randomly those features, concavity, sorry, concavity mean second value, fourth value and concave mean points. These are our five, okay. Okay, here we have to comma. So yeah. These are our five features. So based on this feature, let's try to model, like train model. Here I'll put the diagnosis. And now let's create a training testing split. X test, y train and I test. You can randomly select these features and see that which are performing best. Like I have done that already, and these five features I identified that if you only select the five feature, you'll get much better accuracy. So these features are very important with the help of you can generate some correlation matrix and you can also see various techniques we use for feature selection. So you can do that. And you can do some experiments also by selecting the optimal features for the best like this method is called feature selection. You can find the best features for your model. Now here I'll provide X, Y and test size, let's take it as again, 20%. The random state will be let's say 42. So our training and testing set is ready. Now let's model. Let's train model. So first, for model, I'll take it. Let's say K. Let's say K. First model. Now from SK learn dot neighbors, I'll import K neighbors classifier. Okay. Yeah. Now, firstly, I'll create a instance of this classifier. Now I'll fit our training data. Knot fit, sorry. So yeah, our model is fitted. Now let's do some prediction, I'll say. I'll name it or I can name it as KN Y pred Y prediction. Here I'll do Knot predict. So yeah, here you can see. Now you can calculate the accuracy also. For that, you need to import a library. It is called let me import it from con dot matrix. You have to import accuracy score. Now you can calculate your accuracy score by passing your predicted value and your original value. KN Y pread has your predated values and Y test you have that has. So here you can see, we are getting an accuracy of 92.1% in with our K nearest neighbor. Now, if you are suppose selecting, if you are not selecting only these features, you are selecting all those features. So let's do that also. Uh, suppose you are passing here your DF. Let's just wait a second, if you possibly visualize DF. So yeah, here you have this. Now, you are dropping, sorry, not. Let's create a new DF and you are dropping this diagnosis column. Okay, you have to drop like wait sec. Now, I'll just like I am what I'm doing is I'm creating a new dataset by just dropping this diagnosis column. I'll drop the zero and now if I see my new DF, here, it has dropped from DFO. Let me run this. Now it will see DF here. So yeah, it is correct. Okay, it is dropping from DF. Never mind. So I'll pass my DF now as a complete. I'll select all those features, not just five features. And now let's fit our model. It is fitted, now let's see our accuracy score. So yeah, with all those features, you are getting an accuracy of 95%. So this five features with the help of five features, you are getting an accuracy of 92% and with all those features, you are getting an accuracy of 95%. So we'll go with all those features only. Now let's fit. Let's test some of the other models also. I'll name it as logistic regression. Let's try to see how logistic region is performing here. I'll name it as logs. From Scale learn, you already know that you have seen in your course linear model. We have to import lodges Now, let's me create instance for this. I'll provide random state equals zero. Now let's fit filling data into that. X train comma y train. You model is fitted. Now, if you like now let's create your LR IRad here you can see logistic relation is already you can see not performing very well because it is with the default number of iterations, it is not converging. That means converging means your loss value will decrease. So that's the case. Let's do the prediction, then we will see ROY pred will give it as at predict, and I'll pass my X test value. Now let's calculate the accuracy score. In the accuracy school, I'll pass my it first, then my original TS value. Okay, so with logistic relation, you are getting a higher value of accuracy. With KNN you are getting 95.6 and with logistic, you are getting 96.49. So, yep, logistic relation is performing good when it compares with your nearest neighbor, K nearest neighbor. Let's try to run one more model Nav bias. Let's see its performance also. You for Nav bias, you have to import from Eklan Nav Bias. You have to import Gaussian Naive Gaussian. I'll create a instance for this first and then I'll fit the training data UI. Now if I do some prediction score and score pred. I'll pass gnb dot predict. I'll predict on X test. Now if I calculate the accuracy score, Wideredtest. So yeah. So I guessed this. The naive bias generally performs best as, in some of the cases, not every cases, but in some cases naive bias or you can say generally naive bias perform very well. And here also, you can see naive bias performed well and it is giving us an accuracy of 97%. So yeah, out of these three models KNN, logistic regnon and Nav Bias, the Nav buyers performed best. And so if you are working in any company and your company manager suppose gave you a dataset to work on, and he's telling you to do a classification task on it. So you can report there by this way or I have tried these three models, and out of that, this model is working perfectly. So this is what you have to do in machine learning. You like in some dataset, maybe the case is like Kin performs better or logistic regresi perform better. So this you cannot know directly. You have to model that, you have to fit it. You can see just by changing two, three lines of code, you can do that. So it is not any tough. So the logistic degron you saw like you saw in earlier course videos, but KN and nav bias you haven't seen, but here you can see it is so simple. So by this, you come to an end of this first project, and in the rest of the projects, you will see more. Also, let me show you one thing. Um you also every time you fit a model, you will get some different accuracy. You might get some different accuracy. Here, you can see if I fit it again, right now you are getting a same, but every time if I just shuffle my dataset, I'll just shuffle my X train or Y train and I'll reshuffle that. So we can get different accuracies. So for that, you also have one thing which is called K K cross validation. So let me show you that also because like real world scenario, you have to do that. So here you see cross varidation or I'll name it as k cross varidation. This do what exactly does is, it will be shuffling the dataset, and it will retrain the model and it will take the mean out of it. It will take the best it will take the average accuracy. So that is the more ideal accuracy we have to report. So from Con model Scalon model selection. We have to import our cross valve score. Now I'll create two variables first of all, accuracy. Accuracy every accuracy will be storing in this and the cross valve accuracy. Now, let's do this for Kanan first. Kan Kan model first. And I'll append this. I'll do this by cross val score. In that first parameter it will take is your model. Second, your dataset. And third, is your number of iteration. This is CV. Number of times you have to train your model. So I'll pass it as ten. We want to take K, you can say it as ten fold cross validation. K fold cross validation, that means, okay, here, fold dims. So every model, we are performing ten fold cross validation. So I'll just do it as K and here. Now, what I'll do is I'll apend accuracy for all. For every time I'll calculate the accuracy score. Or I can directly scores we have already, so we can directly do like this. What was that K and Y pred, I guess, yeah. One more variable I have CV underscore all in that I'll append the cross valid accuracies. And I'll mean all that. Now, I'll first print like this. I'll round of it on like two decimal places. I'll format it as test will be passing. And now let's print the clause validitd accuracy also. Because validation score, you'll say. In that, I'll also format it as point the 0.2 decimal places. Here you can see. Also, apart from only 0.2 decimal places, I'll just print its mean value also. But what ranging what range it is varying actually. And this also I'll format it as mean scores and Npttndard deviation. Okay. CVS underscore. So yeah, here you can see. With the N, I'll just import these warnings. Like, I'll import one module. I'll ignore this all warnings to be printed again and again. So yeah, here you can see with KN, you are getting an accuracy of 95.61%, but the cross validation score is 88.23 and your accuracy is ranging between basically 88.23 plus -7.6. But you can say it as your accuracy was ranging between this 81% to roughly 96%. So your average accuracy was each time you model training, your accuracy is varying. The final accuracy is K means all you can say it has ten fold cross validation score. You can name it as here. Ten fold cross validation score is your this 88.23. Let's similarly do it for logistic regression and your naive bias also. Here in place of this, I'll pass my LR model. And here also, I'll pass my R. The LR we are getting an K Frost fold accuracy of 89.46 and let me do it for our NA bias also. What was that GNB. Yeah. With Nav bias, you are getting cross variation score of 90.52%. So this is your basically K cross, you can see it as ten fold cross varidation score because you have shuffled your data set ten times and you have calibrated the accuracy for that. So, yeah, you have successfully done that. So when you are reporting your accuracy, you can report it like this for accuracy, I got it as 97.37%, and the ten fold cross variation score, I got it as 90.52 with the standard division of this 9.94%. So with this, you came to end of this video. I'll quickly brief you once again. You have imported the dataset, you have selected the features, you have splitted into training and testing. You have encoded this categorical variable, and then you have trained all your three different models, and you have done the K fold cross arron also. So yeah, this is your end of the first project. Hope you enjoyed that. And let me see you in the next project. 17. Project 2: Spam News Detection: Hello. Welcome back, guys. So this is your project to Spam news Detection and classification. In this we'll be using some of the NLP concepts, and I'll be showing you how to complete that project. And in your in general, you might have heard about the Spam news detection thing because in somewhere, we get a lot of news a message and everything, but some of them are like spam or fake news, and some of them are like actual news. So in machine learning or deep learning, anything we can detect or classify if we have the dataset for it, anything, we can also train our model to recognize or to differentiate between you and your family if we have the dataset, anything we can perform. So similarly, in this case, have our dataset true news like the actual news or the correct news and the fake news. We have dataset for both, and we can train a model in such a way that it can classify between all those two. Like if we will provide any news headlines or any news text, simply classified them as either true or fake. So let's see our dataset first. Let's have a look at our dataset first. Then you'll be understanding in much better. So this is our dataset one CSV file for fake news and one CSV file for true or you can say actual news, correct news. So in this fake data set, we open, yeah. So here you can see, we have a title where a news title, we can see. The actual news the text here you can see, Donald Trump just couldn't wish all Americans happy New Year. You can see that this news is fake. Like, Donald Trump, why would Donald Trump wish any American? Like, it is simply you can see here. Like this news are fake. This is subject column. This is the date where this news has been recorded. So this is the complete data set. I don't know how much column or how much data points is there. Let me count it. So yeah, 23,502. One is for headers. So 123502 data coins we are having. So you can assume it like that. And for the true news, for the correct news, here, you'll see the difference. Let it be open. Yeah. So here also the title text and subject and date is there. So in the sub text, you can see the head of conservative Republican faction in the US Congress who voted for this. This seems like a correct news. The actual news publishing company has published it. So this seems like a correct news. So what are, what is the power of natural language processing is we can provide any text, any textual data, and it will learn from those textual data. Like, firstly, we'll train our model in such a way that it will learn from these texts that which news is correct and which news is wrong. Like, in future, you can also build some model like extuel some LP model like this that if you will provide, suppose you are providing that suppose you have a different style of writing and a text, and your friend has a different style of writing text. So you can train a model in such a way that the model will recognize what text you have written and what text your friend has written. It can also recognize that. So this is the power of NLB and natural lange processing. So here we'll be using all those knowledge you have previously gained and some of the new knowledge you might not have aware of. So that knowledge, I'll also give you, I'll explain you what are those terms. So let's jump into directly jump into our code. You have understood, like how much let me count how many data points. So yeah, 21,417 data points are roughly in our true news dataset. So all these things, let's now jump into our code, and let's try to build our model. After the end of this project, you simply have to provide any of these texts or any text of your own also, and you can see that our model will correctly classify those image into either a fake news or a true news, like correct news. So let's jump into our code now, and I'll open Jupiter Notebook first. So in this directory, we have our two dataset, fake news Dot dataset, and true news Dot dataset. Let me open a Jupiter notebook. Now this I'll be naming at Project two. Now, first thing is importing libraries, as you already know. So for now, I'll just import two libraries, again, NumPi and Pandas, and if required, we'll be importing if require more library, obviously, we'll be requiring more libraries to work on. So we'll be importing that later on. Now, first of all, let's import our dataset. So I'll make two variables here. One is true news and read underscore CSV. And that we'll be passing through the CSV. Okay, sorry. This should have to be in the inverted course. Yeah. Now, also, I'll be providing here fake news variable. Let's read that CSD file also. Let's see what our true news is. Yeah. So here you can see, we have four columns, basically, title, text, subject, and date. Only this column we need to train our model, only this column. Now, you must be wondering where is the target column? Like how our model will know that this particular text is true news or this is butler text is a fake news. Like this particular text because the model will not know the CSV file name. So how your model is going to recognize. This is fake news and this is true news. So let's add a column. Like in Pandas, you can also add, with the help of pandas, you can also add label to any column to our CSE five. So let's add a column named as label. This is your column name which you want to add, and let's put the values in that column. Let's put it as zero. Be true news, we want to put it as zero, and let's also create for that. Let's add a column in fake news also, in fake news, we'll have the label as one. Now, if we see the true news, yeah, here you can see. All this true news has the target value is this is the Xtrain and this is your Y ran. So this is it and in the fake news also. So ultimately, your model have to give output as zero or one because this is a classification problem. So your model will be giving output as zero and one. Now only this two column, basically, this one particular text column and this label column we need. So let's create another variable. I'll name it as data set one, and let's fetch this two column only. We'll not be requiring the model doesn't have to know subject, what it is, date, what it is. And on the basis of this textual data, it is not necessary for our model to train. So we will not provide that. We'll simply pass we'll simply retrieve text and the label column from here. Data, through news that is also let me create a dataset two to just fetch this fake news also. Again, text and the label. Okay, sorry, this is not correct that one label. So yeah. Data set one, now, if you want to see this dataset one, you can see. Only the text and the label we are having. If you want to see the data set two also. We are having only text and label. Now let's combine all this join all the dataset. We want complete one dataset. So let's join it. With the help of Pandas. There is a function called CCT, which will basically concatenate two dataset. Under that, you'll be providing both the dataset variable, so it will concatenate. Now, the final dataset, as you can see, it contains all those four here you can see, we have 21,000, here, 23,000 roughly, and here 44,000. S combined all those dataset, zero and this oneth. So yes, now your dataset will contain. Also, with the help of this, you can also see dataset or shape, sorry. So yeah, 4,000 44,898 data points total we are having and two is your number of columns. Like one is your textual data, and another is your label. Now let's see if any point any data points is null or not because in machine learning in data preprocessing step, you have you have I have told you that first thing you have to check is whether your dataset is having any null values. And the second thing is, if any categorical variable, then you have to convert those into numeric because the neural network or the machine learning model will not recognize this text. It is not going to recognize it. Now, firstly, let's check for missing values. So for Pandas, you can like this data frame, the label only sorry. This function is null function you have to see that dot S. So yeah. In the text and the label, no values are null, no values are null. So here you can write this. Check for null values. So yeah, no values are nu. So we are good to go. There are no empty columns, sorry, empty rows in our dataset. So we can Sure. Now, if you want to see how many columns here, you already know, but still if you want to count this count in this dataset that how many columns you are having as zero and how many how many rows, how many data points you are having a good correct news and how many rows you are having fake news. So for that, you have a function like in the label you just want to count, you have a function known as value comes. So here you can, sorry. Okay, I just count. So yeah. For one, that is your correct data. In one, you are having basically just ta sec. So yeah. In one, you are having 23,000 data points and zero, you are having 21,000 data points. So this is the function for check that also, you can check that. Now, here you can see that starting 23,000 is only zero value and end one is one. Now we have to shuffle that. Otherwise, your model will be more biased. So we have to shuffle this. Now dataset I just want to shuffle that at dataset dot sample. With this function, you can I will basically resample your data set. This is a function for resampling. Now, if we look at dataset, so here you can see zero, one, zero, one, one, zero, this is all the values are resample. So it is shuffled. So now we are good to go with our dataset. And now let's jump into the NLP part because in NLP, you have two things first. Why we have to use the NLP concepts here. Simply we can train the model like we have our dataset, we have our label, so we can simply train our model based on that, but we have to firstly, encode this data also and clean this data also. Neither we have performed data cleaning here nor we have encoded it because the machine learning model will not understand this textual data. It will only understand this zeros ones and, you know, numeric values. So for that, we have to use NLP first. Now, uh, Yeah. So I'll have to here. Firstly, let me create NLP. Now, firstly, import NLTK. NLTK is a library. For machine learning, you have your psychic Sklearn for deep learning, you have tensor flow, Pitch, or everything. For NLP, you have NLTK. Now I'll also import some more functions. This is RE Rejx. Rejx is basically the fuzzy logic. It works on fuzzy logic, and it is a data cleaning library. Like, it is used to clean and perform some operations in data. L, you will understand more when we do that with the help of this don't worry. From Lp dot corpus, I'll put stopwords. Now what is stopwords, I'll tell you don't worry about that. From tk STEM, I'll have to import emits. Word. Word. Wordnet miser. So yeah, let me put all these libraries. Now, I'll create one instance for this Wordnet emetizer because after we have to import, we have to emtize our words. Now what is emtizing? What is chop words? Don't worry about it. I'll tell you. I have created an instance for that. Stop words also, I'll create an instance. For that, you have to considere instances like this, stop words and what words we are providing English words we are providing. Now altk dot. As I have to use this word net. Okay, sorry. Yeah, it has downloaded. Okay, it already. I have downloaded it before. So now I'll create a function for cleaning a row, complete row aisle cleaning, like aisle clean. So clean row function, I'll be setting I'll be passing row one by one. Now, first thing. First thing that here you can see, some words are capital, some words are small, some words are like that. So firstly, first step, we will convert all those all the textual data to a lowercase. Like, it will not matter. You can it will not matter that either your text is lower case or upper case, both the way you can understand. So let's convert it to the lower case for the simplicity of the neural network to the model, machine learning model. So next thing, now, here you can see some words are special case also. Like some words might be there, which are special case. Here, I'm not finding. You might have you can look at dataset also. There must be some words, which is not like you can say it is having any special character at the rate or anything. So we have to remove all that. This will basically, reduce the complexity for our model. So with the help of rejex, we can do that. What I'll do is like this is basically you might be facing difficulty in understanding. Like, I have already worked with Rj code, so I can understand, but you might be facing any difficulty. So a rejex code, you can search directly on Google. It is available, so no worries about that. This is Rejex code, which is basically converting, which is basically removing any sort of numbers and, you know, special character from your textual data. Like, from the text, it is removing your numbers and special character. So this is your regex code, dot s. Yeah. Now, we have to split the data and we have to create a token. By lemmatizing, we have to provide token. Don't worry, you will get what I'm saying. Now let's lamtiz our word. Firstly, let's write a code for matizing then I'll explain you what is llamatizing. Is in this, I'll pass word and I'll run a loop for each word, I'll be mitizing word by word. So yeah. And these tokens I have also let me join all these tokens because this is boy each word. So now, let's understand what is lematizing. Basically, in your words, there are many stop words like A A and there is what. These are some of the stop words. Now you have to like you have to lematize each word, and you have to remove all those stop words because that is not going to contribute in training of our model. So we have to remove all those words, all those remitative words. Suppose in your basically, I'll explain to you this example. Suppose my name is suppose C and my field is AI. This is the text. Now, what this particular line of code will do is it will convert this text like this. My name is CO and my note field. And my field. Now. This has basically removed this M the repetitive MI and what else is. So it has removed this to what? Now, some of the like I guess it will not yay. So now this M is R and these are all stop words. So basically, firstly, what I'm doing is this complete row I'm splitting it to a token, like 11 word, basically not token, like 11 word, you can say, M is one token, name is one token, is one token is one token. So it is converting whole text into the token. Now, what it is doing, it is lemtizing each word. Now it is keeping account to my appeared one time in text. So next time when any stop word will appear, it will not include that in text. Like, this is what is necessary because you see while training a model just like neural network is not or you can say machine learning is not going to understand what this text is, what is text? What is this text? It will not understand. It will only work on some particular forms. So these words like these words, we have to only feed into our model. And furthermore, we'll be not filling this only this we are not feeding this textual data because you know that machine learning model cannot accept any non numeric value. So we'll be converting this into vector. Now, how it will be converting? Because we'll be converting like this. Zero will assign one vector, one will assign one vector, two, three, four, five, six. Now, next time, whenever any word any row is come where you have supposed core of name, then it will simply assign it it will assign as three because it has already came into the text. Now, this vector will go into a machine learning model. This vector will be fielded. So that's why lemtizing and stemming all these are very important thing which we do in NLB. Now we'll simply return this cleaned news variable because we have already cleaned. So our function is basically ready. Now let's convert this dataset and I'll show you. So this text you are having, now let's clean that with the help of the cleaning functions, we are just created now. Let's create this dataset. Text, and now we'll apply a Lambda function. Lambda function is basically like Lambda is basically if we want to provide a particular function to any piece of we want to perform a particular function with this the data we are getting. So I'll be passing clean data. What was that name? Cleanow underscored row, and I'll be passing each row one by one. Sorry, each row X here, because X is what you are getting by each every time. Now let me run this function and it is cleaning all those data. So let it be done. Let's wait for it. And after that, I'll show you this data set text again. You will see much cleaner version here. I will remove all those special characters. It will remove all those stopwords. It will convert all those upper case into the lower case. Everything every data cleaning part will be performed after this. It is running. Basically, it is taking time because it has to run on all 44,000 data point, not 44,000, 45,000, actually. Okay. After we'll get this dataset, the clean dataset. Now the next step is we'll be converting the vectors I have shown you, the numeric values. We'll be converting all those texts into the vectors. Like, these complete texts will be converted into a vector, and that vector will be fitting into the machine learning model. So, as you can see, as you have seen, all those clearing part, the all complete data science work, firstly, seeing that there is, if there is any missing values or not, we have already checked that the data cleaning part, then we have already done that like it is doing right now and next step is next step was encoding the categorical variable, but now here, it is non numeric value, so we are encoding in the next step, we'll be encoding data also. For that, we'll be using TF DA vectorier. Now, yeah, our dataset cleaning has been done. Now let's see our dataset. So here, here you can see all these special characters are removed this hyphen has no use, this bracket is no use. So all these are removed. A is also, as I've told you, A in S these are all stopwords, so it has removed all and this complete clean dataset we had. Now we have now let's convert all these textual data into a vector. So from again, Eclon dot feature extraction text. From feat test, we have to import TF IDF vectorizer. It is important. Now let's create an instance for this first TDF vectorizer. Max features will be including 50,000 max feature. And as lower case, we already have basically this library will also convert all the text into lower case, but since we have already done that, so I'll be putting that as zero because no need to do repetitive task. It will also save us some of the time. So this I have done range I've provided. Now let's perform this. Okay. Uh Okay, that's equal. Now the vectorizer instance has been created. Also, we will also one thing I forgot here, yeah, we have to split our dataset also in the training and testing set. So what I will do apart from 44,000, what we'll be doing is let's train our dataset on this 35,000 points, and let's test it on the rest of them. So yes, let's create that X and Y variable also. And basically zero is per column, the first column. Put Y seem like all 35,000 rows we want, and first column now we want because Y is your label. So if you see X, so it is this and Y if you see it is the label. Now, let us split those data set into the X and Y. From SK learn. What was that the moran test plt function. Import train test. Split. Okay, this is a skill learnt model selection. Now, let's create our train data, the test data, the train label, the test label. These are all your fold values. Let us apply train test function. I'll pass excess first and then Y. Then test size here will be taking at 20%. Let's take 20%. Let's train our model on 80% of the data and let's test it on 20%. Random state also we have to provide, so I'll provide at zero. Now, if you see the train data, y here you have your all your train data. Now let's vectorize this. Vector ier we have already created. So yeah, it is vectorizing. Basically, this data, it is like TF ID vectorizer is basically converting all the text into a set of numbers. And how many total numbers? Like what till what range the number will be there. So this is 50,000. I'm like, it is just my guess that this total dataset will have 50,000 unique words. I'm just guessing that you can take it as any number. If you will provide some shorter number, then obviously model training will be faster and this conversion will be faster, but I'm providing it as 50,000 because I want a better accuracy. So yeah, it is trained now. Let's also this is currently a data frame. Like if you see this type, it is a data frame. I think it's type or what? Type actually not working. Okay, sorry. This is right. Yeah. So this is sparse matrix actually we have. So in neural network or in machine learning, you have to feed our dataset to inner array form. So I'll just convert this to array. We have a function called a array. And I'll save it in this data variable only. Now if you see the type, it will show it as numpi array only. Yeah, and Numpi array. Now, let me now the training data is there, the testing data is there. Okay. Now also we have to convert this in testing data also in vector form. So I'll name it as vectorized testing data. I'll provide test data. So I'll let me fit in and also we have to convert that testing data also in array. Yeah, it is also done. Now, you can check the shape also, like the vectorize. Uh VctorizTrain, data dot, vectorize test data dot, yeah. This is the 28,000 data points and 50,000 features we have. Basically, now, if you see your vectorize train data, now what it has done that it has converted all those 28,010 28,000 textual rows into the column. It has done like this. Suppose I am C, then it have done like this. I is a separate column. M is a separate column and CRA with a separate column. And it is done like this basically, let me show you here here. For I, this is done like this, zero, one, one, sorry, zero, one, zero. Sorry, sorry, sorry sorry, zero, zero. Now for M, it has done this zero, one, zero. For core of, it has done like this. You can guess obviously, zero, zero, one. Now this is what the TF DA vectorizer has done. So automatically, you encoded all those data. Here, we cannot use that one hot encoder because there are a lot of rules. And with the help of LP tools, we can perform it achieve it very easily. So now it is done. Also we have to create a training data, final training data in which because the column directly we cannot pass, we have to convert this into data frame. Vectorized training data we had and columns. Basically, what you doing that we have to also provide the column name. But in this, you cannot see any column name. So we are providing the column names also. Zer dot GET you will understand when I'll run this code first. Don't worry. And for the training testing data also, we have to do same data frame, I have to provide vectorize testing data columns equals to vectorizer dot Ket feature name. Okay, this F should be capital. Get feature names it is. Now, if we see the train data. So yeah, here you can see, A is any unique word, APL was some unique word, Zuckerberg was some unique word. These are all unique words and you have a value for all this. You have encoded value for all this. Now you can basically you are ready with your complete data. Now you can train your model. Now in the course you have seen we are using logistic regression and SVM. But here, let us use some other novel model let us use naive bias because naive bias I have told you a little bit like it works on this base theorem which we study in high school mathematics. Let's train our model on this naive bias and let's see what's accuracy of that. Right model. Okay. Now let us import first. Sorry, let us import first the model from Econ underscore naive bias and be importing multinomial Naive bias. Yeah, it is imported. Now again, we'll perform the simple task. We'll create a Instant first, then I'll simply fit all those data into it. I'll be fitting training data and the train label. Training data is not defined, okay, I have put her train data. So it is fitting. Now after fitting of your model, let's predict also it will take some time to train the model because you see, we have a lot of data points like 28,000 rows and 50,000 into in the theoretical video, you have seen that we have only 100, 200 rows and two, three columns. So this is your actual problem. This type of problem you get you'll be getting in your industry, you'll be getting a lot like 23 rows. You'll get 50,001 lag, 2 billion, 3 billion. This type of values you'll get. So here you can see our model is trained, let us predict this predict on the testing data. Test data I have testing data. Now it is predicting Now, the test label, the original label we'll be having is test label and this Y parade also located. So yeah, Y parade is also there. So let's create let's find the accuracy for it. Let us see what's the accuracy. For accuracy, we have to import scant matrix. We can import accuracy score. Yeah, let's input accuracy for score only, and let's see the accuracy score for that. Here in this parameter, I'll first pass label the original value and the predicted value, basically. Okay, so accuracy here we cut is 70% roughly. This is actually not a very good accuracy, I'll say, but yeah, this is what we are getting. A, so I'm just re verifying everything is correct or not because we are getting 70% s. It is good. Ally we have cleaned the data. Is good. We have splitted, we have matize all those words. We have joined and we have written. A dialog. Yeah, everything looks fine. It is confusing here actually, the labeled trial label. I'll name it as some other Okay. Here I've also vectorized the testing data. Yeah, yeah, you have to do True array, it's correct only. I'm just cross verifying everything that everything is correct or not. This is a little bit confusing, let's not let's give it as training data only. Train data we have untrained label. Training data we have training label we have okay. The accuracy is a little bit low, but never mind. I'm just refitting. Let's see if the accuracy changes. C. Let me see max. Let me run again from here. X and Y we have was 35,000. All right. Which X. Yeah, it was having right. Let me run I'm just re running those cells. Let's see if accuracy changes. Just wait for 1 minute. I like it is re vectorizing all those theta, and it is retraining, it will retrain the model. Now it is fitting the data cleaning part is done and now it is fitting the model. It has fitted the model. Now it is priting on the testing data. So, yeah, we are getting 69.9% accuracy. Let's see the accuracy on training data also, what we are getting in training. Train label, and let's predict also for that. We have to predict also. However, 70% accuracy is good LLP, you can it is good accuracy only. Why bread is equal to I'll name it as not hibad. I'll name it as pad of train set. Here I have to provide what the training data. And here I have to provide redstra. Sorry. I ask to put yes. Let's also see the training accuracy. It is just priding on all those training data. Yeah. So in training data, we are getting our accuracy at 95%. In testing, we are getting a little less accuracy. I don't know why it is happening, but yeah, sometimes you get like model is a little bit overfitted, I guess. Yeah, I'm just actually re verifying size that we haven't. So yeah, the accuracy is actually 95% 86 on training, and on testing, it was 70%. Now, let's predict on some data. Like, how will we predating on any data, any future? You can say the text you got. So let's spread on that. Firstly, I'll store it in a variable name and text. And suppose let's take a data point only from Let's get Yeah, let's predict on any data this data, I suppose, text it is. This text we want to predict. Now, just wait. Yeah. So this text we want to pred, let's firstly clean this data. The first step we have to clean this data. Sorry. Okay, clean what it was clean data, right? Okay, it is clean sorry. Yeah, now the data is clean. You can see here. Yeah, it is absolutely clean. Now, let's predict on this data, which we have to provide calf dot predict. And also, remember, we have to first vectorize this vectorizer dot transform. News and also to RI. CIT has predicted zero. Now, what was zero actually? I forgot. Zero is for true news. So yeah, you can see it is printing correctly. It is printing absolutely correct. You can also write a code like this if pred equal equals zero, then print sorry. News is correct or else you can write it as News is fake. Yeah, your news is correct, absolutely. You can also do this like this. Input STR sorry. Input, you can see it as Pinter News. Now here you have to convert this in string first, then you apply when you will run this, you have to enter now, let's enter a fake news this time and let's see our model is performing good or not. A news I'll take this new suppose I take. News is fake. It is also printing this news Why is printing that news. I don't know. Let's enter. And Okay, the clean rope, basically, it is also printing. Now, if we are passing this news, we are getting value and news is fake. And here also, you can see the news was fake. So yeah, your model is working perfectly fine. Now, let me recap this all once so that you will not get confused. So firstly, we have imported our dataset, then we have assigned a label manually to it because we have our dataset named only fake and true, but we do not have a label column, so we have assigned it manually. We have added a column manual now we only require two columns here for our features. So this is basically called a feature selection. You can you might like you might be hearing this word again and again in machine learning. Apart from this out of these 24 features, you have selected this one feature. This is feature selection, the selection of appropriate features to train your model. So this is feature selection you have done. Now you have joined all those two directories so that your complete dataset should be one. Now you have what you have done. Now you have cleaned the data, you have converted into lower column. You have removed all those special characters. You have splitted zero, one, one word you have taken and you have matized each word and you have returned the data cleaning you have done. Now you have encoded the dataset because machine learning model cannot simply accept the non numeric value, so you have encoded the dataset. Now you have spritted your data set into training and testing set with providing 20% testing data and 80% training data. Now you have basically assigned a column. You have joined a column also to it, and you have trained your NPs algorithm and the 95.8% accuracy you've got, and then you have predicted using your custom text. Any own, you can also test it uh, with providing your own news. Like any headlines you just copy from the net, you do not necessarily need to copy from here only. So you have to you can copy also from the Google and you can provide here and test that this model is detecting it or not. So it'll work for that also. Now this project is completed. Now what you can do to practice this is here, I have implemented Nav bias. You can also implement other models. Like logistic regression also you know how to implement here, you have to do some changes here. Like only these two lines, you have to change rest, everything will be same. So you can also for assignment part, you can also do like this that you can report me the accuracy of SVM, logistic regression, and all those classification models we have. So you can report all those acts. You can tell me which is the best model for this particular dataset. So yeah, and, like, this project is completed. Now let's see you in next project. 18. Project 3: Handwritten Digit Recognition: Hello, and welcome back, guys. So welcome to the last project. We have this core series. And in this project, we are building we are going to build a deep learning model, a CN model for handwritten digit recognition. Now you might have seen in some places like the digit we write in our handwriting. So we'll train our model in such a way that it will be able to recognize those handwritten digits, like those digits, and it will convert into a numeric value. Like 029 digit will be writing in paper, and it will be converting it to the numeric value. So we'll be using a CNN architecture for that. And particularly in CNN like CNN, we have a lot of CNN architecture avib in, like, Internet and like, there are many previous like pre trained model also which are previously trained on a different dataset, and we can use this concept of transfer learning to leverage those previously trained knowledge. And in this, why we are using Land five because Land five is the old days architecture, and it is proven to be most successful in this MNIST digital recognition. And with the other architecture, also, we can achieve similar results and even better results. But Land five is very lightweight, and it is like very it will train faster and it will perform really fast on this MNS digit. So we are going to use that. And for this, the dataset is I'm repeatedly telling MNIST MNIST words. I'm repeatedly saying that. So what is this MNIST? So MNIST is basically a digit database which contains a lot of images and for this handwritten digit recognition problem. So let me show you this MNIST digit database first. So here you can see this is basically the digit database where you are having this training set and training set labels, then testing set and testing set labels. You already have that. And this has been released by Yan Li kun, and here you can see, there are already many works previously done in terms of, like, K and KN is also implemented. SVM is also implemented. Neural networks are also implemented. So all these works are previously done. This error rate is basically nothing than one minus accuracy. 100 minus accuracy. Like here, suppose the error rate is 3.3, that means they have achieved an accuracy of 97 point sorry, 96.7 because when 96.7 plus this 3.3 is equal to 100. So error rate is nothing but 100 minus error rate is nothing but 100 minus accuracy. So this is your error rate, and these are all your trained and the handwritten digit recognition, if you see, So yeah, this is your handwritten digit, and you will train your machine in such a way, you train your neural network in such a way that if you pass this particular image five, then it will automatically convert and it will recognize that Oh this image you have passed is a five like C here. If you write a digit by yourself and you will pass you will click a photo of that and you'll pass through this neural network, it will automatically recognize that this is a five image. So that we are going to build here. And as you already know, neural networks in deep learning, we have a three type of neural networks, artificial neural network, convolutional neural networks, and recurrent neural networks. Artificial neural networks we can use for general purposes. CNN is more specific than more use more widely used for the image problems, the video problems, image recognition, image classification, detection, object detection, everything. So it is more specific to image and the recurrent neural network is more specific to sound and time series problems. So in this video, we are going to use CNN because since it is a image recognition, or you can say image image classification problem where you were worrying, what are those classes. So those classes are basically the zeros, this ones, these two, three, four, and there are ten classes, basically zero to nine, like one, two, three, four, five, three, seven, ten. So yeah, let's jump into the code and let me start my Jupiter notebook first. We do not need to download any dataset here because I'll show you this MNIST digit database is very popular dataset, and it is in itself you can say the tensa flow Keras library. Like SKLearn library also consists of, also contains many dataset. So yeah, I'll name it as MNIST notebook. And first step first, we have to import some of the libraries. Now I'll import Numbi and Pandas first. Now I'll import one Lib D named from Keras Keras from Keras, I'll import data sets. So the datasets, it contains basically a lot of variety of dataset, and it also contains some of the dataset like Ci far ten dataset, Sipa hundred data set, MNIC datasets, all this thing it contains. So here you can see all those datasets are already downloaded. Now, I'll be loading my MNIST dataset. Now how I load, I'll create two tuples Xtrain, Ytrain comma X test, YTest. Datasets dot mist dot load data. This is inbuilt function which is able to which you'll be using for the data for loading the MNIST dataset. Now here you can see, okay, setting the data sets that no attribute MNIST data sets that shouldn't be okay from LC tensorflow dot Keras, Import data sets, and here now we'll be importing. Yeah, it is importing. So tran, if we'll see, yeah. So here is your training data, and I'll show you the labels here. So yeah, here are your labels. First data is of five character, like fifth character, second data is for your zero character, four data is third data is for your fourth character, similarly, last data is for your eighth character. Now, when doing a image recognition problem, you have to initially, let me show you, yeah. So initially, if you are getting this image, if you are getting this image, this fifth image, firstly, you have to convert this image into a three cross three. Firstly, you have to convert this cross three image into a matrix. You can assume it just we did in machine learning, theoretical videos, encoding the data, you can just assume it like that. You can assume it like you are encoding this data. This image, the neural network cannot accept, as I'm telling you from starting the machine learning model or a neural network, it cannot accept any non numeric value. So this image, you have to represent in a three cross three matrix, and that matrix consists of a numerical value, as we have seen in train. So that matrix, basically the neural network will accept and how the neural network works like matrix that you will be understanding for the videos of and this basically each image is converted this image, you can consist of, you can assume it as a three cross three matrix. And with the help of this data set, actually, this MNIST data set, it is already pre converted into this you can say vectors, like three cross three matrix. So as you can see here, yeah. So here you can see this is already three cross three matrix. Now, if some image in future if you are working with any problem treatment and that image directly you are inputting it is not converted into a dataset. Not converted into a three cro three matrix. Then you have a inbuilt function in OpenCV and image libraries or many libraries. The inbuilt function you have for converting those image into 33 matrix. So with the help of that, you can convert that. Now, here it is already converted, so we'll be proceeding further. Now if you want to see the length of the dataset. So here you can see, yeah, so 60,000 images of 28 cross 28. Like 28 is basically 28 cross 28 size. Each image you see, you can hover over any image, and it consists of a particular row width into height. Each image has a width and a height. So 28 is your width and 28 is your height for all those MNIC images. So there are total 60,000 images in our training set. And if I see for testing set, if we see so 10,000 images we use for our testing purpose. So on 60,000 image, we'll be training our data, and 10,000 image, we'll be testing our data. Now let's proceed further, and we have to reshape that because the neural network cannot accept this 28 cross 28 cross this also, it will be unlike the convolutional neural network except the three basically, it accepts the RGB values also. Now the convolutional accept this type of value. You can see 28 cross, 28 cross, three value. And now this three is what? This three is basically RGB. Now, every image consists of three channels, the red, green, and blue channels. Every image you can describe, red, green, and blue channels. So this image consists of this neural network except the image in 28 cross 28 cross three. Or you can see the width, cross height, cross three, the three for RGB channel. So let me define the width and height of our image. The image row and image columns are your 28 cross or you can say the width and height of your image is 28 cross 28. Now your input shape will be your input shape will be image row image columns one. This will be okay. Image row is not okay, sorry. It is width and it is your height. So input shape is like that. You can see here. Input shape is your 28 cross 28 cross one. Now, the training data is in this format and you have to give neural network this type of input. So you have to basically reshape your training data. Now, how you will reshape your training data is that you have to sorry, train reshape and train dot shape, u comma, uh your height of the image and your width one. Now, same for the testing data also. The test V shape X test dot shape zero height width. Comma one. Now, this will be sorry width. So this basically reshapes your training data. Now, if you want to see that, sorry. Now if you want to visualize do train dot shape, and here you can see the shape is now the training data is no reshaped. Like, first initially toward this and now it is reshaped. The third column is also there. Now, you must be one ring. Like, as I've told you, every image consists of three RGB channels, then why it is one here. So also for gray scale images. Now what is grayscale images? The black and white images, those Black and white images, we do not have our red, green, and blue part. We only have one channel there. So that's why we are putting it as one here. Now, if you to uh, the train you see let's see the Y train labels shape also. So yeah, this is, again, a supervised learning problem. So we have our input data also and we have our output also like we have our labels also. So 60,000 for 60,000 images, we have our 60,000 labels. Now let us convert also, this training and testing set we have created now in neural networks, we also have a validation set. Now, let's know what is a validation. Basically, on the training data, your neural network will train and after each iteration, after each epoch, your neural network will validate the model. It is going fine or not. It will validate. So for validation also we need a dataset, and the testing data is for final testing or final evaluation. Like after each iteration, also, you are evaluating and after each iteration, after complete training, you also have to evaluate. Now, if you see here extrane we'll be using the psychic on library only, I'll import that also. What was that? From Sklearn dot model selection. We have a train test and split. Okay, sorry. So here, Xtrain l y train, Y. So I'll be using this test and split function train Y train. Oh test size. Now, test size, we'll be giving let's give only 10% data, 60,000 just for training out of that 6,000 images we are taking for each iteration validation, validation after each iteration. And the 10,000 we'll be using for our final testing data. Now let's do that. Now, again, if I show you the length of XtraN, it is 54,000 and if I show you the length of XL, it is 6,000. Now, now the training and testing data is ready. Now one more thing. We have to basically normalize the data. Like, why? Because again, I've told you one thing. In the machine learning, we are doing feature scaling. Here also, we have to scale the features. Here, we have to normalize those data because you can see, some images might be having a value of zero. So images might be having a value of 255 because a black and white image ranges 0-255. Zero is for black, 255 for white. So zero and 255, those are different these are in very different ranges. So the model will eventually focus more on 255 value, but this shouldn't be the case. The model should focus equally on every sort of pixel. So you have to normalize all those data now to normalize. You have to like this X minus X train Man, and I'll be dividing all those by the standard deviation. With the help of this, you can normalize your data. Now, same we'll be doing for XL and val and XX also, same thing, basically. Here, it's not underscores, XL minus X val dot divided by l dot standard deviation of it. Same for testing data also. Standard division. So, all the data should now be normalized. Now, if you want to see this train, yeah, it is all the features are scaled. All these features you can see are scaled. Now, another thing is, since this is a categorical variable, we have to convert this into a categorical variable because we want to format those data. Now, how many labels are there? We have total N ten labels here. So I will define a variable named as number of labels here. Which is ten, now I have to format my data according to that. I have to encode my variable also because C, in machine learning, like what you are doing is firstly you are feature scaling like you were scaling your splitting your training and testing data and you are encoding category encoding both your training and testing data. Now the training data we have already encoded, it is already into numeric value. But the testing the labels, basically training data, the Y train is also only numerical value. But Y, the labels that we have to also encode, that encoding is left. So that we are converting with the help of a function named in KRAS is Keras dot Utils dot two categorical. With the help of this function, we can encode our variable. So this is your Y train. You can see here. Y train currently has a shape like this. But after this, the keras is not defined. Uh from tens of Import keras. Nowadays, fine. Now if you see your label, C, it is encoded. The first two, basically you can visualize zero, one, two, three, like this. And for second number, this column is one. So it is encoded. Now let's do the same thing for the validation and testing data also. The validation and testing data I just copy paste. It is also encoded. Now we have to build our model. This is the time we want to build our model. Now, firstly, wait. I'll write it down model. Firstly, we have to import some of the libraries, then we can start building our model. So firstly from tensor flow dot Keras dot models, I will import sequential Sorry. Then from tensa flow dot caras, I'll import some of the layers also. I'll be importing dense layer, dropout layer, flatten, input layer, sorry, it is not like this input. Input layer. I'll be inputting layer, the convolutional layer. This is most important. The max pooling layer. The average. Okay, let's import this much right now. Cannot import Okay, flat and I have misspelled it. Yeah. Now, all those layers are important. Now let's start building our model. Now, the traditional Linet architecture, you can Google it also Linet five architecture. And here, if you will see these consists of these five layers. The first layer is input, then the convolutional layer, then the max pooling, then the convolutional, then again, max pooling, then convolutional, then fully gneted layer. So this is your architecture. I know the architecture, but you might not know any architecture, so you can Google it also. So let's start building the architecture because I memorize those, I have memorized those architecture. So I have in memory, but one might not need to know all these architecture on like they do not have to remember all those architecture, so you can Google it. So first layer, I'm putting it as conn layer of six neurons, let's say, and the kernel size, I'll be taking as first, then I'll be putting strides value of again, one comma one, then an activation function tanag and your input shape. Input shape. What was your input shape? It was your 228281. One more bracket I'll be having here. All right. Sorry, you're right. Now I'll be adding average pooling layer. Average pulling I haven't imported. Average pulling. Now I'll add this layer here. And in that, I'll define one pool size. Pool size of let's give us two comma two, and strides of one comma one. Model dot ad. Again, I'll add a com layer. Let me copy from here only. I'll add this convolutional layer. Of this time, let's give them 16 neuron. The kernel size, I'll be giving a same activation, and this time, I do not need to give input shame because input I'm defining only one in the top. W here you can see the initial layer was input layer, not the later ones. So here I'm only defining this. Now again, I'll be putting an average pulling layer. This is the architecture, actually, I'm copying for I'm basically copying this architecture of Let five. If I'll be using another architecture, I can use any. But I'm training our Lant five model here. I'm copying the architecture of that, so yeah. Now, average Puri layer, I've defined it is two cross two and strides, let's give two cross two this time. Yeah. Now, after this, again, I'll be putting a convolutional layer, then I'll put because this is a four layer architecture. So yeah. Five layers, sorry, 120 this time, I will put and everything I'll say. Now, after this, basically this block is your feature extraction block. You can watch deep learning videos to get know more about this feature extraction. This is your feature extractor. And after that, I'll be flattening all those layer. Like this will be converting your complete layer into a single dimension vector. Like, these are all your features, I can say. Now after that, I'll add a fully connected layer of dense fully connected dense layer. Of 84 neurons, let's say, activation function as tach. Now, I'll add denser final dense layer for number of classes. I have already defined a parameter number of classes, which is actually ten, so yeah. Activation function as softmax. If you have a binary class, then you can use Sigmoid function. If you are classifying between two categories, for example, if you are only classifying between two digits, either it will be zero or it will be one, then you can use this architecture. Then you can use Sigmoid, but here we have more than two classes, so we are using softmax function because it works for more than two classes. Okay, here I am I'm spelling mistakes. Number of classes, I was as far as I remember, I have defined number of classes. Okay, number of labels I've So, our model is built. Now, let's compile our model. You can also see your model summary by this. Your first layer is this, your input layer, then your average pooling, then your convolutional again, then your average pulling, then your convolutional, then you have flattened those layer and 300 vector size you have got in the end and then your dense layer and at last, your dense layer of ten neuron for the classification. Now you'll compile our model. And I'll put the loss function as Kara losses, dot categorical crossentropy. And I'll use the optimizer here as Adam. And the matrix, the matrix which we'll be evaluating is the accuracy matrix. Now, yes, the model is compiled. Now we have to train our model. The history variable also I'll be saving now I want to train my model. For training, again, the fit method, here you have to provide training data, the training labels, the bad size. I'll explain you once, let's start the training first, then I'll explain you. Bad size we'll be taking as 32, the epoch. I'll be training it for 20 epoch let's say. The bo I do not need to I'll define bos equal one and your validation data. Validation data. It'll be equal to L. So, we can start the training now. Yeah, our model is now like it is being ready to train. It will take some time. It will take roughly five, 10 minutes or even more than that. Till then, I'll explain to you what are all this. So optimizer adam optimizer, there are so yeah, your training here you can see, your training has started. Here you can note the accuracy, and here you can note the loss value. The loss value should always decrease if your model, if you have built your model correctly. See the first epoch is also like first epoch has not completed yet and you are achieving an accuracy of 91 above. Like it will reach still, I guess 93 94. So yeah. Now, the model dot compile one loss function you have to use in neural network, the complete game is basically to minimize your loss value. And for that, we have to use a loss function here, which will basically take two values as input, the rated value and the actual value, and it will determine the loss based on that. So here we are using categorical cross entropy. There are also loss function known as binary cross entropy or other, but since this is our multi class classification, so we are using binary cross entropy and yeah. So that's why we are using binary crossentropy and like, sorry, we are using categorical crossentropy because we are multi class. Now optimizer there are multiple optimizer, the Adam, the stochastic giant descent, the Adamax, the Add, many more RMS many more optimizers we have. So basically, Optimizer is anything like it fasten up your training process. So for that, that's why we are using Adam because Adam is the fastest this atom is your fastest optimizer. Now, matrix to evaluate, we are using accuracy matrix because here we have to measure the accuracy. So yes, let's reduce it to five Epoch only because it will take a lot of time. Let me run. You can run on your personal PC for more EPO so I'm reducing it to five EPA holly. Now, the model dot Fit. Here, you have to in machine learning, you simply have to provide your training data, and that's it. So parameters also. But here, you have to provide the training data, the best size. Now, basically in your neural network, you have seen you have 60,000 images or like 54,000 images in your training set. Now all those images you cannot provide at once. Otherwise, PC, PC GPU will be simply basically whenever the training is starting, whenever you are starting the training procedure, then the complete images are copied into a RAM. If your model is using GPU, then that will be copied into your GPU RAM. So for that we cannot provide the complete dataset at once because GPU RAM is limited. So we provide it in batches, we are providing in 32 batches. Like, suppose complete dataset is of 32,000, then in one batch you are providing 32. So there will be basically 1,000 batches, 100 batches. So that is your batch size, basically. In each batch each batch is you are training is performing. Now, the number of epochs, basically, after one epoch, the model will run completely on this, I can say, your model will be running in this one epoch your model is adjusting their weights in this first. Yeah. But basically on your complete data, suppose you have 100 data points in your dataset, then on your hundred data points, you can model is learning from those hundred data points once, and then after 100 data points, again, your model is like shuffle the model will shuffle those data points. And again, it will train because neural network takes a longer time to train. Now your validation and you have to pass the validation. Verbos is simply if you put bos zero here, then you will basically see no details here, but we want to visualize also while training, we want to see the details also, so we are using that. Now, the validation data. The validation data is basically after each epoch, you have to validate your model two. So for that, we are using the validation data. Now it's your almost training procedure is completed. After your training procedure is completed, the model is fitted. We'll be also evaluating our mod a Okay. Sorry for the disruption guys, my PC actually my battery gone away. So yeah, I was explaining that after each iteration, we have to validate our model too. So for that, we are providing validation data. Now, after our model is done, I'll simply test our model in the final testing set we were having. So in the final testing set, we'll be passing X test and the Y test. Here and both again, I'll provide it as one. I'll do that and the score, I'll be printing. It is evaluating on this thing. Now this core LC. So yeah. Basically, though your training accuracy was 98.32%, your validation accuracy was again 98.23% and your final testing accuracy is 98.24%. So when reporting your accuracy when you are reporting your model accuracy, then you'll have to report this testing accuracy. So 98.24% is your final accuracy, which is a very good accuracy neural network. So yeah, you have achieved that and you have done those, so I'll recap that. You have first, we have first loaded this MNIC data set, then we have reshaped that. Then we have created our training and testing set. Then we have normalized our data, and we have encoded our labels also into categorical data. And we have created our model by following those Let five architecture. And then I have trained our model and we have validated our model. So here this is your end of the project, and we can now it is done, and I hope you have learned a lot of things. So yeah, this is the end of the project. And yes, based on that, based on this knowledge, you can provide you can basically create other models also, yeah. So yeah, thank you guys. 19. Project 4: Automatic Licence Plate Detection: Hello, everyone. My name is Gorof. I have six years of experience in the field of artificial intelligence, machine learning, and deep learning. And today in the collaboration with HURsity, I brought one more real time project as a part of your internship, which is practice in the industry in real time. So this project is automatic license plate detection and recognition system. So I'll quickly walk you through the table of content we'll be going through in this video series. So first of all, I'll brief you with what exactly like license plate recognition system is and how it is used in the industry and in the real time applications. Then I'll brief you through what is exactly object detection. Then then as you know, for any machine learning or deep learning problem, we need a dataset. So I'll walk you through the dataset. Then I'll tell you what is transfer learning. Then I'll brief you with some of the object detection models and how to apply on how to use the pre trained models for object detection. Then we'll install the tensor flow object detection and we'll see the complete setup. Then we'll do the modeling part, using the pre trained model for our dataset. Then we'll train and save the model and we'll see how to save the model for future for us to use in the future. Then we'll detect the license plate from an image in real time when we'll pass a car image and in real time, it will detect the license plate from it. Then we'll apply the OCR optical character recognition to the license plate. We'll apply. There are many OCRs we'll see which are there. But in this series, we'll apply EthosiR. Why we are applying EEOsi we'll also see that. So we'll apply EZ Osia to detected plates to get the number and the license number out there, and then we'll save the results in a CSV file with a detected image and their corresponding number in the CSE file. So hold this thing we are going to do in this video series, and we'll see one by one. So what is exactly license plate recognition system? So if I quickly Google through if you see. So in, like, in the highway or anywhere, like we have several cameras running placed across in the highways. So whenever, like, car or a bike is passing through the highway, we detect, we can detect with the help of computer vision and deep learning applications, we can detect the license plate from there. What is the use of that plate? Suppose there can be many use, suppose there is, like, every car needs to renew or, like, check for the fuel consumption every year. So we can detect the license plate, and quickly we can verify with our database that this car has done those verifications of fuel consumption or not. And quickly, we can verify and quickly, we can detect the car like someone who hasn't done the procedure 2-3 years, then we can quickly detect that car and stop it at the next checkpoint. So with that, we can prevent the pollution occurrence from that car and from many of the cars. Suppose someone has broken the rule of traffic signals, and we can quickly detect that car who has broken the rule. And in the next stoppage, we can exactly same. We can just send the license number plate number to the traffic police and from that, we can quickly detect that car. Also, there can be many applications of the real time, license plate recognition system. So what we do here is, like, at the corner of any traffic signals, we have several cameras. From that camera, whenever a car is approaching there, like, it detects the license plate. Let me show you here. It detects this license plate out of that whole car. And from that license plate, it apply EZ OCR to detect that HR 26 BR 9044. From that, we'll just need this number, and then we can save to our database. And there is many Indian applications also like Mahan, India, you can see, yeah, National Registry service. Currently, it is not opening, but it is that E vehicle system in which there are many online service related to that license plate number. So all this information we can use if we are able to detect this license plate successfully. And this is one of the major application of deep learning and computer vision in real time applications. This is one of the biggest application of deep learning currently being used in the industries. And several companies like some startups are already approaching manywre in supposed Delhi to Japur Highway, that big highway. So there also people are implementing this license plate recognition system to detect the number plates. So this is it. And now, what is object detection? Basically, in an image, suppose I'll show you effect. Suppose I'll show you in this image. So there are basically three things three things in deep learning. Let me show you very quickly. Uh, so this is not opening beta sec. If you see this picture clearly, there are three things. One thing is classification in which we classify this image into a cat or a dog image. Second thing is segmentation. In this we segment this whole cat image by this borderline and then we'll output this face one is object detection. We'll detect this cat and we'll output the bounding boxes. Now what exactly is the bounding box let me show you here? Now you can see here, we have detected this dog and we have outputted this bounding box like this bounding box. We have detected this bicycle and we have outputted this bounding box. So this is basically the object detection. In the classification problem, we see we input an image and the output label. Like we are just inputting this image and we are inputting the label as cat, and then we are inputting another image of a dog and we are inputting the label as a dog. And then our model will simply classify those images into cat or dog. But in the bounding boxes, we input a single image, and we input also the bounding boxes of, like, the annotations, basically. I'll explain to you what an annotation is. And basically the input set is this picture and the annotation. The bounding boxes or we can say the coordinates of this bicycle. And every item in an image, like the bicycle, the dog, the car, these are the labels. These are the bounding boxes we are going to input in the model. And then the model will train itself so that in future, we'll just simply input this whole image, and it will automatically output us the bounding boxes. Like it around the car, it will draw the bounding boxes around the bicycle. I will draw the bounding boxes around the dog. I will draw the bounding boxes. Like, here you can see every car it is detecting, every truck it is detecting the person, the umbrella to all of this thing, it is creating a bounding boxes. So I just simply in this whole picture, we'll get the two car images. And here, just we'll crop this car image and let me open this aside. Huh. So if I'll just crop this car image, then we can simply get this number plate. If we can crop this car image, we can simply get this number plate. This we don't care because this doesn't show a number plate. So yeah, if we can detect the car in an image, then we can simply get the number plate. So this is basically the obj like here you can see. If this image I'll pass around the dog, it will draw a bounding box around a cat, it will draw a bounding box. Now, let me show you this wait. So yeah, let's see this. Yeah. So in an bounding box, we have this coordinates. If we assume as an XY coordinate, then this is your X plus width X plus Y. This is basically X will remain the same because the XF is not changing, but the Y will change because we are going upward the coordinate Y plus the height, and you will get X plus W Y plus H. So yeah. So this is basically your width, and this is basically your height. So if we detect a bounding box, so basically, will this is your X and Y coordinate. This is your X plus weight. This is your X plus weights and Y plus height, and this is your X plus Y. So we only need the four coordinates X, Y, we need the height we need the wits we need. Rest, we can all calculate itself. So the bounding box, the model will train itself in such a way, it will output when we input image, it will just output those X, Y, heights and weights and everything. Like, I will simply output the bounding boxes. So the four parameters it need to create train for every picture. Suppose we are inputting 100 images of this cat and dog in a group of features. In some of the images, only dog can be there in some of the images. Only cat can be there. In some of the images, multiple cats or multiple dogs can be there in some of the images, multiple dogs and combination of both like dogs and cat, both both can be there, so we can train according to that. The model will simply train according to that. In that we are only inputting two labels. Only dog and cat we are training. So this is basically the overall concept of your object detection is. Now, coming to the dataset, so in this basically the whole tutorial I'm going through is after this tutorial, you will be able to get your complete basically, you'll be able to do object detection in any of the dataset. Like, this is the whole template of, I can say, object detection you will learn in this series, and after that, you can perform object detection in any of the images. In this, you are applying this to the license plate recognition system, and you just need to change your dataset and some other parameters. And then you will, in future, suppose you are detecting you are training an observation model on suppose, let's say, pen and a marker. Suppose a pen or you can say a pen and a pencil. You are training your model according to that. So just you need to, you know, change your basically the dataset, and then you will get to work. So in this video, basically, we'll go through complete object detection procedure, and after that, you can apply this knowledge to your any of the problem statement. So first of all, we'll see what the dataset we are going to use. So this is basically your car license plate detection dataset which we have got in to the Kegel. So this dataset basically contains your images and the annotation. Now, what exactly is this annotation? So this is basically the dataset I have already downloaded and split it into the failing and testing set. So this is basically your car. Image, and this is your annotation respected through that image. Now, if you remember at the starting, I have told you, in this model in the training of the model, we need two things. Firstly, the image of this firstly, we'll need this image, and then we'll need this bounding box. Now, this bounding box, we need those coordinates where exactly we are going to detect the model detect the object. So these coordinates we need. This XML file or we can say this annotation, this exactly provides the coordinate. Let me show you when I open this on VS code you understand more clearly. Now, if I'll open this car zero into VS code, so yeah, here you can see car zero dot PNG that width and height I have told you initially, is basically this is not that width and height. This is not this width and height. This is basically your width and height of your image. Let me show you here. Yeah. So 500 cross to 68, so 500 cross thishs is basically width and height of your image. Now, this is bound this is your main thing which we are going to need. L X minimum, Y minimum X maximum Y maximum. Now, what exactly is this? Now, this is your X minimum. This is your Y maximum. This is your Y minimum, and this is your X maximum. So I have told you like X plus W Y plus But in that, X plus W is equal to basically your X maximum, and Y plus H is equal to Y maximum. So this is basically your input set will be. Like, I'll just input two things for deep learning model, the image. This is your I can say image, and this is basically the annotation respective to that. This is your bounding box coordinate. So the model will train itself in such a way that in future, whenever we provide this car image, it will automatically detect this license plate and output as detected or we can say the crop plate. So it will be easier for us to detect. Now this is your dataset you have gone through, and this has total of four, 33 number of images out of which I have already splitted it into the training and testing. And in the testing set, I have taken as 22 image only for the testing, and the rest of them, I have put for training of the complete model, and this is our complete data set. Now coming to the transfer learning. So transfer learning you must already know like many of the deep learning models basically, they are all trained on a large scale dataset which we call as imaginate. So all the deep learning models, we can say any of the model for classification or objectation, any of thing, they are trained on this imaginart dataset. So this is a dataset of a very huge number of images, 14 million images we have in this. And on this, all of the models for classification for objetation they are trained on that. So what we do exactly, if we try to train a model from very scratch, like we have created an architecture of our own and we are trading, we are inputting the image. It will take a lot of time, and the accuracy achieved will also be not that great. So what we do exactly, we train a model like we use the already trained model in this image net dataset, and we just fine tune that model according to our dataset to leverage those weights. Like suppose the image, like the already trained model. Suppose we take an example of Yolo. Yolo is a very popular object detection model. So here you can see, Ylo is a very popular object detection model. So if we take a Yolo model and the Yolo is already trained on this image t dataset, and it will as soon as I'll apply this model in this image, it will automatically detect these cars. It will detect these cars. So what we do exactly is we don't want to detect this car. Like, Yolo can detect this car or any objection model can detect this car, but we don't want our model to detect this car. We want to detect this tire. Suppose, let's say we want to delete this tires or suppose we want to detect these headlights. So what we do is we provide already, we just in wait, wait a second, I show you use the diagram. Suppose this is our neural network. Yeah, let's say this is our neural network, and this is our input layer in which we pass the input. These are our handle layers, and this is our output layer. What we do exactly in the transforming procedure is we freeze all those layers. Like we just freeze all those are by freezing I means that the weights will not change. Like in neural network, you know, whole the game is about the changing of weights. Like we change or we can say we adjust our weights in such a way that it will output always correct the required the desired output. It will compute to the desired output. So what we do in transfer learning that we freeze all these layers and we vary these weights. Basically, all these weights, all these hidden layers are basically your feature extractor. These are already learned many of the features, what exactly by feature, I mean to say that. Wait, let me show you the car image. So, yeah. So this is your car image. This has many features like this side mirror, this headlights, this number plate, this like you can say back mirror, you can say these tires. All these are the features. The model has already learned those, but we have trained the Yolo in such a way that it will detect this car, but we don't want to detect this car. We only want to detect our headlights, let's say. So we'll change the weights and we'll again train our model just to adjust these weights so that it will output the headlight, not the whole car. So this is a relatively less heavier process. This is computational less heavy and it will train very faster, and then it will give us a very good results also. So this is basically the whole concept of transfer learning, if I can define in 19, transfer learning is basically leveraging the weights or using the already stored knowledge in another problem statement. Like the Yolo model has already the knowledge of detecting many features of the car. We are just using that knowledge to detect the headlights. So this is basically the whole concept of transfer learning. Now there are many object detection model, and which are those. There is a very nice website you can explore. That is your TensorFlow Zoom. So this is all the object detection model which is being developed or used in old world. So here you can say center, resont efficient Det, SSD, Mobile Vito single shot detector, Mobile Vt SSD resont faster, CNN, mask R CNN extreme net. These are all these models. And what the output. What the output are the boxes. By boxes, it means the bounding boxes. As I told you earlier. The whole concept of object detection is we just input image and we need that bounding boxes. So it will output a bounding boxes, and it is already trained on a COCO dataset which I told you earlier, which is your image datasets. So these are already trained on that. This is your some parameters like the speed MS and Coco MIP. MIP by MIP it means mean accuracy, precision. So this is like, suppose we are comparing this model. So it has speed speed is very less, I can say, and lesser speed, it will be much good for our model. So it is of very less speed and the accuracy is 41. Now, when we compare to that, this is more speed and the accuracy is also less. So this is not a very good model for our comparison. This is also a getting of like this is having a speed of much higher L 222 millisecond, but accuracy is good. So we can consider that. So depending on the problem statement or depending on our choices, we can submit the models. Suppose we are creating or we can say we are training a model for the raspberry Pi or very small scale object. Then the accuracy is not a concern here. The speed is much concern here. So we can use any of the model which has very, very low speed. Like the time it takes to detect a bounding box should be very less. Like, this will not work there because it has a very large time. One bounding box will take a lot of time to detect. So it is not a preferable choice there. So we have to choose this model accordingly. So how to use this model that you will learn in the video and we'll proceed further. But now that just know that these are the models used for object detection, these are already trained and they are using in the industry in various applications. They are being using in this industry. So next thing is the tensor flow object detection setup. Now, how I will proceed further is like all the coding part will do in Jupiter notebook only, and we will create basically a very dynamic template for the object detection. And with that template in future, also, you can train any of the object detection models and use any those object train on any of the objection model in other data set all, not just the license plate recognition system. So we'll see how to do that and firstly, we'll create a virtual environment. And in that virtual environment, we'll install many of the packages, and side by side, we'll see how to do this and we'll create a dynamic template. So let's start that. Firstly, I'll minimize all this and we'll just create a new folder name, let's say, ANPR ALPR that ALPR is basically automatic license plate recognition system. So yeah. So this ALPR now let me open my command prom. Let me move to CD desktop. I will go into the directory desktop. Now in the desktop, we have our ALPR. Now, first of all, we'll create a Python virtual environment. Now to create a Python virtual environment, we have our command Python hyphen MV ENV, which stands for virtual environment, and then we name our environment. Suppose this environment I'm naming as my environment, my ENV. So whenever as soon as I presenter, it is already creating this environment. My ENV. Now, as soon as it will get. So it is finished. Now, we have to this is basically your global Python. Like, this is not any of the environment. This is your global Python. So to activate the environment we have just created now, we have a command called dot backward slash. Then the environment name my ENV. Then we go to scripts. Then we go to activate. Like, suppose, let me not put that command right now, just cut. So if I'll do a piplistPiPlist is basically listing all the installed Python packages in your environment. So if I do this now, PIPlist Uh, just let it low, yeah. So here you can see, there are so many Python packages installed. We don't need that in every time we don't need that. So that is a basic concept of the watch environment, why we use that. So only the packages or the important libraries we need for this project. So we are only considering that. So let me come on not now. So for activating our environment, my ENV scripts Script sign, then activate. By clicking this C here, your vouer environment is activated. Now if we click Pip list, C. There is only two Python packages are there PIP and setup tools which are by default. So firstly, this is your vocheEnvironment concept. In this environment, currently, we do not have any of the packages. So firstly, we'll we upgrade our PIP in this environment. For upgrading PIP, you can say PIP install, grade, upgrade PIP. As soon as you enter, we'll upload. PIP is basically your Python package installer, Python install package. This is basically your command which install all those Python packages. Suppose you have heard of Num Pi. So if I do PIP Num Pi, so here you can see. This is PIPYRg and this is PIP install Numbi. So PIP is basically your command to install any of the Python packages. So, yeah, it has, I guess. Yeah, so it has upgraded PIP 22 point latest son. So now all the work we are doing is on the Jupiter notebook. So let's install Jupiter Notebook first. Pip install Jupiter is a command. So it is gathering all those collective packages, and it is installing the Jupiter notebook. Let it install first. See, working in a virtual environment is a good option because for some of the projects, you need some of the libraries, but for others, it don't. And while This is like, at that point, you can say, why we are not considering any single environment. We can use the packages in one project. We can use the package in another project, and it will be of no issue. But see, the main problem is for some project, you require a different, suppose versions of packages. Like, for some project, you require a Numbi version of, let's say, greater than 2.4. But or you can say for some project, you can require a tensor flow version of less than 2.4. And for some project, you require a tensor flow verson 2.7 or above. So this is basically very conflicting. So it is better to, like, use a voucher environment and in that you can use any of the, you know, like, say, m, that packages of the different versions you want. So here you can see the Jupiter notebook is already installed. Let us open that Jupiter Notebook. This is basically Osama Jupiter space notebook. So see it is opening the Jupiter Notebook in RPC. So yeah, this is basically since we are in folder APR, so it is only displaying the content inside the PR. So this is mine ENV is the only content we have. So this is now, if we create a new new basically notebook here. Now, here, one thing you can notice, uh we do not have the kernel. We have a kernel Python three NPR ENV. We do not have the kernel we have just created now. Like we have just created this M ENV kernel right now the environment right now, but we do not have this environment here. So what we do is like we are just closing this duden for closing the Studeno youve command control C, basically. Now what we did what we do is we install a package called IPI kernel. To install I P kernel, yeah it is installing. So yeah, it is already installed. Now there's a command for installing the kernel in the Jupiter notebook is Python space hyphen, IPY kernel, install hyphen hyphen name equals, and this is your name of the environment. So yeah. So here you can see we have successfully installed our kernel. Now if we open the Jupiter notebook, let me close this. Now if we open our Jupiter notebook and this notebook, Now, if we go to kernel C, here we got our kernel, my ENV. So we'll create we'll select this mine wave because all the packages in this kernel we are going to use. So the first step is done, your virtual environment is all set up. Now we'll move to our first step of this project, which is we are basically defining all those pass. This is the most important thing we are going to do. We are defining all the setup of all those pass, so I'll quickly convert this into a markdown. Name this as setup pass. Now, in this basically, we'll define all those pass. Also, one thing I forgot to tell. In this project, we are basically using the tens of flow Zoo I have told you. In this project, we are going to use the SSG MobileNet to FpNlight. This model we are going to use. Why? Because it has a very low accuracy to chat has a very low time to and a decent amount of mean accuracy precision too, and it will output us the bounding box. So this model we are going to use. So let's just set of everything for that. Firstly, we'll import OS, since this is the important library. Then the custom model, I can say the custom model name custom model name. So this we will name as suppose my SSE mob Net, and then the pre trained model URL. I'll name this as pre trend model, URL. Now, what's that UR? Like I told you we are going to use SSG, MobileNet, two, FP and i 320 cross 320. So I'll copy this link. Basically, as soon as I click this link, it will like here you can see the bottom of the browser. So it is star dot CSt. So it is already a downloadable file. If we just click that, it will automatically start downloading, but we do not need to download anywhere else. So yeah, here we have paste. So this is basically This is basically your model. Now, also one more thing I missed pre trained model name is also very important. Pretrained model name. I'll just simply copy from here only. We here only, I'll copy SSG This is your model. This is basically dot G is your file extension. So yeah. So we are set up the pretrained model name and the URL. Now we'll set up a TF record script. What this script is exactly, you will see in further videos. Don't get confused right now. Just see that we are getting all our pass setup so that we can use it below our code. Generate tf record dot PI. Yeah. Now, one more thing we'll need is label map name. Anything you are not understanding right now, just see it once. In the further cells, you will connect each and every dots, everything. You'll know what this TF record script name is, you know what the symbol. You know why we are defining all those pass and we are using this model name and why we are doing that. You will get to know for the cells. For now, just like, see what we are doing, why we are setting up the pass. So yeah, all the pass have been set up. Now, m, yeah, we need some we need with the help of OS library, we need to create some of the directories. We can also manually create those directory. But as I told you in this earlier video, basically we are creating a dynamic template or we can say a dynamic code for the object detection. So which you can use anywhere in any of the future object detection task. Like, suppose your teacher or suppose you need to detect a guitar in an image. So you just need to download a dataset in which you have a guitar or annotation, and then you'll run this cell one by one, one by one, and just a little bit of things you need to change below and then you'll be ready with all your task. Like get your train model. So quickly, let us set up all those paths which you will need further. I'll create a dictionary first. Of pass, basically. So first, I'll say ox space pass. I'll say your ox space path. In this, I'll use our OS library, OS third path Join. It will create a library, I can say named as Let's name a sensor flow, the first directory, and the second directory will be ox space. So what we do is it will create a tens of flow directory, and in that it will create a box pad directory. So this is all we want. Let's create more one directory for all those scripts because many of the scripts we'll be using in this project. So let's put all those scripts into one folder. So yeah, script spelling misspelled it as yea Oath in again. It will be tensa flow scripts. So in that tensa flow folder which we have created earlier, we'll just add this script folder, and then we'll create one path for API, the model path, basically. Again, I'll just copy from here only. So yeah, in this tens of flow folder, basically, we'll create this models folder. So it will contain all those models in the tens of flow Zoo, basically. Then we'll create in one folder, we want all our annotations. Annotation path. And in this basically, I'll again copy this from here. So in the tensa flow path and in that pace folder, basically, I'll just create one folder. In the workspace folder, I'll create one more folder named as annotations, which will contain all those annotations. Now we'll create one image path which will contain all our images in our dataset basically I'll copy this. And images in the tensor flow Wopace will create another folder two folder we need. One is for images and one is for annotations. Like one is for the JPG or PNG file, one is for the XML five corresponding to that, uh let me so it's like one thing only. I simply write inverted single des only. Yeah. So next thing is the models path in, I'll also create one models path in our x space basically, which will contain our train models. So you'll get to know like this in next few cells. Just like we are setting up all those paths so that in the future also we can use same thing. So yeah. Now we will create a pre trained model path basically. Let me create a pre trained model path, which will basically contain all those pre trained models like the SSD mobile we do this efficient everything we saw. So I'll create one that for that. I'm sorry West path join, then again, our tensor flow, then our workspace. Then our pre trained model. In the workspace, I'll create a pre trained model folder. So, this is your pre trained model path. Then I'll create a checkpoint path. What is that checkpoint path? Basically, after in the training procedure, basically, after each certain number of Epox the model save a checkpoint so that if your laptop got shut down in between or your training is anywhere for any circumstance, your training is interrupted, then the model will save the at chat chat point. You will not checkpoint. You will not lose that training, already trained thing. Like in the small small projects, we are on the training time is only taking for 2 hours, 3 hours or maximum of 4 hours to 5 hours. But in industry level when we are training the model at last scale or suppose the image if we are training our model on the imaginary dataset, then it is going to take a long time. Sometime it takes one to two months also for training. Like the complete training procedure will take two months around. So in that two months, we cannot afford to lose our work at somewhere between 25 or 30 days. Like, on the 25th day, suppose our PC got broke and all the work we have all the training we have done so far, it is all lost. So we do not want that. So at each checkpoint, after one day of training, I will save a checkpoint. After another day of training, I'll save a checkpoint. Suppose at the third day end of third day, I save a checkpoint and in the middle of fourth day, it is like shut down. The PC has shut down. So the third at the end of third day, we have already the checkpoint of the third day. So we can start our training from that checkpoint only. Like in the game, we used to play, we save a checkpoint and then we'll start from there only. So that is the concept here also. So yeah, this is your checkpoint path, basically. I will quickly call as CheckPoint path in that OS path join. I'll create basically in that workspace only some model name. In this only, I'll create. I'll not name. I'll save this in the models. And in that basically, I'll pass the custom model name. This This is basically the whole point of creating a lot of variables here. Like, suppose every time we are not using the mobile my SSD mob net. So suppose if in future I'm using the models, suppose efficient net. So I'll just simply edit here. Rest hole of the code will get same. So this is basically that's why I'm creating this whole lot of code because to get things all dynamic, very, not static code. So yeah, it will help us in next future. So yeah. One, I'll create an output path. This is basically, again, tensor flow box based models OS sort path or join. So yeah. In this, basically, I'll again in the custom model name after that custom model name, I'll name one more directory as export. So this will basically output any type of output after in the training procedure, any type of output is there, it will save in this territory in the tensor flow in the workspace and in that models part. That also like my SEC mob net folder, it will create a folder named as export. Like this is basically your. Then I'll create one folder for also TFGSh this is basically tensor flow in the JS JavaScript. It will sometimes if we want to deploy our app not in Python in JavaScript, then we need our model to be in the JavaScript. So it will save the model in that format also. For that, I'll also create Ospatht join, TensorFlow, then again, workspace, then again models. And in that, I'll just write this custom model. And in this, basically, I'll create one more folder as I did earlier. TF Js and TFJsEport. Yeah, TJs, export. So one more path, same as this TFJs I'll create. This is your TF light. Like sometimes you are not just creating the model. Basically, the model we save if you remember, is the.h5 file. And sometimes if we want to use in the JavaScript, we use the TF the JS five. So if we want to use in the Raspberry Pi. So we have to use the TF Lite file. Tens of flow has already inbilt libraries to convert those H five into the light version, but we need to save that model in a separate file. So here I am doing that TF tc. Flight path, basically. In that, you will have OS or path join TensorFlow workspace model, customer model name, and in the TF Js, no, here in, TF Lite export, basically. TF Lite port. So yeah, everything's on, one more thing I miss Proto path. What is this you will understand below? Don't worry about that. In this plight Pa thought. This is basically some of the scripts which we need in the op detton so we are creating a separate folder for that. Tens of flow, then Proto. We create a outspace apart from workspace, not inside the workspace, we'll create a separate folder for that only. So, I think the path is done. If there's something remaining, I'll create after we'll create afterwards. So yeah, for now it is cool. Now, let's create one dictionary for the five. For the pass, we have already created now create for five. One is basically your pipeline config. And for the pipeline config, we'll create one path. This is basically the whole configuration of our model. Like, suppose we are using SSE, MobileNetV two FP and Light verson here. So whole configuration of that model, as I said earlier, we are using transfer learning here, so we have 20. Project 4.1: TensorflowObject Detection Setup Installing Verifying Packages: Welcome back, guys, to this second part of the license plate recognition system video. In the last video, we saw how to set up pass and how to create folders and everything. And when we run those codes, we have successfully created the folders. Here you can see in the ALPR tensor flow, we have successfully created those four folders. And with the help of this code, this code will basically run on both the Linux machine like we have set up for the postfix and the Windows machine that is empty. So it will work accordingly. We just need to run those four cells. Why this is very important because every time we are not training an obiation model on our local PC. Sometimes we will take we will train it on, like, a Suppose we are training it on a colab, or suppose we are training it on a Kegel. So for that, we need this dynamic code. So for that, I have created this like, complete setup pass code for both the machines. Like, either you are training it on a colab or you are training it on a Kegel or on your local PC or somebo in your university PC. So all that everywhere at Tilburg. You just need to change some small details and this code will work. Now, how to set up paths we have already gone through. Now, let's install, first of all, let's download all those pre trained models from the tensor flow Zoo. TensorFlow Zoo, I have told you yesterday, it is basically collection of all those object detection models. Let us see once again. Yeah. So here, TensorFlow Zoo basically contains all those object detection models with, like, guide to how to implement each of those models. So first of all, let's download all those pre trained models from TensorFlow Zoo and let's install tensor flow object detection. That complete setup basically this is your step one. So let me write here step one, setup pass. And the next step downloading all those models and setting up the object detection, tensor flow, we'll see that in this video. So let me write that step two here. I forgot to write on the markdown. Step two, basically, I'll name it as download pre trained models. From tens of flow Zoo and install TensorFlow object detection. So yeah, this complete setup will be going through. Now, first of all, for getting any downloading any file from the Internet, there's a library in Python called as wget. So we need to do firstly, we need to install that library first. So I'll just write the code for that if OS name equal equal. Like, again, we are using this for Windows. So yeah, pip install. The Blue get. If it is present, then it will not install it. But if it is not present, then it will simply install that and then import that Bluet library. So let me run this code and see here it is collecting DG and it is successful, install the Dubs on 3.2. Now, if we are working on a Linux machine, then the D Gate is already pre installed. So we do not need to install that. That's why I have only written at NT. In the s, I can simply write as this. Like I can write as s and just pass. But it is like it is not necessary. We can simply write I condition, if it is Windows machine, then it will install DubugOwise it will skip that. So we have installed this WGate version. Now let us install, let us clone all those already that API model path. This path we have already set up in the tensor flow model. So let's clone this repository, this tens of flow Zoo. This tensor flow Zoo repository into this folder only so that we have access to all our pretend model. So let's install that o dot not. Again, I'm creating a very dynamic code so that it will work for any environment or anywhere. If the repository is already cloned, then it will not do it again. So I'm doing that only. In the past dictionary, we'll access this API model path, API model underscore path. And in that, basically, I'll go into our research, and in the research, I'll go into that object detection. Object detection. So it will go into this API model path first in the tensor flow models, then it will create one folder name research, then it will create one folder object detection. And into that, I'll clone like all those libraries, all those models in the tensor flow Zoo. So yeah, let's do that first. We it is missing. If it is not if this path is not present, then, clone. If it is already present, that means the repository is already cloned. Like the research folder, the objector Mul, this is already cloned. So we do not need to clone again. But if this research folder and this objection folder is not present, that means we have not cloned the repository yet. So we'll clone that repository. And the link for that repository is I'll just write down github.com, tens of flow models. In the tens of flow, we have the models. Let's visit this ink once, then you will get to know what we are cloning exactly. So yeah. In this tens of flow, basically the tensor flow Zoo, this is only a read me file. So it is very inside this tensor flow model. So we need this whole library. Like this whole repository we need. So in this tensor flow, you can see, there is research, and there is tensor flow models. In the tensor flow models, you have access to various models. So yeah, this whole repository, we are going to clone it down, and it's clone it first, where we have to provide a path too. So we'll provide a path as the API model path. We have created one folder before only. API model path. So yeah, let's clone it here. We enter this. So this code is running. In the workspace, we have this API model path we have in tens of flow and models. So intensive flow, sorry, tens of flow and then models. So here you can see it is cloning the whole Git repository here. So it is cloning down. Here, you will see this complete repository. Like what these two things we mainly need the research and the object detection folder. So yeah, uh this research and the object detection folder. So, the two things we generally need Here's the read me file the complete documentation of the tensor flow models there. So if you want, you can read that also. The support like Python 3.7, 3.8, 3.9 and 3.10, and all those things. And after cloning, it will take some time. Depending on the network speed, it will clone, and that's wait for some time. It is cloning. Here you will see basically, yeah, here you can see, it has already cloned now. So in the tensor flow models, we have same repository as we saw here. So it's Github community folder, official folder, orbit, research ten every folder is there. So we have the complete tens of flow models folder cloned down. So yeah, here you can see. Now, after cloning all these models, now let's install the tensor flow object detection complete thing. Like this is very important. So first of all, again, we are creating a dynamic code environment, which will work on both Linux machine and the Windows machine. So firstly, do it for the Linux. In the Linux, we simply write OSM, equilqualPosfix. If it is postfix, then it is Linux machine. And if it is empty, this is your window machine. So for Linux, I'll write those commands, APTgt install. Protobuf basically. This is your compiler, basically. And this is your whole complete tensor flow object detection relies on this proto Buff. This is developed by Google. This is a compiler. So the complete tensor flow model tensorflow is also developed by Google only as you like. No. Uh CD in the folder named TensorFlow models, research, proto object detection. Object detection. In this I'll create one path, which will take all those files and you do not need to completely understand what's happening here, just like C and just side by side code with me and create your own template too so that you can you will also you can perform also the same task whenever you want. Like whenever you want to train a object detection model, you just simply run this code and do those minor changes, then you'll be ready. CP object detection. Object detection. Packages. Then your tens of flow two comes. So because we are working on our tens of flow two version. Tensor flow is basically the tensor flow is also one tensor flow basically named as tensor flow one and another is tensor flow two. TensorFlow two is just an upgraded 10 tensor flow one. So currently we are using TensorFlow two as the latest part. Set up dot PI. Here you can write Python, Pip install and everything. Like dot represents everything. So we'll install the complete package. Now this is for the Linux command. Now if your PC is Windows, which is R case, what all code we have to write. So if the PC is NT then first of all, we need that EURL where we have to install our whole repository. For that, I'll write as you can see this as I have said, like protocol buffers, it is the complete object detection model relies on that. So I'll just copy this and I'll just write a command after that. I'll download the version 3.1 0.3 0.15 0.6, basically. This is a version of the compiler we are installing. You can install the latest one also. It is not going to make any difficulties. But I'm just using this for my current project. And my windows is 64 bits, so I'll write 64 dots. This is basically your file name. This is nothing else. This is a file like this is your compiler name, and it is going to go and go to this link and download this file, and then it is going to install. So yeah, this is your G. And now we have that ERL to go into this link and download this. We need dot URL, sorry, w dot download. And in this, we are going to pass this URL. So it will go into this URL and it will simply download this complete file. Now, as we have downloaded this file, then we'll simply move this file, this file name, I'll copy from here. As soon as we'll download this file, we'll move this file into a directory which we have created earlier in the sorry, pass. And in this pass, basically, our Protok path, we have already created one folder. So in that we'll simply move this and then we'll move our command to the proto file, this path so that we can install it from there. And after that, we'll unzip it. After moving into the directory, I'll simply unzip it by writing to our hyphen F and this again file lane. So it will unzip this file name, and then we have to set up some of the OS environment path. So I'll simply write OS sorry environment. And in that, I'll simply pass this path. And it is like OS sort path. CEP plus OS ABS Path. In that, I'll join one directory. Pass or join pass. And this path, I'll pass it down here. The proto path where we have moved where we have downloaded and unzipped this to zip file. The path we are going to like the file we going to install, and I'll move it down to the bin folder. Yeah. So here, the path is like environment is set up. Now let's install this for installation. Again, we need to move into that directory tensorflowmdel dot research. TensorFlow models and then research. In that, basically, we'll write proto object detection, the same thing, the same thing we have written here, with a minor difference. I'll copy it till here only. So yeah, to the object detection, I haven't copied this proto. Let copy down. Yeah. So intensa flow and this and after that to object detection, protos, and I'll complete whole of the files we are going to take all with the extension dot Proto. Then Python out is equal to the check detection. I'll write it down simply here. T output equals to I, and then I simply copy the object detection folder. And in that backward slash packages. And in that we'll have TF two and from that sorry, backward slash TF two, then double backward slash. In that we'll have one file named as Sent PI. So from where we're going to install tens of low object detection. And this we are going to apply Python setup dot PI. After that, we'll write build and Python setup dot P install. Firstly, we'll build the wheel and then we'll install. Python setup dot PI and then Install. So, this is a complete command for installing and after that, we'll write one more thing. Miss it down here. So again, we'll move to the tens of flow model research folder model research folder, then we'll write SIM then again, Pip install. Yeah. This is your complete code for installing the object detection. I'll write it here also, so that it will not get confused. What is the name? I'll write it down here, Install tens of flow object detection. Tens of flow object here it is not. AOS name equal equals and T, so yeah. Here I have written this. Now, let's run this and let's see what's happening. This UR is not founding, why it is so. Let me see once. I write in tpstia.com, protocol buffers, Ptograph releases, then download, then version 3.15 0.6 proto, so here is not equal. It is hyphen. And windows zip then rest everything. I guess this is also we have to change. And here also, we have to change. It is not equal.This is basically hyphen. You you will not need to do this again and again. This is one time thing. And after that, you will have all those dynamic command ready. Let me run it again. So yeah, it is running. It has downloaded this protocol buffer set of file that zip file. If you want to see what's happening inside, so you can go to your this environment, my email because in my ANV only we are installing everything. So in this, you can go to library and then site packages, and here you will see the whole changes. 159, you can see 160. So it is installing whole stuff here only. It is 160 items, so it is installing everything like here, here you can see, 162163. So every package is, all those packages which are necessary to perform like object detection or train a model on object detection. All those library, we do not have to install one by one and every requirements. We not have to install one by one. So all those requirements, all those packages, libraries, and everything, this code will automatically going to get and install for us. So this is like the beauty of this code, basically. Here you can see we are getting some of the errors. So it has installed, but it has pop up with some error. What's that error? Firstly, we do not have a Python library named as Num Pi. No issues. We can install that too or anything else. Okay. Requires pi passing. So it has installed, but it has encountered some of those errors. Okay, so I'll install install numPi so that will not pop those errors. So we have installed this numpi. Let's again run sorry, let's run this. See if we can get anything. I already if the packages are already installed into that environment, it will simply skip. Like first time in this environment, we do not have the package named as Numbi. So while installing the Numbi, it is installing. But if it is already installed and if it is already there in the environment, it will just simply skip. So this is like those all thing will Pip fill manage. We do not need to do that. Now, again, it is running this code, and if anything's there, it will tell us. It has installed many of those libraries. We need complete setup to, you know, perform the obdit detection. Let's see that a. Here, you can see it is installing more libraries. So let's wait for that. Here you can basically, I'll write for you what all things you need to install more because some things definitely this object dediction this dynamic code will miss out. So for those things, you need to install those manually. So I'll simply write so that it will get easier when the next time you are performing this. Let's wait for this code to run. After this, we'll perform a Pip list and see all those packages. Also in the tensor flow, like the API model path that API model, the TensorFlow models path in this TensorFlow models path. In this research folder, and in this research, we have our folder named as object detection. Here we'll go to Builders. And in the builders, we have a file name as model builder TF two test dot PI. So this is basically your testing script. Like the whole basically the whole the whole set of packages, the libraries, everything we're required to perform an object detection. So all those packages or everything, it will verify from you. So we'll also run a verification script after this so that we are confirmed and we are like we have that surety that everything required for performing the object detection is now already with us. So we did not get errors like further. In my environment, let's go to library site packages. So here you can see it has already installing many of those libraries. It is installed 192193. All those packages which this optation model is installing. So when we run this, when we start training our model without installing those packages. So we'll simply get an encounter an error, and this package is not found. This package is not found. And sometimes, it will not tell us what's the error, and it will start putting out a random error. So for that, this is very important. Like with the help of this URL and this package and this set of code, you will simply install the complete thing, a complete setup we required for the operation. So this is very important, and this is a very helpful code. So let's wait for it to complete. It is installing, as you can see, till then, let's not waste the time till then I'll write the verification script too. So this is let's name it as a verification verifications script. And firstly, I'll name it in a variable. The path of the verification script I just told you, I just gone through we just go rough that setup file, the test file. So let's set up the path for that file. In the fuzzy we'll go into the API model, that tensor flow models path. And after that, we'll go into this research folder, then we'll go into that object detection folder. Object detection folder. And after that, we'll go into this builder's folder. After that, we'll write those path name model builder underscore TF two underscore test dot PY. So this is our file path. Let's see here. So yeah, it has run this, successfully installed. So anywhere, anytime in the end, you will see the successfully installed any of the packages. So yeah, it has installed all those packages. So here you can see we haven't encountered that error we are getting error like initially. Error one error 3.2 0.1 is installed, but put above is less than nine is required by tens of road tens of flow. Okay, let's not see it now. Let's wait, we'll see it if it is encountering any error in future. So till now, we have successfully installed. Let's run one time pip list. Let's see this. So here you can see the tens of flow version is 2.9, the tens of flow Okay. Error it is putting down here, protobuf. What's the version of our protobuf? Here it is 3.2 0.20 0.1. And it is saying that it is not compatible with the version tens of flow and tens of flow board. Okay. Okay, we'll see this if we are encountering any error after that. Let's proceed further. We'll see if we are getting any error. Or we can simply do one thing. We can uninstall the pen tens of flow version, this and we can install our own custom version. So I'll do this basically by uninstall tens of flow. And after that, we'll just install our version of tens of flow. Let's install version 2.7. If you install tens of blow, it's also install tens of flow GPU. I'll explain to you what that is. Let's install 2.72. It will basically uninstall all this tensorblow estimator 2.9 boat 2.9 and everything. So it will not encounter any error. These all things see. These all things will not you will not be sometimes people not understand in one video. So these are all things like reading the error, interpreting the error, and, like, manually solving those errors. Like, these things you have to, you will learn slowly, slowly after you are doing many of the projects and many of the custom, like if you do anything from scratch, without the help of any video or anything, then you will get to know this. So yeah, this thing will slowly, slowly come to you. Don't worry for that. And for that, for the rest of the time, let me write this script for running this Python. I simply pass here verification script. It has stuck I don't know why it is stuck here. Let us see the progress in the task manager. With the task manager, you can simply see what's running here. Let's run this verification script for now after that. No, it is not running. Let's wait for some time while it is uninstalling tens of flow. This is the command, I guess for tens of flow. If I get to this command, sorry. In this, we have our APR and in this let me activate our environment. Activate. And in this when we do a pip list, no, it is not uninstalling. It is still there. Let me, control here. So it is running a verification script for now. Let us do that pip list again. So let us uninstall tens of flow from here only. Install tens of flow. It will uninstall these many libraries. So yeah, we need that. Let us uninstall this. I the command prompt, you will see this output also. So it is much easier. Now if I do Pip list, tens of flow is gone, but some things are still left. So let us install this tens of board also. We uninstall tensor. Because these two library, this has outputted that protopuf is not compatible by tensor board, and now let us install the fresh version of tensor flow. Tens of flow equilqual 2.7, let's say, and also the tens of flow GPU. Or let's install a little lower version 2.4 0.1, let's say, because I do not know if it is still compatible or not. I install tens of flow, tens of flow GPU. Let's install that. It is collecting those packages first. It has collected both the packages. Let's wait for it to install. Okay. Yeah, it is collecting all those packages for us. Yeah, this library here you see the optim this library. So it is installing that also, and here you can see in the verification script we are verifying all those we have all those packages with us that requires our object detection to run. You can see the optimism is not found. So after running this code, this error will be gone. So yeah, this is why I'm doing this manually installing the tens of flow again because obviously it will encounter the error again. Because sooner or later, we need to do that, we need to uninstall and install it again. So why not? Why wait for future? Do it. We'll do it currently right now only. Let's wait for some time till it gets installed. You'll see all those activities. One. This is basically what we are doing right now is basically we are setting up the whole environment required for the opposite direction. After that, feat, every time, we do not need to wait for obviously the installation will take some time. But this code writing part, this template you will be already ready with, so it will not take any time. This is only a one time effort, you know. Let us see what's happening, what is stuck here. Okay, gotalling. Here it is collecting the packages, then it is using installing collecting packages. And it is obviously uninstalling some of them because when we are installing tens of flow 2.4 version, then it will not require tens of flow estimate of 2.9. So it is like installing that. Let us wait for some time, also. Let's write code for importing the obit detect till then. Yeah, let's write us that. After that, we'll verify. So after that, tensor flow object detection is installed and verified by this verification script. We have to import the object detection. Why am I writing objection again, again, object detection, and then again, we'll create just sex. So yeah, here you can see all this is installed. These are popping up some errors, but installed this iso These some errors, but I'll simply do a pip list here. So yeah, here you can see tens of flow 2.4 0.1 is installed. Tens of flow GPU is installed, tens of blow estimator is 2.4 0.0 and everything is installed. So yeah, we have, everything completed. Now let's run this verification script now. It will verify all those packages and it will pop up any error we have. So here I was writing the numbi you also write tens of flow equal equal to 2.4 and the tens of flow GPU equal equal 2.4. A. We are getting an error here. Let's Google that error. I do not know what's this error, actually. Let's google this error. Here it is not. Yeah, see. Here also someone was trying the verification script and here it is error is popping. So let us see any solution for that. It is d. Okay, it is suggesting us to run this code in 2.7. Okay. So earlier we were doing actually correct units again install, sorry for that. Let's install tens of flow 2.7 only. It is basically collecting this tensor blow 2.7 package. It will automatically uninstall the 2.4 version. We do not need to manually do that. Let's wait for that. Yeah, it will uninstall what is not necessarily like C nine. Let's write the code for object detection till then. Basically, we have let's assume we have already installed all those tensor flow of detection and we have verified and we have got a success message there. Like, I'll show you whats message is. Then we need to download the pre trained model, like the pre trained model we were talking a long time back, this model, basically. Yeah, this model. So we need to download that also from the TensorFlow Zoo. So let's write code for that. Again, that dynamic code. Firstly, we'll write for the Linux. And in the Linux WG, and then the pre trained model URL we need. But and this pre trained model URL. Then in the Linux to move, we need to write the MV command I'll move the pre trained model name plus I'll add one extension because the model will named as stardd head Zip file. It is a compressed files, basically. Then I'll again, write our pre trained model path. Oh sorry I have not put in the inverted codes, trained model path. Then I'll move to that directory. Again, I'll write the path pretrain model path and this command is for unzipping in the Linux. I'll write that pretrain model name plus theta dot G set here and that name. Now, this is basically for your Linux and that's write it down for the Windows also. See this again and again, we are why we are doing that because as I've told you earlier also, every time we are not running the object ection because it requires the installation of packages also taking us so much of time. So this is basically require this whole object detection or training any deep learning model. This requires a hell lot of hardware requirements. This needs very robust hardware requirement. So every time we will not be using our local PC. Instead, we'll use some colab or Cagle. So for that Agar Cab they uses the Linux pCO that these codes sell with work. The you'll not be getting the windows. So let's write pretend model dot name. The same thing we have done above because the file name will obviously be same either it is a Linux or Windows PC. Model path. Then I'll write I'll simply copy from here only because it will be same for both Windows and the Linux. 310 path, ds, yeah, this thing. So yeah, when we run this code, it will download and install, here you can see it has installed this library. Now let's run this verification script again. Let's hope it will work now. Now here, you can write tens of flow 2.7 only if it is going to work now. Say a verification script is running, delete from here, delete from here. We placed also delete from here only. This we need, this we need. So let's wait for the verification. Now, the verification script is basically verify. Like all those packages we have installed with the help of this code and with our external sources, all those packages we have installed this verification script is verify we have sufficient number of sufficient hardware sufficient software requirements set up for running this object detection. So this is basically doing that. Now let's go into that preach and model path till then. Was that path is basically your tensor flow workspace and this tensor flow workspace, and your Annotations. Sorry, not annotation. This pretrained models with the pretrained models. So yeah, in this basically, so here you can see the verification script has run. And yeah, here you can see and 24 test and Okay skip. We whenever you see this message, like, Okay, and skipped, this means you have successfully installed all those packages. If it will show any error like this module name is not found, this module has not found, then it will obviously show here only. So yeah, we have successfully run this thing, and now let's import the object detection first. Okay, yeah, one more thing. Like, many of the time, while running the code till here, you will not see any like this objection might say no module name. We have installed this objectation, but it will still show the module name, no model. So what you need to do that is just restart your kernel. It might have, it hasn't updated yet, so you need to restart your kernel MNV and after restarting, we do not need to do all things again, we need to run some cells. And now, if we run object detection, so yeah, it is important. Now, I'll download that pre trained path. So here you can see it is downloading. Okay, the syntax of command is incorrect. It is showing what I have done wrong here, it is run this line of code, but it is getting an error. Pre trained model name, and I undated those two strings and taught the GSED then okay the paths, basically the name was pass, not the path. So pretrained model path and like the rest, everything is fine, I guess, let's run it again. This is basically downloading your system cannot find the file name. Again, it is getting an error. Pretrained model URL SDx said System cannot find the path name. Let's run it down again why it is showing Path specified. Download pretrained model URL. I don't know why it is showing this error. Pretrained model name is also a model URL pre trained model name. Basically, this name, I'll This name is also correct, like we have Data dot she said is there. Just wait for a sec. See model name. What we'll do is we'll restart our kernel once again. Let's see if it works or not. Model name dicta dot G, everything is looking fine only. Let's restart our kernel once again. I don't know why it is showing this error. Let's import our objecton again. Let's run this. Again, it is showing this error. Pre trained model URL. This URL, I think is fine, right? Yeah. URL is fine only. And here you can see this is Coco 17 T two underscore. The name is correct, right? Okay, let's delete all those files first, then let's re try because the bluegate is downloading again and again those files. We only need one. Let's Let's run this now. Again, it is saying the same thing. Pretrained model path, let's verify it once. Pretrained model name plus dot set. The name we are writing is correct, I guess. Okay, so it is already named as To tar. Tochi said. Let's try with this. Let's see if it is, again, it is not getting. To SSD, Mobile V two SPN, 320 gross 330, COCO 17, underscore TP eight to tar. Everything is looking fine only. TP eight tar. I see property. It is dot G that file only. Then why is showing this error. It is downloading correct. It is writing the pre trained model name as correct. Copy from here on just to be sure it pre trained model path. We are giving us correct Pretend Model URL, pretend model name, Preten Model URL and Preten Model Path. That we are giving as correct only D target, I think it should work, but I don't know why it is not working. Let's run it again. No is saying that same thing again and again. Okay. Let us, I'll just work it on that where it is showing an error, it must be a minute error somewhere. Let's see, once again, move and then system cannot find the file specified. Move pretrained model name. Pre train model name, the pretend and everything we are giving fine only. Pre train. Let us see this once. Oh, okay, sorry. Pretend model name is not defined. Why is showing this pre trained, see, here it is getting an r pretrained spelling, I have written wrong. Pre trained now it is correct. That's why it is giving an r. See? This is what we were doing from that time. Now it will run. I hope you are also getting point out. Basically, we are misspelling here and we are accessing that file from here. C. This is basically this has installed your SSE mobile Net VT. Now, if you will go to your tensor flow, this path pre trained model path, pre trained model path, tensor flow workspace, pre trained model. Train models and then this SS mode. So here you can see this your trained weights. This is your weights of the train model, this it has installed already. So we have completed step one, sorry, step two of this object detection. Till then, we have successfully, set up all those dynamic paths. We have successfully let us do that. Yeah. So we have successfully installed and set up our object detection. We have downloaded those pre trained models and everything. So in the next video, we'll create the label maps, we'll create the tensor flow records, and basically, we'll get our model ready for performing the training procedure. Now, every installation and everything is more or less done. So in the next video, we'll see how to, like, get ready for the transfer learning and, like, get our model ready to train. So yeah. Thank you. 21. Project 4.2: Create Label Map TF Records Model Configuration Pipeline: Hello. Welcome back, everyone. So in the last video, we have successfully installed our object detection, the TensorFlow Object Detection, till now, we have completed two step of our license plate recognition system. In the first step, we have created or written code for the dynamic folders creation and everything. And in the second step, we have downloaded the pre trained models from the tens of flow hub bottles hub, data TensorFlow Zoo and we have installed the tens of flow object detection. We have encountered many of the errors, and we have seen how to install the tens of flow object detection through the proto the protocol buffers in both of the systems, like in the Linux and in the Windows system. And we also saw how to run the verification script which is provided in the tens of flow object detection repository, and we have successfully imported the object detection, and we have downloaded our pre trained mode model we are going to use in this license plate recognition system, which is SSD Mobile Net V two FBN Light 320 cross 320. Now the next step or we can say the further steps of our object detection procedure is to create a label map. Now, let me just write the step three for that. Step let me write the markdown, like as we did here. So this is your create label map Now, in deep learning, you see, we have to provide an input and output. That is the label corresponding to that. Now here our input is the bounding box coordinates, like the coordinates we are going to detect and the label those coordinates or I can say those bounding box represent to which of the label. Like suppose there's an image of let's say, let me show you an example only. There's an image of this car. See. This image of let me show you the backside view of the car here. So this is an image of a car, and this is your bounding box for the license plate. Suppose this is the bounding for the headlight. This is the bounding box for the tire. Suppose three labels are there in a picture. So we have to provide a label map which consists of three keys and values. Like when there is this, we will provide label like this. Like, we'll represent this since the neurom network doesn't understand any text or any string. So it will understand zero, one, two, three, any numeric values. So we'll provide this bounding box like let's say license plate bounding box as zero, the headlight bounding box has one, and the tire bounding box has two. So we are going to do the same thing here also. And as you know, like in our dataset, basically, this image, this annotation, let me show you while opening in this VS code. So when you will open any of the annotations here in the VS code, so here you can see, we have total of one annotation, like one label here, the license. So we'll create the same label map here. Let me show you how we're going to do this. So we'll create labels variable first. And in this, the first is your name. What is your name of the label. Note here, it should be the same as here, provided. This should be the same. Any spelling mismatch will cause error in further steps. Now, I'll provide one ID for that, and the ID I'm going to give is as one. And suppose there are ten labels in a picture, then this dictionary, you can add here, also one more label. So since in our case, we have only one label, so I'll create the labels as one only. Now, let me create a file. Let me write a code of dynamic code for the file creation. The label map we are going to create in this file path. Like, let me show you here this label path. Yeah, label map. So this is we are going to create label map. We have already defined a directory for that. Let me write here files and then label map. And with open, I'll write in a write mode, so as W, not in a read mode, as F, and let me write in that for label in label since in our case, it has only one label, but in other cases, it can be of many labels, like multiple labels. So let me write here first the item in the dictionary, we are accessing the keys one by one. So firstly, I'll write the item, let me write here only N. The next line, we write the tame. The slat is basically the table space we are giving in. The slash name. Yeah. This is it basically dot. I'll just format it so it will be in the right format. So yeah. Here it goes. Now, it will write. It is giving an error basically. Underscore. Here I have written this, but here it is to know. Yeah, now it is perfect. So this will write. You'll understand what we are doing when I actually run this code, and I'll show you the output in that directory. For now, just understand what we are doing. Now I'm writing this ID. Slash, and again, I'll format it in the same way with the label as the ID. Let me write it this way. Yeah. Here it goes. Then I'll write, I thought, last like the curly braces, the closing curly braces. Well, again, create a space here. Now, all is good. Now let me run this code and let me show you what it does actually. Let me go to this the label map directory where it is, the annotation path and label map name. The annotation path is tensor flow workspace annotation. And when I go to this directory, PR, then tensor flow, workspace annotations, here it goes. The label map, I have just like we have just created here. So let me open this on a editor coedor So yeah, here it goes. Item. Like here, name is license and ID is one. This is what exactly this code is creating. So it will create in this format. Now the step three is completed. Now let's move on to step four, where we'll create the tens of flow records. Like, the object detection model will not expect like in the image classification or any of the other tasks, we are just preprocessing the data so as the model gets input in that format because the neural network will not understand any image or any labels or anything. It will understand only the numeric values. So we'll create the tensor flow records. After that, we can input our input that particular record to our model and we can proceed further. Let's create that tens of floor limit as create TF records. This is our step four, basically. Now I have written a given a path for I guess tensor flow. Here it goes, tens of flow records script. Now, if there is a script, basically, which will create all those records, we do not have to manually create those records. The record doesn't exist in this directory, then we are going to create. Otherwise, we'll just simply skip this is what this line of code is doing, if not. Now I have already one script in my Github repository, which I have taken from the object detection official object detection repository this repository. So I'll just simply clone this from here. You can also do the same clone then this record script GenerateF record. Yeah, everything's good. Now I'll again give the path as the scripts path. We want all our scripts in the script path so that everything will not be a mess up in the end. So I'll copy here. So it is cloning this repository, and here it goes. It has successfully cloned, I guess. Let me check once. Sorry, this is not a It is crooning into the path. So yeah, it has clone successful tensorflow scripts, and here it goes generate TFRecord. So yeah, by this thing, we have successfully cloneed the TF records. Now let's create TFRecord file. I'll just write down a code through which we can generate the tensor flow records. So for that, I'll just write Python then files. TF underscored record underscore script. The OS path join. I'll join the path of the image path first. Image path first. And then I'll join the train folder. Now, what exactly is this? The image path you see here is tensor flow space images. Now, there are no images in our folder. So let us copy this image. This by mistake it has created first. So let me delete that. Deleting. But sited. Now let us copy these images. Like these images we have seen in starting. This is the trading folder and this is the testing folder. Let us copy these two folders in our tensor flow, sorry, tensor flow, workspace and images folder. From here, our script, we actually pick 11 images and create the tensor flow records. So for that, we need to copy those images first. The training and testing record, we are going to create the records for that separately. So first, let us create for training and let me do that for training first. Again, the files, the label map. Put thought path thought path Join. Again, I'll join the path of annotation Path two because as input, we need both that thing. Annotation path. And I'll simply name it as the train record. Train dot record because the tensor flow is the TF record we have created. Now let us create the same thing as for the testing to the test record. In the same TF record path join Image path, I'll just name it as the test and rest all things will remain same. Here, I will just change it as test records. So let us run this line of code. It is not opening TF underscore cannot it is saying can't open the file, TF underscore, record underscore script. Why it is so. Let us check first TF underscore script. Let us see this here only. Then we'll get to understand. In the tens of flow in the tens of flow scripts, we should have a name Gentfcord dot PY. It is same, I guess, then why it's not opening. T record underscore script. But if you can't open the file. Let me see once. The same file we are having the tf dot record. TFRecord generate tf record. Let me only write this here. Doesn't run again. No did not write this. In the tensa flow scripts, we are having this file generate under SCO TS record. It is opening here, right? Yeah, it is opening here, but it's not opening in the Let me check once. The scripts me again with this ta fact test. It is not able to open that basically. So let me write again for that. Scripts. Let us run this again. Yeah, now it is opening. Okay. So basically, it's not getting okay. Again, it is not opening. Why is it so generate underscore Generate underscore TF record. Let me just see and let me just Okay, guys. So here I figured out the problem we were having. Actually, I was writing here hyphen one where it was actually hyphen L. So this was the problem we are having. We have that script correctly placed in the tens of flow scrapes and everything's cloned perfectly, but here I was writing wrong the command. So my bad. Now if we like clone this repository and I'll run this script, it will successfully going to create in this tens of flow scrape sorry, tensor flow workspace and annotation folder, it is going to create those record files. So let it be let it run. It will take some time. Basically, it will take each and every image and it will modify it in accordance with the model input requirements. So it is doing for all the first it will do it will create two separate records. One is the training record and one is the testing record. It is running. Okay, here we got an error end member four child out of range. Okay. So this is also error you can get. I'll show you what exactly it is. Let me show you here. Let us delete this record first. Let me open that script first, generate records. Yeah. Now, if we see this generate TF record script. So here it is basically accessing the fourth member here. If you will see the error, it is getting error here. So here it is basically accessing the fourth value. Now, if we see in this annotation file, this is your overall the index. This is your zeroth index. This is your first, this is your second. This is your third, and this is your four. But the bounding box is in the fifth one. So that's why it is giving error. If we change here, the fifth one, basically, some of the dataset will have the bounding box at the fourth place, some will have at the fifth place, some will have the sixth place, so you have to do according to that. That's why I've shown you because in the future also you can encounter this error. So whenever I click this save, I'll just click the save butter. I'll close the VS code down, and then let me open the workspace, the annotation. Here I read this and now let's run this script again. So when I run this script, Hopefully, it should work fine. No, again, it hasn't created the train record. Okay, it has created the train record. Yeah. Here you can see the train record is of 197 MB and 182 MB, and the test record is of 9.94 MB. So it has created successfully the both training and testing records in this directory. Now this step is done basically. Now let's move on to the next step, which is step number five. Let me convert it down to the markdown first. Now. Now we have successfully created the tensor records. Now we'll basically copy the model configuration through our training folder. Now, model configuration initially, I've told you that pipeline dot Cfig which is the whole configuration of the model, like the hyperparameters, the parameters, each and everything the model has to be input. So that model configuration, let us copy to training folder. Now, again, we'll write code for both the Linux and the windows here. Firstly, I'll write for the Linux. I will simply use the CP command, which will just copy path join. In the past, we were having the pre trained model path. You see here the pre trained model path. So from there, I'll copy. Now, after the pre trained model part, we have to write the pre trained model name. As you know, in the model directory, we have that model named folder. So yeah. And in this, I have a name called the pipeline dot Config, which I shown you earlier. I'll show you once again just wait a sec. I'll copy this whole thing to checkpoint path, the model checkpoint path. Who path ChoinPass the Checkpoint path. Now, what is this checkpoint path? It is here, the tensor flow space model and the customer model name. I'll copy this down through there. Let us do that for the Windows two first. If the OS name for window is t's ti. Now in this we'll use the command copy. Sorry, this is OS thought path. W is dot path join. Again, the rest thing will remain same. Pipeline dot conf we are copying it down to the training folder. Now what you do exactly is the pre trained firstly, what is our pre trained model path? Ittends up to workspace models and the pre trained model. Here it goes. Sorry, workspace, pre trained model. So here our pre trained model is, this is the unzipped one, and this is the configuration we are going to I'll show you what is it exactly. Now, just show you what this configuration is exactly. So here you see, these are all those hyper parameter, the weights, the regularizer, the activation function, every hyperparameter and all those configuration of the model, it is shown here. So this configuration we are going to need for our requirements and we are going to modify it according to our requirements. So just copy that. So yeah, one file is copied. Now, where have I copied this? I in the models, my SSC moment here I'll so this step is also done. Now, next step is basically, we have to modify this pipeline dot conflict according to our requirements. So this is a very important step. So firstly, again, we move on to the next step, update the configuration config file to transfer learning, right? So yeah. Now, let us import some of those libraries because we're going to need that. Let us import Object Detection ULS me input ConficUnderscore Util again, from the Objectction library. I'll import the pipeline. Let me import one more library from google dot protobuf these are the text format. These are basically the libraries which we are going to need to update the configuration below. Now, okay objection not object. It's object detection. Sorry. So yeah, all the libraries are imported. Now let me show you the config we are having currently. This is Config underscore the UTL which we have just imported. This will provide a function known as get config. Get underscore config basically from Pipeline file and what that file name files directory, which we are having in the pipeline config. So yeah, now let me show you this configuration. So yeah, here it goes. Model name is SSG, number of classes is 90. It is trained on the 90 classes. The height and width of the input image should be resized to 320 cross 320, L two regulation, the activation function, everything it is shown here. Now, this is basically your configuration of the pre trained model you are having. This is unmodified configuration. Now, let us modify this configuration according to our model. Now we'll, let us do that in the next video because already were covered four steps here. So we'll update our configuration in the next video and we'll start the training procedure in the next video. Yeah. 22. Project 4.3: Updating Configuration file Training the Model: Hello. Welcome back, guys. So in the last video, we saw how we copied the configuration file of the model and how we have created the tens of floor records, the label map, and everything which is necessary to train optic detection model. Now, we have successfully copied the pipeline dot Cf file of our FSD Mobile net. Now, as I've told you, in order to train train our model on our dataset, we have to modify it. The configuration file should be modified. Now, let's modify that configuration file and the code I'm writing like right now, you'll just have to write these all codes once in a once for a time. And then every time the objation model you want to train, you just need to run this code, and the whole procedure I'm showing you where you have to do the changes and where all you have to, you know, teach tweak some parameters. So like the rest of the time, you need just to run these codes and some minor changes you have to do. Now, let's just modify the configuration file. I'll create one pipeline underscore config variable first. In that, let me create let me use a function pipeline underscore PB two. L pipeline config. This is the function the instance we are creating config. Now let's just open this file. The TF we have already imported above re tens of flow basically. Sorry, I G file. File. In that, we are going to find this pipeline config path, basically. Files is consisting of pipeline underscore config. I'll open it as read mode only, not a write mode. Open this and read mode only because we do not want to write anything. So yeah. Now, proto SDR is equal to F not read. Let's create a variable in Proto string. Now the text format variable we have inputed now we just merge into that with that function. The proto string variable, which contains all the file data and we'll merge this with the pipeline config. So yeah. Basically, Pipeline PP is okay. So I haven't run this cell, so yeah. No, just wait for a set this cell to be run. Okay. I haven't run. Basically, I restarted the notebook, so yeah. I'll just import this object detection model too because it will create error. Yeah, it has run successfully. Now let us modify those configuration. So firstly, the pipeline config file dot model dot SSD, number of classes. Now this number of classes will be different for any of the models. Like if in our case, we only have one model because we only have the bounding box of one license plate. In some cases where we are supposed detecting cat and a dog in image. So we have two classes there. So to make it since from start, we are making our code dynamic so that it will work for any code with a minimum number of modifications we need to do in the code. So I'll just write this as this labels. And this labels, you see, it is basically if I print the length of the labels so label is not defined. Let's define this labels here. Yeah, here. So number of classes is one. So this dynamic code we are creating. Now, let's modify another pipe configuration. The bass size. The next configuration is our bass size. Now ba size, as you know, the number of batches, suppose there are a total of 100 images and the ba size you are providing as suppose four. So in each of the batches, four, four, four images will go into the model because in the GPU, we do not have much memory so that we can input all those hundred images at once. So the batch of four will go. So total 25 iteration will perform in that case, because like 25 per iteration, four images will go per batch and 125 into four will be the hundred total number of images. So let's give the bass size of four here. And the pipeline underscore. Config dot Config. Let's start that fine tuning checkpoint. I'll explain to you what is it? Sorry, fine tune. Checkpoint I'll provide the path has Sorry, sort path join here I'll pass the pre trained model path. Apart from that pre trained model part, I also need to provide that pre trained model name into that, I'll pass this checkpoint. CPT and zero. Now what exactly it is. Now, as I've told you, we are using the transfer learning here. So we are leveraging the previously trained weights. So if you will see here, the model, sorry, the fospace, the pre trained models, this checkpoint. In this checkpoint, basically, when we have downloaded this model SSD Mobile Net V two, we have this checkpoint. These are the train weights, these are the initially train weights. Now we'll start our work from here on. Like from here, already trained, already trained part, we are not going to train our model from scratch, so we are already trained still here. So we'll start our work from here. So that fine tuning checkpoint I'm creating is here. Like these are also the configuration we need to modify. Now, the next configuration I'll create is a pipeline, what do called config. Dot tin underscore, CFICt Now, the fine tuning checkpoint type. Like what exactly is this model performing? Suppose I write one type. Suppose some models are desired to do the classification and some for detection. So here we are basically detecting the license plate, so I'm providing it has a detection here. This is another type of configuration. Now we have to provide the label map and the tensor flow records we have created above the two files, so we have to provide the path for that also. That also comes into the pipeline under configuration path. This will be a train input reader because see, these are the input we have to provide. So we have to provide the configuration for that also. Map scored path. This is your Pis label map. So in the file label map, we have that path of the label map, the label map path basically. Now let's modify another configuration. Again, a input reader, the record the tensor flow record thing. We have to provide the path for that also. Input reader, the input path we're having. Now, the path I'm providing it as the OS with the OS join. And in this we have that path with the annotation path. And the annotation path, basically we have that training record as the train dot record. We have created the configuration for that also. Now, let's just do the same thing for the label map path too. We have done this for the input now for evaluation, also do the same thing. I'll just copy it from here only. Now let me change this label map the input reader to the eval input reader. Unless we provide the same and the evaluation input reader here also put path to the test thought record because here we are evaluating with the testing data, not the training data, the training data we are using to train model and the testing data we are using to test or we can say evaluate our model. Now every okay. Google, sorry, in this line number seven, input reader is, we do not have any label map Path. Pipeline dot CtenUnderscore, input Underscore reader dot label underscore Map, underscore Path. Here here is showing an error. Pipeline underscore config, evaluate, underscore input, underscore reader. Here I missed basically index I have to provide. It is correct. Index siment. So the index I miss sorry. Now we have successfully modified our path. Now let's write, let's save that modified configuration file to a folder. Now let me do that on fake underscore text. Let me create this variable. Text format dot message to string Pipeline conflict that pipeline conflict file, we just modified right now. We will pass simply here. Flood GfleGfle in that I'll just pass the files path. Pipeline underscore, config. I'll open it as a write file because we are going to write and save. I'll just save this conflict test file. We just modified right now. Pipeline under scode config is not defined, why it is so okay. Sorry. That's why I put in the single cypress Inverted codes, we have to, it has basically written those file. The pipeline config, basically, the pipeline config file path here tensor flow box space model. Pre trained models and this config file, it has successfully, changed those things we require. Now, this modification, like this updating the configuration file so that we can do the transfer learning. So we successfully completed this step. Now it's time, everything's done so far. We have downloaded the pre trained models. We have updated the configuration file for it. We have successfully installed the object detection tool. We have created the label map, the tensor flow record, which will be inputted to the model. We have also copied to the training folder now every step is done. Now like the steps to it's time to train our model. Now to train the model, we need to write a training script. I'll write a training script which will be running through the command prompt. Let us write that also thought path or join. And write it as API model path. In that, I'll just write the research that we'll go into the directory object detection. I've shown you these directory earlier also. And in that, I'll access this file model main underscore TensorFlow two dot PI. So this will be a training script. Now, let us run this and I'll just ge a command to start the training procedure. This is your Python, Kelly braces, hyphen hyphen model directory, we need to provide a model directory first. Then the pipeline underscore configuration path, the updated configuration file path basically. Now, the number of training steps. So this is important. The total number of training step you want to perform. Let us train it for 2000, let's say. You can train it for more also or you can train it for less also, but it is recommended the training step is basically you heard about the number of epochs in the deep learning, but the step is basically the epoch if the epoch is multiplied by the bass size. Like, if I divide this bass size, size of four, we are taking. So if I divide this 2000 with four, so let's train it for 500 Epox. So we are training it for 500 Epox. So let us train that 500 will be, I think, sufficient to train a model. You can train it more also like thousand or 2000 epox also, but 500 is more than enough to my belief. Now, I'll format this with the training script I have just written above. And I'll provide a checkpoint path in which the model will be saved the checkpoint underscore path that I'll provide pipeline underscore conflict. C. Now, let's print this command. So yeah. This is the command to train our model. Now, let's just copy this command from here and let's just paste this on, Okay, so here, Jupter notebook is running. Let me open another notebook. Okay, so ALPR we are having. Firstly, we have to activate our environment. The environment is activated, now we have to just paste this command here. Okay, now APR no such file ditory why is it so? In the text of APR tensa flow models, research, object detection. We are having this model here, but it is not and no such file or directory, why is it so again, I have done I might have done a mistake here. Python, model or directory. The space should not be there anywhere. Number of training steps should be 2000. Like everything seemed fine only dot format. The training save, the path, the file configuration file. Yeah, everything's looking good. Print those pass again. Nope, it is not opening model main model underscore main underscore tf dot PI. Tensorflow research model dot PI, then the model directory will come. Let us explore this territory first in this tens of directory name, the syntax is incorrect. Why is it happening? So let me see it. I'll get back to you on this. Let me see it once first. Okay, so I have figured out the error guys. The error was here, basically. This is not the object detection. This is the object sorry. This is not the objection detection. This is the object detection. So yeah, this was the error. Sorry, my bad. Like, this was the error we were making. Now let's just pace this path again here. So yeah, now what is like running? Now here you can see this is okay, so this is sometimes you can encounter the error with in the Pi Coco tools. So to encounter any of such errors, we simply need to basically Pi Coco tools, we need to install and uninstall again. Let me show you. Yeah. So this basically we need to uninstall and install it again so that it work correctly. Remember just like whenever we encounter this type of errors, you just simply need to uninstall that first, and then you need to install it again. If it is not working again, then we'll see some alternative option. But it should work, it is installing Picts. Many of the errors you can encounter, you can just copy the last line and paste it on Google or Stack overflow, then you will get those solutions from there only. Where it is installing this PIKCO tools. The other dependencies also. Sometimes, suppose there are five number of packages like A, B, C, and D, four number of packages, ABC and D, and we have installed A, B, C, and at last D. But as soon as we have installed D, it has modified some of those ABC. So again, we have to install that A one in requirements with that B, C, and D. So, this happens sometime. Again, I will run this command. So for encountering that type of error, you simply need to uninstall those packages for which are getting in which we are getting error and install it at again. Okay, so here we have another type of error in which Audi will not found typecard simply This is a procedure which we follow while encountering the error. So let's just install this type card. Yeah. Again run this command? Okay, it has started running, I guess. It is running. Yeah, it is running, I guess. Now you can check here in command prompt also because the tensor flow GPU you are using and here you can see. The whole memory, it is copied in this GPU. So that means it is running, basically. Sorry, this is the G. Yeah, just the GPU. And as soon as this compute here graph will rise up, this means the computational computation has started. So we can assume the model is already training. Till now, I can see that the GPU use is like increased that GPU memory uses. Here you can see it has successfully loaded the COD and UD basically stand for the Koda Deep Neural Network library. Now I can show you here. CUDA Deep Mural Network architect. Like this is basically a for running a tens of flow model training or train a model on GPU. We require some of the libraries. Like first of all, the basic requirements is the NVDA drivers, then we need a CUDA. Like KUDA is a set of drivers which help us to run all those training part on the GPU. And then we need CUDNN Koda deep neural network. So these are all the things we need to install and configure so that we can run the tens of flow. Like, we can train our model on basically GPU with the help of TensorFlow GPU. Now here you can see the memory usage is, like, fine, but it is not showing us any progress, yeah. So here you can see the compute zero, the computation has started, basically. It has gone up to the 98 or 97. So yeah, the computation has started. Now, I'll just wait til the hundred step, like the first step. Then it will take like some time, half an hour or more, basically 2000 Epo 500 Epox we are training. So it will take around 500 hours. Since we are training on GPU, if we are on training on CPU, it will take over night time. So yeah, this is the basically benefit of GPU because it Excels, the training time, it decreases the training time but not of margin. So we are training on GPU, and let's just wait for the first Epoch. The first like 100 steps it will show the output. So first 25 Epoch will show us the result. Then you can just have a cup of coffee till then and, like, we'll get back after the training part is done. Let us wait for the first EPOC to complete. The first not exactly first EPOC, the hundred training steps. It will show us all those values for the hundred training steps. Let us wait for that. Till then I'll just go through what we have done until now. We have basically set up we have set up all those paths I'm just reviewing all those things we have done till then, our first EPOC training will complete. So yeah. Firstly, we have set up all those bass in which we are creating folders. Like, these are things we can keep it on a same folder or same directory, but it will be a lot more messy as you can see, there are so many folders and files we are dealing with. So it will be a very mess up thing and we do not need to do that. So that separate separate folders like we have created. And then we have created every code for both the windows and the like Linux. So the T means the windows and the postfix means the Linux. So we have created all those. And again, in the next step, we have downloaded all those pre trained models from here, the tens of flow models repository. We basically cloned that repository, and we have installed the tens of low object detection. Here. And for the objectation, we need that protocol buffer protocol buffer compiler. So we have done that. And then we have run a verification strip to verify everything. And as soon as we see a message here like Rand 24 test, we can be sure that everything's running fine. Then we have imported the obsitation and then here, we have downloaded the pretend model we want to use. Like the model name we have defined here, MSR Mobit and we have given the URL from where it has to download, and then here simply downloading. Then we have created a label map, like the number of labels we are having in this dataset. Then we have created a tens of four records, like the record that record script, I have cloned from my Github repository. You can clone it from here only, and also you can clone it from the official object detection repository. Then we have created a transfer for records because the model will take input in this format only, and we have copied the model configuration file to training folder, and then we have updated those configuration files so that we can perform transfer learning. And all those configuration, what we have to modify, why we are modifying it, I have shown you here, and then we are just starting this ring this we can delete. So, yeah, we have started cleaning. I hope one epoch is completed. Oh, so here you can see, two epochs are completed, like 200 steps are completed. So here you can see in the first step, we are getting the classification loss as 0.23, and in the second step, the loss is decreasing. So this is the goal of neural network. The loss should decrease every time. And in the one step it is taking time as 1 second. So basically in 100 steps, it will take time as 100 seconds, roughly. And in the 2000, it will take the 2,000 seconds, roughly. So after like if I can say the rough estimate time if we divide 2000 by 60, we'll get somewhere around 33 minutes. So after half an hour, our complete training will be completed. So yeah, let's just wait for our model to train. Then in the next video, we'll see how to use this model to detect the license plate from an image, and also we'll see how to evaluate this model. So yeah. 23. Project 4.4: Evaluating model Detecting License Plate trained model: Hello. Welcome back, guys. So here you can see the training is completed, and we have successfully trained our model until 200 steps, which means like 500 epochs and you've seen initially it was taking a time of 1 second, but later is it took only 84, like 0.84 seconds per step only. And the loss is like we have started from a loss value of, I guess 0.23, then it increased somehow to 0.44. And in the end, we are getting it as 0.77. So loss is decreasing. And somewhere in the middle, it is basically fluctuating a little bit, but yeah, the final loss we consider. So this loss is decreasing and the model is successfully trained. Now, if we want to see the model we have trained, we can go here. And so, yeah, here you can see. These are the three checkpoints we have created like PKPT one B which was, I guess, created at the starting of the training. And the CKP two, it might have created at around the end of the thousand steps, and this is the final model we have gotten at the end of 2000 depo 2000 steps, sorry. So yeah, this model we want to use for future use. But before showing you how to train that model from that checkpoint, let us, evaluate our model first because this is also a very important step in deep learning. After training, we have to evaluate our model. And for that, I'll just write. This was your step six, and this was your step seven, basically. So let us write that too. That was step seven. So yeah. Now, other part of step six, step eight, sorry, we'll be evaluating our model. The model. Now, the command will more or less same as here, the minor corrections, minor changes we have. This command, Python model DIR pipeline conflict path, but this time we are not going to train it for the thousand depot. Instead, we are just providing the checkpoint path, checkpoint directory, basically, Checkpoint directory. And then we'll format the training script, the pass, the checkpoint pass, the five checkpoint path. Sorry, in this. The path, the checkpoint path, the five pipeline config and the path of the checkpoint path. Basically, it will also provide one checkpoint path here. I'll write it down as checkpoint path because at the checkpoint path, we have our saved model, which we have trained just now. So that, let us print that command. So yeah. This is your basically command to evaluate your model. Now let us print that on the command prompt. No. Yeah. This is your command to evaluate your model, let us evaluate first. Let us see what happens when we evaluate a model. So, you can see here it is evaluating the model. It is loading the model first and then it will evaluate the model on that test dot record basically, that testing set we have created and we have created that record for the testing set. Let us wait for some time then till it. These are some of the warnings. Don't get like if you ever get any warnings, basically, the tensor fluid publish one version of the function, and after some time, it creates another function for that. And that function is basically deprecated. The initial function we deprecated. So yeah, these were the warnings. So yeah, here you can see the model has evaluated, and these are all the evaluation results average precision, every every recall, everything it has printed, the mean accuracy precision, the mean accuracy pression it sent 50 IOU that is in texter intersection over union, I guess. So yeah, all those results, basically, it has shown here. The total loss was this, the localization loss was 0.23, et cetera, overall result. So let us stop that. So this was your evaluation of the model. Now let us load our trained model from the checkpoint. This is a very important part because then only we can use our model. So let us load our model. Let me wide this as step nine, loading the trained model from Checkpoint. Now, let us import some of the libraries first because after that after training, why I'm importing OS again because after training, once the training is performed, you only have to run all the cells or you only have to work from here only. So let us import all those important libraries first. The flow ATF. Then from object again, I'm writing it. Check Detection dot Utilities Utils Import report label map, Util. Then again, from object detection, these utils. We need to import the visualization utils. Us as U because this is a very long name, so we shorten it down. Now from again the object detection. Builders we have to import the model builder, which will basically build our train model. Again, from the object detection eotils, we have to import the config underscore util, which will load our configuration file. No module name, object detection. Line number four. Number three, basically. Everything is correct and it is showing an error. It is opening here, but it is not detecting here, why is it so misspelling it? That error was gone, but again, it is putting an error in the object detection. School builders. Visualization underscore utils us. Model builders, we are having object detection. Okay, this is not underscore sorry My bad. Yeah, that is all imported. Now, let us load the pipeline configuration first and to build a detection model Config under schoe Util Get configuration. Get confix from Pipeline. And in that we'll pass that pipeline configuration file, the path we have created earlier. Then in the detection model, we create a variable name breadth in which we'll load our model builder which will basically build the model model underscore config fake model. And we'll set is training as false because we have already trained our model. We just need to load that. So we'll set it as false. Okay. Uh, underscore, tell lot get underscore, confixF spelling, I've misspelled here. It has successfully loaded. Now let's restore the checkpoint, CKPT compare Voson two because that is deprecated train. Checkpoint model equals to detection model because initially we set it as detection only. Now, CKPtRtore I set the path here. That checkpoint path we have set earlier. Then the KPT here we have to put the name the latest model we put CKPT three we put. The partial has loaded the model successfully. Now I'll write a function, just a tensor flow function. In which I'll create action detect function basically, which will take an image and it will output the value. I'll pass the detection model I loaded earlier. It will preprocess the image and set it according to the model input requirements. Then it will predict a dictionary. I'll I'll use my detection model in which I'll detection model to predict basically, in which I'll pass my image and the shapes then the detections I'll get from here, use my detection detection model to post process the dictionary we are getting and we'll pass the dictionary and the shapes. By this, you will basically get the detection. This is the function for using our trained model. So yeah, I do that. Now, everything's done. We have success loaded the model. We have written a function which will take image other input and it will return the output detection. Now let us try this. Let us detect from an image. Then then you'll see everything's in working, then you'll get okay. So here how we are detecting this with the help of train model. So let us do that. Step number ten, basically. In which in which I'll write detect license plate. Okay, so firstly, I'll import CV two. This is basically computer vision library, OpenCV library, basically, which contains all those OpenCV functions we are having. Now let's import NumPi for all those mathematical calculations. MD plot, lip Import. This is basically I have imported to plot the picture. Basically show the picture. MD plot, lip in line this we need to do in the Jupiter notebook. Now, firstly, I'll create one variable named as category in text. Category I misspelled it category index from label map, which I'll pass my path to the label map we have generated earlier. Okay. Let me see. Catarina, Labor, Util category spellings. Now, let us give an image path, basically. This is your label path, label the category index we are having and now let us give an image path. For that, we already have the path for the image directory, let us put let us pick the image from there only. Path Image path. Cars four and two. Let us give an image. In the image path, basically, we'll be going till here. So let us put some images from the test folder. Let us put these three images here, and firstly, we'll predict on this car. This model hasn't trained, so let's detect this. Let's see if the model can detect this image. Its name is cars 411 dot PNG. So, yeah, let us write a code to detect all those and basically, we'll detect our bonding box in this code and also we'll plot those bonding box into that image only. Then you'll see the results in the real time. So firstly, I'll read the image. In the computer vision, we have function named IMRaD, which is used to read the image. Here I'll simply provide the image path Okay. So here only, I'll write the image. Basically, as I said earlier in the neural network, it will not understand any image or any video or any audio. It will only understand the numeric value. So we'll convert this whole image into NumPi array into a three cross three matrix basically in the machine learning or deep learning, we represent the image as three cross three matrix. So we'll convert that, then we'll create a variable name input tensor. In this we are converting our image to the tensor. Basically the model in which the model will take the input. Also we expand the dimensions here. Dims the image we will pass the type float value. Now here we'll get the detections by passing it through the detection function we have created earlier. I'll simply pass the input tensor here. Now we have gotten the detection. Now let's get the number of detections we are having in our separate variable in which this is detections. I'll remove, I'll pop the values of num detection. By this we'll get the number of detections. Now, I'll get the detection values as the dictionary. The key I'll provide as the value since all we have to consider the num detection. I'll convert this to the numPi format and then I'll create for key value. I'll create a loop init item. Basically, we are accessing the auditionary, and then I'll create one num detections is through the num detections. It will give all the detections we are having and then the detection classes should be the integer variable. Let us convert that first. The detection classes in which we'll be having the detection classes name. I'll set this type as pi int 64 bit. So, this will set. Then I'll create one label ID, which we have defined earlier only as one because since we have only one lever ID here I'll create one more, we're able to copy this original image and then we'll mask the detected image into over it. You will see when we actually run this code. Yeah, so here it is now, let us use that visualization library, which we have inputed earlier to basically visualize the bounding boxes. The bounding box, the detection in the dectionn In this, we have gotten all the boundary boxes coordinates, but let us plot that then you will see what the model has actually done. So let us get the bounding boxes and labels mag A here. Firstly, I'll write the image pi with detection. Then the detections in that, I'll get my detection boxes. Then we need to get that detection classes. Plus the label the label ID that one we have created earlier. Then we need our detection scores. We also want to print that detection score so that you can get how much confident our model when it is detecting those boundary boxes. How much confident that probability will see. Then I'll pass one category index that we have created earlier. Then we'll normalize the coordinates basically coordinates. Then the maximum okay, now the maximum number of boxes we need to draw. So in a picture, let me write it down first. So in a picture, there can be multiple number of bounding multiple number of detections. Like, suppose in an image, we have total of five cars. So in those five cars, basically, there will be like five number of license plates. So this is basically that how many maximum number of boxes you have to draw. Now, how it will decide, suppose in a picture, there will be six license plates. And in that I'm passing that maximum number of boxes to draw is only five. So how it will decide those five boxes out of six. It will only draw five because we are inputting that parameter here, but how it will decide. So basically, here, the scores will come into picture, or let me write it down first, then we will understand more clearly. Minimum score threshold. Let me set it as 0.7. Uh let me 0.7. So yeah. So minimum score threshold, if a model is detecting some plate with a confidence of let's say 60%. The model is confident about 60%, it is that I have done the prediction correctly. So the model is confident about 60% because as we know, neeal network will give a probabilistic output. So the model is 60% sure. And suppose another model, say model is sure for another license plate, it is like 70% sure already. So out of top five top five from those six detections, it will consider. Now I'll pass one more thing agnostic or equals false. You'll see everything when I'll just run this now PLD IM shot, color, then image and P with detections and as we know, in the CVT, we have to convert those image again to the RGB channel because PCV library any of the image in the RGB format, like the gray scale format, so we need to convert that again. Now Androidt dot. Sure, us connect. Okay. Now it is giving an error here in this detection function. What is writing as shapes is not defined. Where is this shapes? Oh. Let us see here first, the configuration file we have defined, the CCPD we have defined the image and shape, we are already given here. Okay, so here we are giving shape, not shape. Sorry for that. Again, if we run here, it is running on this image car 411. It's basically running that model on that image. This is our image. Let us see if the model can detect or not. Okay, so we have a runtime error here. It is seeing that phon label on image array is getting a non correct input use normalized. Okay. Sorry for that. Okay, normalized. Minimum score threshold spelling. Correct. Okay. So here you can see the license plate is correctly detecting on this image. The model is performing right and it is detecting it with a confidence score of 76%. Like the model is 76% sure that this plate it has dt is a license plate. So like, you must be worrying that why it is showing only 76%. Why it is not showing 100%? Because we have trained the model for five mini depos. Let's just train it when you train it for more number of depos, 2000, then obviously the model will be more sure. Like it will be a more sure. I can say with a more surety, like, Yeah, this is a license plate only. So, yep, that is the thing. And let us try it for one more image, this 41, two, let us try this, let us try for this image. Okay, so here it is not displaying, let us decrease that threshold value. So yeah, when we decrease that threshold value, see, here it is detecting this plate because the model is only 66% sure. Let us try it for the 41 fifth image also. Yeah, the model is correctly detected this plate. It is 73% sure that the detected plate is of license plate only. So yeah, this is the key. Now let me show you one more thing. Detection dot keys because detection is a dictionary. So yeah, these are your keys, basically the deicton boxes we are getting the scores we are getting, the classes we are getting classes, that means license, raw detection boxes, all of these things we are getting in this detection by the help of the model. So yeah. Till then, till here, we have seen we have trained our model, we have successfully saved our model. We have loaded our model from the checkpoint. From now only we have to run ourself from the step nine, and we have detected the license spread from different images in our testing set. Now, out of this detected image, we have to extract those numbers because our project was not only detection of the places like plates. We have to extract the license number out of those plates. So yeah, that we'll see in the next video. See, this is basically how we perform the object detection. Now, in future, any object detection task you have to perform, you just need to run these like ten steps and then we'll be ready. Like, you have your data get your dataset ready, get this notebook ready, and then you'll be ready with your object detection model and you can detect these only. So yeah, in the next video, we'll see how to apply the OCR and which OCR library we are using, which OCR we are using. There are many OCRs available. So yeah, all these things, let's see in the next video, and then also we'll save all those results after applying OCR, we'll save all those results in a separate territory also. Let us see all this in next video. 24. Project 4.5: Applying OCR Detected Plates filtering Saving Results: Hello. Welcome back, guys. So till now, as you have seen, we have successfully detected the license plate from an image, and we like till now, we know how to train a model, how to load a model from its checkpoint, how to save a model, that CKPT file, like how to install and complete, setting up the whole tens of low object detection, how to download those pre trained models and leverage those pre trained weights, like that transfer learning concept, all these things we know. Now we have successfully detected the license plate from an car. But what about what after the detection? So after detection, we urge if someone is providing you the task of detecting a license plate, it will be much more, good to give him, complete license number. Like, after you have detected the plates, like, you can apply the OCR, the optical character recognition to this license plate and detect this number like MH one, two, and, as you can see. Now, first of all, what is an OCR? So you'll Google it. This is basically using a lot like industry is using a lot of things. Basically, any image with a text. So after applying the OCR, it will convert it into text format. Like, suppose am I giving this suppose, let me open this here. Suppose I'm giving a model this cropped image like this many image only. So after applying OCR, I'll be getting VIPER as an output. So this is what OCR does. It will convert an image into the string format. I suppose I'll apply this OCR like this image to OCR, then it will detect this OPT ICL character recognition. So this is what OCR does. Now there are many trained, obviously, the OCRs are trained models, so we have many train models. So first of all, we have a very famous Google Tesseract Pi Tesseract engine we know. This is an open source like OCR engine, which is being developed by Google. So this is one of the most famous OCR engine we know Tessat. Another one is EZ OCR. So this is basically the EZ OCR is developed by the PyTorch community, and the Pytoch is developed by basically the Facebook. So this is under maintenance under Facebook. So yeah, this is another one popular type of OCR EZ OCR. Another one is Kara OCR. This is also a very good OCR. These are all very famous OCR engines. Now in this video, we'll be going to use the EZOCRw why we are using the ECOsR Because in Tesseract Tesseract, we have one problem. Like, suppose this is your image. So the Tesseract engine, let me open an image in a new browser. Yeah. So in Tesseract it will detecting it will be detecting those letters or those strings from the left to right. Like, suppose it will start from here, like P, it got A, it got SSP PRT. And then if the next letter it is getting traffic T, then it is going to detect that. But suppose let's say this traffic is a little bit lower and after that, there is nothing text. So it will just simply skip this traffic sign. So EVOCATason does not perform like this. It it performs like the bottom down approach, top to bottom approach. Like, it will detect from here. So it will encounter the passport, also, I will encounter the traffic also. It will encounter this sign also. So it will cover basically each and every text. You can apply different you can apply these OCR into different images, then you'll get some outputs. And based on that, you can decide wherever I should use EzoCR or I should use Tesseract even you can use. Like, Tesset is a little faster. EZOCR is a little slower, but the accuracy of EzoCR is like a little bit of higher than the Pitserat. So all these comparison based on that, you can use. For the PDS, generally, we say like Tessera for the PDS, EZOCR work good for some handwritten character recognition, the Google test write work better. So yeah, everything every OZR pros and cons, you have to decide which OCR you are going to use. So in this video, I'll show you the example of EZOCR how to apply the OCR to the detected plate first. And then, in future, you can change the OCR engines and you can experiment with that. So let us start with the OCR work. I'll name it as apply OCR to the detected plates. Now, firstly, we'll need this EZ OCR library. So I'll install this EZ OCR. It will take some time because the EVOCR is a big library. It is basically under maintained. Let me show you this Spy Doch. So yeah. This is basically the framework, as in this video, we are using tens of flow. Everywhere you will see tens of flow. But the Pytoch is also a framework to implement those deep pluning functions. And in that Pitoch we have that EZ OCR. So it is under Pytoch only. And the Pytoch is developed by the Facebook community. So yeah. Like as the tens of flow is being under maintenaned by Google, so the Facebook is the Pytoch. So yeah, let us install Esos until then we'll move proceed further. We'll define first the detection threshold as we have defined in above here, you see. So detection threshold, I set it as 0.6. Now, I'll apply those. I'll create those detection classes first. Image equal image and P with detection. Okay, so I guess if you said installed or not because it is showing an error. Let us check that on command prompt list I'll do. So EZ OCR. No, it is not yet installed. Let us install it again. Click the EzoCR it is installing everything. So here you can see it is also apart from EzosR is also installing the torch vision because I guess this is necessary requirement for that. So it is installing that EOCR image NP with detections. After that, we'll make a score array of different scores we are getting. I'll create a list of that. So yeah, here you can see the EOCR is installed. Now I installed, let's import the EZOCR here. It is imported. Imputing the UCR. Now, we'll filter out with a Lambda function. Now what is Lambda function? Like Lambda function is anything in the whole iteration, we have to perform this sllmall operation for that, we use the Lambda function. Now, what Lambda function we are going to use here we basically pick those X values which is greater than this detection threshold value. Basically, if some detection has a threshold value of let's say 0.2, then we are not going to consider that. You're only considering the threshold value which is greater than 0.6. So for that, if we are creating a list of that, then we need that lambda function here. So I write threshold detection threshold in that I'll pass the detections array, and from that, I'll pick the detection scores. Yeah. Yeah. Now, let's get the boxes. And detections in that we are having detection boxes. How much we want, we'll just do the length of the scores we are having. Basically, the number of detections is equal to the number of scores we are having because already we have applied the line of function. Now let's get the classes here. Again, we'll apply detections. Detection underscore classes. And again, we'll see the number of scores, length of the scores. I'll apply this. Now let's see the detections. Deduction classes is not defined. Why is it so Should I run these steps again? Detection classes, I do not show. If we see here the classes. I'll see here the boxes. So, it is showing it currently, but in the detections, sorry. I forgot to put it in the inverted codes. Here you see. These are the number of number of all those detections we are having zero, zero, zero, zero, 00 values because the label ID is zero here. If we want to find the bits of the image, let's find it here. The first value will be the width and height and the second value will be the width. The height is image, the first value, basically. Let me show you here. So, width of the image provided is 400 and the height is 300, we can see that also. Now we'll provide the ROI filtering and the OCR, we'll apply the OCR into data detection box. For that, I'll write IDX. Box. We'll iterate through all those detected boxes we got from here. These are all those boxes, so we'll iterate from there. I'll just print one box first. So let's see. This one box only we got, so we'll print those. This is basically, as you can see here, here we are normalizing those coordinates. So we are getting those four coordinates, but in a normalized form, if we plot here, it will not get us the correct value. So let us like multiply it with the height, width we have salted here so that it will give us the correct boxes value. Let us do it again here. I'll just simply multiply those boxes with the height, width, again, height and again width. And now, if I print those boxes, here you can see, these are the actual coordinates. These are the actual coordinates of this image. So it is giving us the correct output. Now let's calculate the region. In that image, I'll pass those in teaser value of these ROIs. These all four RIs we have got the final coordinates we have gotten. I'll pass this RI value zero. This will be the first region first coordinates. From here, I'll get to the region of second. Teacher RI. And this will get this will zero to two. Basically, it happened like zero, one, two, three. So zero to two we are getting and two to three, we are getting. So 02, we are getting 123 we are getting. So yeah, let's right here one and in ROI of three, that's correct. Let's apply EzoCR here. Now to apply EzoCR here, we'll write this car dot reader and select in this, we have to pass the language, so we're passing the English language here. Now OCR result. This is the OCR instance we have cited here. Now let's apply the the reader object, the OCR object and apply this function we text to the region we have calratd above. Like the region means that the bounding box, like the box we are having. Let's print these OCR results. Yeah? Let me bring this. So yeah, this is detected MH one set N E, this was detected and this was detection confidence. These are the bounding boxes we are getting. So everything we are getting. So this is basically what we need redetection. Now here you can see COD or not every word defaulting to CPU. Basically, EZ OCR works on both of the platform. I will work on CPU also it will work on GPU. Now you might be thinking like, how we can perform those OCR activities with the GPU. So here, I'll show you in short. So yeah. This Pitch, basically when you are installing, right, this Pitch, you can install the stable verson for Windows with the help of PIP for Python, with the help of Coda, you can install any other Coda, 10.2 also 11.3 also or CPU also. So if you install with this Coda, you have to copy this command not this PIP three, three, for Linux also, you like PIP install this, this, this. So when you install this, you will have your Coda activated for your Pitch. So when you run the EV Osia, then it will automatically be running through your GPU. So yeah, if you want more speed, you can do that. Now, we have successfully printed the OCR results. Let's show the results. Let's show those bounding boxes over me detected image also. That cropped image I'll show you. Color region, cbt dot we are converting that image to the RGB channel. Let's run this again. It will, I guess, here it is showing MH one by mistakly it has interpreted as Z, but is two, but never mind. I creating prating correctly only. So, sometimes it can make some mistakes, but yeah, like another image if you want to try, let's try this for this image, car 176. Car 176. Where was it? Yeah. Detected the license plate now when we are here again. The coordinates we have gotten now applying the FOC here. Okay, so there is one more problem. I'll explain to you what it is. So yeah, there is one more thing we are getting here. Le suppose this is your image, Let's see. Firstly, I'll get back to you on this, firstly, let's complete sorry. Let's complete that right. Just wait for sec. I'll basically print all those, all those length and this OCA results for now so that you can get a clear idea. You subtract it from zero and two. Zero and one. I'll just print, I'll also print this result. So yeah. Now, this was what I was telling you. Like in this OCR, suppose let's try another image once, then you'll understand try for car 411. When I detect it for car 41, one, then here you can see. Like it is detecting it is correctly detecting this viper. But when I ran this for this car 176, here you can see, car 176. When I ran this for this. Basically, what it is doing is, it is outputting me all those values. Like only this value I need EVO nine FTW, but we do not need this values, like these all values. So how to do that. Let's just filter, let's apply some filtering with the help of filtering. What we'll do is that in this particular image, the multiple bounding box are generated. Like this was the one bounding ball, this is the one bounding ball, this is the one bounding ball, this is the one bounding box. So what we can do is we can apply some filtering suppose this is one bounding box and this is one bounding box. So we'll apply filtering in such a way, we already know the coordinates, and after that, we know the coordinates of those basically the initial step was detecting this license plate. And the model has detected this as the license plate here you can see, model has detected this. And when you apply the EZ Osia here, so it will again detect some of the bounding boxes. Like it has already trained. So wherever it will find a text, it it is going to detect the bounding boxes. So what we'll do is this bounding box has an area, we can calibrate this area because we already know the coordinates, and also we can calvate the area. Now, we'll apply the filtering in such a way that if the area is less or shorter than the bigger area, then we'll just ignore that. So by the help of this, we can ignore some of those extradited numbers. We'll only be focusing on this EVO nine FTW. So let's see how to apply that. I guess you have gotten the concept. Now let's apply the OCR filtering here. So first, I'll define region threshold, the threshold value we going to set. Now, let's just write a function to filter the text. Now, here, I'll print here you can see OCT California, like EVO nine, everything is going to printed. So after that, if only this EVO we need. So when we write this function here, see our result. Threshold is all the parameters we are going to pass in this function. Now the rectangle size, we calculate first. With the help of the regent or shape we are already having we'll multiply this with another coordinate. One. Now I'll initialize one array and I'll loop it through the result and the OCR results. In the OCR results, we are having many rectangles, so we'll calibrate each of those area. Firstly, I'll calculate the length because the area rectangle is length into bits, like to height. I'll calculate each of those parameter first. Result. Okay. It's a zero, zero, and for height also will do the same, but for 02 and 01. We have our length and heights length, now we are writing those functions. If the area is basically via will divide with the rectangle size is greater than the region threshold we are passing here. Region threshold will upend that plate. Append return the plate. Now, what it is doing exactly? So in this, we are having the area this complete plate, basically, this area, then this area, then this area. So what we are doing is we are dividing this area by this area. And if it is greater than the threshold, then we are apending that plate. We are considering that plate. Like, suppose if we apply this area OCT, it is very small. So as the numerator will go small, the denominator is same. The denomeor is bigger area. So as the numerator will go small, it will the value overall will decreased by 0.05. That value we can take with our choice also. So let's see the result with that first. I'll apply this function filter text to our region, we have Albuted above to our result we already know and the region threshold, I'll just pass here. When I apply this here, I'll get on the road as C output. Okay. If I like here you can see it has filtered out all those things. If I now apply this function as this, yeah, it is not detecting anything, 0.1, then in detecting 0.01, again detecting. So yeah, 0.0 sure. So with the help of that, we are eliminating all those things. Now, let's if we could find another image. For this image, we can test car six basically. Let us see first of all, it is detecting the plate or not. So yeah, it is detecting the plate. Now let's apply the EOCR here and let's see the results first. It has detected the e20 11n, it has L, but never mind, then the virginia and everything. But we only need this. Let's apply the OCR filtering here, it is not detecting anything. Let's decrease this threshold value first. If I decrease that threshold value, it is going to detect something. I decrease it further. So, we can keep this threshold at 0.5 only, I will work for the most of it will not work for some cases. So yeah, here we are getting this virginia and this 802 ion. So this way, we can experiment with the filtering part, and then we can get the desired output. Now, let's bring it all together. Like both the things we have written above, the ROI filtering and everything. Let's bring it all together. We'll create one function together for that. Threshold. So in this first I'll convert it to the markdown, combined code write. Now, let's copy this region threshold here. Let's write a function or CR in which I'll pass the image, the detections, the detection thresholds. The region threshold. Then I'll calculate for C scores we have already done here. I'll just copy from here all the three things basically. So let me correct it indentation. This is your function created for that. Firstly, I'm like we are applying the Lambda function, the detections we are getting here and the boxes and the classes. So yeah. Now let's get the image dimensions. We have already done those things here. Simply, let me simply copy those. Image dimension we are getting from here. The width and the height. Now we'll apply the RI filtering. So, we have done here. This again, indentation is wrong, correct it. There's no need to print again and again, it was just edit to show you now 022, one, two, three, it is all correct. Now Easy OCR, we are applying. We are getting OCR results and we do not need we need not to print the results again and again. Then we create a text basically by applying. Then we apply the OCR filtering here after getting the OCR results. I create one new variable. Then after applying the OOCR we'll show this image and I'll write plt dot show here. I also print this text the final text, the OCR, basically, and this is a function, so we'll return this text and region. Okay, so here it is getting an error. Why is getting an error here. Boxes with. The indentation is right only why it is showing an error. Where it is getting an input. It's not showing the correct error to the input. Mode. The indentation is correct, I guess. Then why it is showing this error. Everything we have just here. Red boxes. Everything seems to be correct only then I don't know why it is showing this error. Define first line is cting error. Okay, here by mistake, I put. Okay. Yeah. This was the error. Basically, I put an inverted comma here. That was the error. My bad. Now, let's use this function. We need the text and the region, basically. We'll pass the NP with detections. And pass the detection, then the detection threshold. Then I'll pass the region threshold. Yeah. So it is running all those. Firstly, it is getting the score, I run. Now let us do it for another image. Let's say this car 411. Like this. That decreases station threshold by somehow. That's why it was undetecting. It is detecting the 07 here. It is right for another image. Car 412 cars 41, two, basically the same error. 07. Let's see that here. This is not here we are getting correct r33 TE 0.6 here. Yeah, here we go. Now we are getting correct. So this is the combined. Now, let's save those results in a CSV file. Like, we are passing car image and we are getting, like the output as the OCR. Now let's save our results. This are the final steps. Let's save the results. We'll create a CSV file, and I'll import the UID. Now, the random JPG files we are going to create, which will save the detected or we can see the cropped plates. I'll use this library to create the random random generated IDs, unique IDs, basically. Oh, sorry, this was my bad. So yeah, this is every time you see a unique ID here. So if this is not going to use anywhere like Herogancy every time it is changing, Now, let's write a function to save the results. In this, I'll pass the text we are getting the region, the CSV file name, what we are passing the folder path where we'll save the detected plates or we can see the crop plates. Basically, we'll pass a car image, and then the detected plate will be just saved here, not the whole car image. Because that only we need. So I'll pass for Cmagename. I'll format this with this same thing I'll copy from here only. Now, I'll write those image with the help of OpenCV. I'll pass the folder path, the image name, the region, the region. And with the help of now I'll just open one CSV file so that we can save there. With the mode of right. And after saving everything, we'll create a new line. Fair. Now we'll use this CSV writer. CSV writer and this will pass this open the created CSV file, Delimiter so that it will separate all those entries. Code character. Now, the coating will be the CSV package underscore, underscore minimal. So these are all the things we need to do that too in order to save those fives. Now we'll write row by row, not by column by column, so I'll write the row function. In that, I'll pass the image name first and then the text. Basically the image name and the OCR dected file according, corresponding to that. Also, when I see this region, here you can see this is the region, basically the three by three image metric. Now, I'll just save the results. Let's see if results, I'll pass text the regioni results dot CSV. This is the CSV name I'm creating. And this is the folder detection images. Let's create that. Let's wait for a second. Okay. Here it is coding. Let's tell it there for now. Now, where it is getting an error. Also, let's create that folder for us otherwise will give an error. This detection results creating, but let's create that detection images folder in which the images will be saved the cropped images, the plates, basically. Here, everything is, I guess, fine, file name, mode, A, new line. Writer in the CSV writer, we are the CSV writer we are using. We are passing the five, the deminor, code character, code character, and pass this and the coding CSV, this is also wrong. The code minimal CSV writer wig name text, it should work fine. Again, it is. Let's write this CSV write. CSV writer is not defined, it is telling. CSV write I don't know why it is getting an error here. This is basically creating there. So you have error you can see it is saving those images. It is also creating that CSV file. But I guess it is not saving anything because it is getting an error here. CSV right we are getting I any libraries, no. Libraries, we have imported CF Here we are writing the image baria CSV file name. Let's create that file first. It is already created. Field dot code minimal. This line we are getting error. I'll write it for only way. Okay. Let me see once I'll get back to you on this. I'll fix this and come to you. Say I have fixed this error, and now it is gone, it is running successfully. This was a minor error. Now, whenever we just pass this image and we'll run this basically, this image we are passing here, the car image we are passing here, and out of this car image, it will automatically detect this license plate. It will save in this detection image. Here you can see this is the detected license plate here, and it will also generate one CSV and it will save this is your image name, the unique image ID, and this is your detection. So this is your let's try for one more image. Let's write for this per image, 41 or image, this car 415, cast four. Cars 415. So yeah, this is detecting correctly. Now let's apply this combined OCR to it. Let's see if we are getting the correct result. Okay. We'll have to run from here. Let's run this first. So we are getting the correct result here. Okay, sorry, let me first, you're getting the correct result. Then let's see this results as saved. And when we go to the detection images, here you can see this image is saved. And when we go to the CSV file, here you see the image unique image ID correspond to that they detected the OCR output. So by this, we come do this project. Overall, we have learned how to train tensor flow object detection model, how to use the transfer learning how to use those pre trained models to create your own custom object detection model. And this whole dynamic code we have created in which you need for now from now, you just need to run those cells. I suppose I'm changing the data set, you need to do some minor tweaks here and there, and then you'll be ready with your obj deton model. So we learned how to train the model and we learn also how to load the model from checkpoint. Not every time you need to know, every time you need to learn train those models again and again. And we have also applied the OCR to the plates. We have also applied the filtering where somewhere we are neglecting those small small regions, we have combined those codes. We have also saved those lists in a directory, those detected plates in a separate directory and those CSV file, we are getting the OCR. After string, we are saving basically the lisse number. The end result we want to like it. So with this, we came end to this project. These are the very many real world applications in the highways or in the real world. It is using in daily basis. So yeah, this is a very real time application of the deep learning of the oxide detection. So thank you so much, guys. With this, we came end to this video. Yeah, thank you. 25. Project 5: Covid 19 Detection using Neural Networks: Hi, guys. My name is Goros. I have six years of experience in the field of artificial intelligence, machine learning, and deep learning. So today in collaboration with Adiversity, I have brought two real time projects as a part of your internship, which is being practiced in the industry in this real time. Since you have covered basics to intermediate levels in the industrial training program, I'll be taking you to the next level by building to real time projects. In this first project, we are basically detecting COVID 19 using convolutional neural networks. So you can see it at the COVID 19 detection through deep learning techniques, and we'll be building a web app in this. And let me show you the overall pathway of this series of lectures. So firstly, I'll be briefing you through the deep learning in biomedical imaging. Then we'll be going through the dataset we are going to use in this model training of COVID 19. Then I'll be giving you some brief overview of transfer learning data augmentation techniques. And then we are basically modeling our overall dataset into COVID 19 model. And then we'll be doing some predictions to test our model in real time, and then we'll be creating a web app. In this Webb, basically, there will be one front end, HTML, CSS and JavaScript and the overall R model, the train model. So how we have to connect those front end pages with the model that we'll be doing with the backend server known as FAS. And then we'll be integrating our overall model with the Webb and how we are going to do this. I'm going to show you in this series of lectures. And in the end, we'll be building something like this. This is basically the overall design of our webpage. This is basically COVID 19 detector I have named like this. And in this when you choose an image, suppose I'm choosing this COVID 19 infected, this is basically COVID 19 infected image. And when I choose this and I'll say predict. So here you can see the result the model is outputting is person is affected by COVID 90. And when I choose any normal image, this is normal image. This is not infected by any disease. So when I click predate on that, it is showing result is normal. So we are going to build this thing in our series of lectures. Again, you can see when I select COVID 19 infected image, when I click Predit it is showing person is affected by COVID 19. So firstly, the first thing, we are going to see the dataset. Wait a sec. So yeah, here we can see. This is basically COVID 19 x dataset we are going to use in this program. Here you can see the training validation and testing set. It has already been divided into these three sets. Firstly, the training set. This set is basically used to train our overall model the initial weights are updated with this training set, and there's something called a validation set. After each iteration of training, after or you can say after each EPOO, the model is validated if everything is going fine as expected or the validation, basically, we validate our model after each iteration to ensure the loss function is decreasing, and the training part is done successfully. And there's something called a final testing set. So this testing set is something which through that, we validate our final model. Like, initially, we train our model, we validate our model, and then in the final stage, we test our model in the real world data set, which the model has never seen before. Like in each basically training set, the model is seeing the data every time. In each validation set, after each epoch, we are validating our model with that data set. And in the final testing set, we are just testing our oral model. So this is basically the overall data set. And here you can see these are the normal images, which is not being infected by COVID 19, uh here you can see, yeah. So here are some normal images sample in our training directory, and these are basically COVID 19 infected images. So we have to train our model so that it can classify between the COVID 19 and normal images. So the overall path of this video, there are so many concepts related to it. So if you are like since you have covered the basics of your machine learning, but if there is some concepts which is missed in the previous video lectures. So I'll be briefing you with that also. And side by side, we'll code and we'll see the progress of our whole project. And if there's any new concept, I'll explain you side by side. Overall, we'll be using Jupiter Notebook to basically create or train our model. Wait a sec, hop in a notebook. So we'll just create a new notebook. So yeah. Here I'll create one markdown, saying that importing libraries because, like, first we have to import some libraries and yeah, the framework. So Scalar you might have heard in your previous videos. So in machine learning, the Scalar is like open source library, which consists of all the tools required to model to train a machine learning model. In this, we are using TensorFlow. Like, it is built by the Google Brain team in, like, somewhere around 2015, and it contains all those packages which required to, you know, like, solve a deep running problem. And basically Keras, uh, so this is also a deep learning API which comes under tensor flow, Keras interface for tensorflow library. So it comes under tensor flow. So these two libraries we are going to use. Basically, we are going to use Keras only, but it comes under tensor flow. It is under maintenance with tensor flow. So yeah, overall library, we can say the tensor flow framework we are using. So let's import some libraries which is like, which will be used in between. So first, I'll import Numpi Let's import tens of flow also from grass layers. Let's import some of the layers. Don't get confused in these libraries. I'll be briefing you with every single function I'm importing. So don't get confused now. I'm just importing some libraries which we'll be using below. For now, let's proceed with that only. So yeah. In short, let me tell you what is exactly deep learning. So let me show you with an example cat. So yeah. Basically, what is deep learning? Now, uh, It's not right now, yeah. So in childhood, you must have heard you have in your childhood, first time you saw, like, the cat image or a dog image, and your brain cannot figure out what it is exactly. But like your mom or dad or any of your relative or any of your friend, like, they told you, Oh, this is a cat. Like, the thing you are seeing in front of you, it is a cat. And sometimes first time you see a dog and someone is there to tell you, like, Oh, this is a cat. But your brain cannot recognize it at that point. But since you grow up and your age passes above, like, the brain is trained in such a way that it will recognize this is a cat or this is the dog. So basically, in your brain, the two inputs are like basically two inputs we are giving. Firstly, image of cat which is in front of you and a label, a label like your mom or dad is saying, Oh, this is a cat. And second time and also an image is getting input in your brain, and someone told you, this is a dog. So an image and a label, the two inputs we are giving. So initially your brain wasn't trained, but now, since your Ages passes, you have seen so many cats, so many dogs. So your brain is trained in such a way that it will automatically recognize any of the cat or dog you see right now. So this is basically overall concept of your deep learning. So initially, the model will not recognize any of the normal or COVID 19 infected images. But as we train, as we provide so many images of COVID 19 and normal, and we are providing like we are telling the model. Oh, this is a COVID 19 image or this is a normal image. This has not been infected by COVID 19. This has been infected by COVID 19. We are telling the model and we are training our model by providing various inputs of the image, and we are also telling what that image is of. And once the model is trained, we can provide any image, like any chest tex or image, and it will automatically recognize, like this. Is it COVID 19 infected or not? I will automatically recognize those. So, let's proceed further. And also, uh, one thing. In deep learning, basically, there are ANN CNN and RN. So these are basically three pillars of deep learning. So ANN stands for artificial Lunar networks. So basically, artificial artificial un network, is a very simple type of network, in which we simply deals with CFE files or any of those data. And in CNN, we generally this is just generally deals with the image or video and any ECG signal, these type of datasets. And in RNN, basically we generally deals with that, you know, the sequential data, basically the sound data in which the previous data depends on the future data. So that type of data, basically sound processing, we can say. So that type of data which is sequential, that comes under RN. But in our problem statement, we are classifying between a COVID 19 and a normal image. So this deals with the image data. So for that, we are using convolutional neural network. Deep learning is, let me show you one thing. Deep learning has proven to be very successful in this biomedical imaging, here you can see. With this convolutional neural network, this is basically a brain MRI scan. And with this convolutional neural network, we can classify so many things like the brain tumor. Like, we will just simply provide a MRI scan, and the model will automatically tell like this is a brain tumor infected or is this having a brain tumor or not? Similarly, we can also detect pneumonia with deep learning. We can, you know, detect breast cancer, we'll just provide breast cancer like histopathical scans, and it will automatically classify it as a breast cancer infected or normal image. So with deep learning, it is very successful in this biomedical imaging, and it has been like recently when this COVID 19 pandemic has begun, several researchers were trying to detect COVID 19 with this deep learning techniques only. So it is very successful in biomedical and it is a real time application of deep learning. Like till now, anything anything you are using with deep learning. Those are just for the sake of your learning, but this is a real projecting COVID 19 detection through deep learning, it's real time application. So yeah, we are going to build like that. So let's come back to our notebook. First thing, in any modeling part, deep learning, we will define some parameters. Basically, first thing will come as a data pre processing. I'll convert this to Markdown. Now, let me show you with an example, what exactly is data preprocessing. Like this is our dataset, training set. Now, here, as you can see, there are so many normal images and there are so many inputs to our dataset. Like, the first image I'm seeing is like 400 plus 400 GPD file. This is also 400 plus 400. But in COVID data set, if you see. Like here you can see. This is 447 cross, 418 image. Suppose this 516576 image. So all these image are of a different size. So as a part of pre processing step, firstly, we have to resize all those images in a single size, like any size we can take, we can resize all those images in 400 cross, 400 or 128 cross, 128 or 256 cross two gluten, any size we can take. But we have to resize all to a homogeneous size. So let's begin with our data process pre processing step. Firstly, I'll define some parameters, suppose I'm defining image size as 224 cross. Let's take 224. Now I'll define some path as you can see, our dataset has three parts training set, validation set, and testing set. So we have to define all those paths. Like, we have to tell model where these data are present. So how we can do that, there's a library called OS Import OS. You must be like you must know this if not, no issues, this is OS library. I will basically list all the directories we are having. So here you can see, there are so many directories in it, and this is basically dataset. This I need. So let's pass that. And yeah, here you can see. Training, testing and validation directories are present. So let's define all those paths first. Training path is our dataset Train. So this is our training path. Let's define similar for the validation too. So we have successfully defined all those paths. Training path is basically data set slash train, validation pass is data set slash well, and testing path is basically datasets or test. I've already told you what is training, what is validation, and what is testing. Training basically through which we are training our model. Validation is through which we are validating our model and testing is which we are testing our final model like model which the data model has never seen before. So let's proceed further with the training data pre processing path. Let's. So firstly, let me explain you data augmentation. So yeah, here's a nice example of data augmentation. So generally, the deep learning model, there's a difference between machine learning and deep learning. Like, machine learning doesn't require so many data, so much data, but deep learning is all depends it all depends on the data. Like, the more data you are providing, more the model will predict the correct output. The more the accuracy will be achieved. So generally, the deep learning data, they have been trained on a very large data set. Let me show you that data set off. Image net. So this is basically the dataset image net. It is named as ImageNet. It is it contains basically 14 million of images. So these large number of images, the models are being trained. But as you can see in our directory, like the COVID 19 dataset, the dataset we are using right now, it only contains like here you can see, 2616 data, like 2.5 thousand and the COVID we are having 1,000. So total in total, we are having roughly like 30 to 4,000 of images. So this image is not sufficient for training a deep learning model. Like, it will train a model. It will give some accuracy, but not the desired accuracy we want. So to generate more data. Now, we do not have this much data, this much data, 14 million, so we'll generate some synthetic data. In that the data augmentation plays a very important role. Through this data augmentation, we can generate many of the synthetic images. Now, how we are going to generate those images like let me show you. So suppose this is basically our one image sample of a cat. Through data augmentation, basically we can flip this image horizontally or vertically, we can flip this image, or we can tilt this image like this image you can see, this is basically tilting the image at some angle in the left direction. This is basically tilting this image in some right direction, and this is basically zooming those image. This is basically tilting with more angle. This is basically horizontally flipping this image. This is zooming, but also flipping. So these are the six samples we have generated with the same. This is basically the same image, but we are generating those synthetic data with the help of data augmentation. So that's why we are using the data augmentation. So we can generate many more data in the training set with the help of data augmentation. So let's jump back to our code. Now we'll import the library image generator. The image. Import image data generator. Now, what exactly is this? Now, let me show you. Basically, all this data augmentation thing where we have we are enlarging our image enlarging our dataset. So these are operations we need to perform with the help of some libraries. So as I've told you, we are going to use Keras and tensor flow. So in this very this library known as image data generator. With the help of this image data generator library, we can generate we can perform data augmentation. So that's why we are importing as I've told you, Keras comes under tensor flow. So firstly, we are importing the main tensor flow class. In that it's called as Keras class. And in that we have having pre processing, preprocessing like the image preprocessing class, and in that we are importing the image data generator function. So yeah, let's define that. Basically first firstly we are defining training data gen. Basically this is basically training data generator. In this, we are passing this image data generator function. And we are giving this requires many parameters. So firstly, we are giving it as one dot 45 scaling. Now, what is this re scale parameter? So let me show you. So basically, any of the image, yeah, let's see this image. So this image, as you know, machine learning or deep learning, I don't understand any of the image or video or anything we are speaking. Like the model doesn't recognize those. So it will only recognize the numbers. Like in machine learning, also you have gone through, suppose any text classification, also we are building. So we'll firstly convert those texts into some numbers and then we'll perform a deep learning modeling. So in the image in convolutional neural network, every image we considered as some sort of metric. Let me show you image as three cross three matrix. So yeah, there's a very nice example. So yeah, here you can see, this is a image of a man face, and we are just representing these images in a set of metrics. Now, how we can define these images in a matrix. Like every metric we are having our values 0-255. These g the scale value. So 022 55, zero is basically for black and 255 is basically for white. So let me show you with an example. Suppose this image we are having. So yeah. So in this image, this is basically complete white. So this is having a value of 255, and this is like, let's zoom here. This is completely black, so they are having a value of zero. So we'll convert whole this image into zero to 255 matrix, and in that matrix, we can represent this chest x ray as a sort of matrix. So this will be having somewhere value around 02 somewhere between 135 or 130 or something. Now, you understand what is how we can represent those images into a matrix. But what is this rescale? Now, as you have heard, in machine learning, we normalize or scale our data first as a part of data preprocessing. So what exactly is like this normalizing? Basically, suppose there's one column, it is having some feature value ranging 0-10, zero, one, two, three or something, seven, eight or something. And in one column, we are having a value of 10,000, 20,000, 15,000. So the other column is having much larger values. So the model will eventually focus more on that. Like, the model will think, Oh, this is having a value of 10,000, 15,000. So I should give more priority to that, but this shouldn't happen. Like, we have to give the weightage equally to every feature, to every feature. Now, let me show you one thing. What exactly am I talking about features. So yeah. In this deep learning, this cat image we are having this eye is a sort of feature, this nose shape we are having, this is kind of feature, this hairline, this ears, this jawline, this mouth, this hairs coming out from the nose. These are all some set of features. In dog also, the same thing, like this nose is kind of another feature for the dog. This is a feature for the cat as well and the dog as well. But there's a difference between the cat of nose of a cat and the nose of a dog. So this feature basically discriminate between a cat and a dog in deep learning. And the model will try to learn those features separately for cat and separately for the dog, and then it will classify. So these are all features. So let's come back to what we are discussing. Like in machine learning, we have to give every feature an equal weightage. Like, we cannot say that the eyes are giving more important that the model will decide. We shouldn't be deciding that. So yeah, every feature should be given equal weightage. So that's what we are doing here. We are rescaling every value. Like as I've told you, the image is coming as a 0255 matrix. And in those metrics, we are having different values like 185, 16, 137, 175, every value will be there. We are just simply dividing all the values by 255, then it will be automatically scaled to 021. Now, this is basically rescale part. And let's define some more parameters range of zero point let's say two, Zoom range of 0.2, let's say, one more parameter, I'll give horizontal flip equals true. So now what is that? As I've told you, in data augmentation, let's come the idea. So in data augmentation, there are so many techniques we can either zoom, we can either horizontally flick, we can either vertically flip the data image. We can zoom, we can share. So these are all parameter. So what all techniques we want to be, inputted in our model. So, let me show you that. Sorry. Yeah. So in shear range, basically what is happening. Shear data augment So, yeah, this is very nice example. So in she basically we are rotating the image in particular angle. Like this is let's say original image, and we are rotating this image in a three dimensional angle. And how much we are rotating we are rotating I'm giving the value as 0.2. So it will rotate with 0.2 angle. Like I will rotate like 20% angle. Same with the Zoom range, how much Zoom I should provide to a data. This is basically defined as 0.2. And if we want our image also to be flipped horizontally, so yeah, we want that. So these are like this we are performing in training data. Now let's define also for validation data. Now, let me copy that. Uh Now, in training data, we are applying so many augmentation techniques, which let me put here a nice Mdm too. So yeah. Here in training data, we are augmenting our dataset, but in the validation and testing here, we do not have to augment the dataset. Why? Like in training data, basically we have, as I told you 3,600 roughly images, so we'll generate more synthetic samples from it and like, we'll generate roughly around 30,000 or 40,000 images from that and we'll train our model. But for the validation part, we do not need to augment our dataset because in the validation set, we are just validating our model like how well it is performing or in the testing set, we are just taking testing the robustness of the model. So we do not have to apply augmentation technique on that. We just have to apply the augmentation technique in the training set so that our model is more like well fitted. So yeah. That's why I'm applying only to training set. And now, basically we are done with the input parameters. Now let's create our training set. So this is a very important part. Train underscoea chen dot that it. Then we'll fix one target size. Firstly, we are giving path here and then we'll give some target size. Let's give as 224 cross 224. Let's give a bass size of let's say 32. Class mode also we have to define, let's give us a categorical. So yeah, these are parameters. Now don't get confused. I'll explain you what all these parameters are. So we have defined what all augmentation techniques we are going to apply in our training set. Now we have to create our training set. Now what this will do, this will basically go into the fuzzy we have defined this path. So it will go, what it will do, it will go into the dataset and training this directory, and it will pick 32 image. What is this 32? This is basically bad size. Like, we are having a total of 3,600 images, and at one time, the model cannot pick 3,200 image and store it in somewhere in memory and, like, generate or you can say augment those data because that will require a hell lot of memory. So we are just picking this path size concept is very important. So we are just picking 32 images at once, and we are applying these augmentation techniques, and we are setting those as categorical variable. Like what is categorical? Basically, we are dealing with the classification problem here. We are not dealing with any regreon problem here. We are dealing with classification problem. So in classification problem, we are defining two classes here. One is COVID class and one is normal class. So that's why we have to pass categorical variable here. And what is this 224 cross tutoring for? Because as I've told you earlier, in our terretory we are having images are of various sizes. And from those various sizes, we have to pick 132, the model will first pick 32 images, and it will output the images in a standard format of 224 cross tough four. All the images outputted by this training set will be of 224 cross four. So that's all we want. And let's create similarly for those validation and testing set too. I'll just copy ones. So. This is our validation set. This is our test set. So if we run this, yeah. So here you can see, in our training set, as I've told you, there are 3,600 roughly images which belong to two classes. Now, these two classes, it has come because of this. Like the class mode is categorical. Now, what two classes are there? So the first class we are having is COVID class and the second class we are having is normal class. So in the training set, we are having 3,600 images, and in the validation set, we are having 455 images, which will be used to validate the model after every learning step, or I can say, after every epoch. And the final testing set, which is which also consists of 4,455 images which are used to, like, the test test, the final model. So if you calculate this split, it is having a 80%, 10%, and 10% split. Now, what is this split? In the Econ also, you are splitting your data into the training, testing and validation set. Basically training testing set. So there you might have heard, we generally take 0.2 split. Like we divide the training data into 80% and testing data into 20%. So here we are using 80, ten, ten split. We are dividing 80% data into training part, 10% data into validation part, and 10% data into testing part. So the split we are having and we are done with the data augmentation, but now our training set, validation set and testing set are created with the augmented images. Like when we run the model, it will pick those 32 images. It will apply these augmentation techniques where it has been told in the validation z, I'm not telling him to augment, so it will not augment. It will just rescale those values and output us. So it will apply those augmentation technique and what output size it will output. What image size it will output the image, it's 224 cross 24, and it is a categorical variable. So it will output with like it will output two things. First, the image and the second is the label, suppose it is outputting a normal image, so it will output a chess taxa and it will say, like this is of normal category. Oh, now, this is of COVID category. So yeah, it will also tell the label of that. So, yeah, we are done with the data preprocessing and data augmentation part. Data pre processing part comes under rescaling and augmentation comes under basically data preprocessing part also. So yeah, we are done with that. And in the next video, we'll see the further steps like creating a model and transfer learning. Everything I'll explain like this will be fun. So yeah. See you in next video. Thank you. 26. Project 5.1: Transfer learning Building Model Architecture Training: Hello. Welcome back, guys. So in the last video, you have seen like till now what we have done in COVID 19 detection. So in the last video, you have seen the data pre processing steps, the data augmentation part, and what exactly is deep learning? What are those bass sizes? What are those parameters we are inputting and why we are scaling those inputs and the splitting between the training validation and testing set. And what exactly is the concept of that training validation, and, you know, the testing thing? So in this video, we are basically creating our model and we are applying like we are inputting those training and testing and validation inputs into our model, and we are basically we are basically training our model. Now in deep learning, there is something called as transfer learning. So let me show you that first. So yeah, like, basically, there are a lot of models which are previously trained on a very large dataset. In the last video I've also shown this dataset, ImageNet. So there are basically many models, like suppose VGG 16, inception V three, ResNets model. Like let me show you that, uh reset Inception V three. Like this resonate basically stand for residual networks. And this basically model is trained on this image net dataset, which is, as I've told you, this is a very large dataset and the model, already been trained on that. And similarly, inception V three, it is basically created by Google, and this is trained on a very large data set. Basically the overall CNN journey or we can say the convolutional network journey. This starts from this Lent five architecture. And this is basically Lent five model. Let me show you that. Yeah. This is basically the Lant five model. And in 1990s, when the CNN first starts to grow and we are becoming familiar with the power of deep learning. So at that time, the authors have, like, created this Let five model, and this is used for this handwritten digit recognition. Like, let me show you what exactly it is. Yeah, handwritten digit recognition. So yeah, this is basically the digits which are written with any human being in a handwriting, and the computer has to recognize, Oh, this is a four. Oh, this is six. This is five. So the computer has to recognize those digits. Like here, you can see, there are so many zero to nine digits we are having. So the computer has to recognize, and this is the first deep learning or you can say CNN problem we have encountered in 1990s. And for that, the Lanette five model has been created. And from the time there, there are so many models created and, like, validated or performed in many competitions. So there is a competition held every year in which like authors present their architecture and train it on image Net dataset. Like this is a standard benchmark data set and report their accuracy. And every year, some improvements we see. So after LanetFV in 2012, architecture known as AlexNet. So this is basically an architecture which has evolved, which is known for the revolutionary scene and architecture. And this architecture basically outperforms all the previous architecture and reported an accuracy of, like, 80 76%. And at that time, like the people have reported like deep learning can perform so well on, like, image recognition problems. And from that was a revolution architecture, Alex Nt. And after that, there are so many architectures being released by different authors, different companies. Like the Microsoft is releasing ResNet. Google is releasing Inception V three, and some organizations other organizations has also been working. So after AlexNet, next year, a VGG 16 architecture has been introduced. And this is also like beaten AlexNet and like outperforms and outperforms many models. So this 16 basically refers to the number of layers. Like, basically, if I show you this, this is basically the input image. Like, in our case, we'll be inputting COVID 19 or normal image. But here you can see the scenery input image is there. So this is basically input layer. Then several convolutional max pooling and fully connected layers are there. So in the CNN, basically, there are three things convolutional max pulling and the RLE. Like, ReLU is basically the activation layer. So basically, we have three things convolutional max pulling and activation layer. So convolutional layer is basically act as a feature extractor. So as I've told you in suppose a cat image. Yeah. Let me show you this. So, as I've told you, in a CAT image, this is like eyes, nose, mouth, hair, jaw line, ears, this hand. These are many features. So the convolutional layer is basically used to extract those features. And max pooling layer are used to downscale. Like, here you can see the dimensions are very wide, and the max pooling after applying this red, that is max pulling layer, the dimensions are just half. So why we are doing that because here you can see the number of parameters are 224 into 224 into 64. Like, these mere parameters we are having. And here we are having only 112 into 112 into 108. So we are just reducing the initial height and width of image by half. And this is basically done by the max pooling. So why we need to reduce those parameters because like, as more number of parameters we have, the more more time it will take and more computational power it will take. So that's why the max pooling layer is being used. And the activation function RL, this is basically applied just with the convolutional layer to basically speed up the process and, like, activation function, many activation function, you have heard Sigmoid, ReLU, Rikki ReLu. There are many activation functions. ReLU is generally used in the hidden layers, and now what is hidden and input layer, let me show you this. Let's understand with this example. So this is your input layer, in which we are inputting our images, and this is basically one, two, and three. These are the hiddle layers. In this layer, these are basically hidden layers as shown in the neural network digam, but if you've seen in the VGG diagram, there is this input layer, and all layers are known as the hidden layers, and this is your output layer. Now all those hidden layers will consist of in the car and basically, all those hidden layer will consist of max pulling, convolution, and ReLU basically max pulling, convolutional and activation function, activation layer. So in activation in the hidden layer, the Lu performs best. Like this is basically the theoretical concept and the experiment various experiments the authors have performed. So they have like suggested the Lu to be the best working in the hidden layers. We can also use a tanage activation function, but the tanage basically considers the negative value as well. So it slows down the Oro training process by huge margin. So we do not use that. So we use like ReLu function. Now after those like this hidden layer is basically your feature extractor. Like, we will extract all those features. Now, after extracting all those features, till here till here, we are extracting features. And this blue, blue, blue you are seeing, this is basically your uh dense layer, like the fully connected dense layer. And why we are using that basically after extracting all those features, we have to classify all those features. Like, we have extracted all those features from a cat image and a dog image. And then we are classifying basically which all features combines output the cat and which all features combines output the dog. And in our case, which all features, when we get together, we'll combine output COVID 19 infected image and which all features when we combined output as a normal image. So that classification part that is performing here, like the fully connected layer, and basically when we are inputting the image, in short, I'll brief you again, when we are inputting the image, we are extracting all those features in these hidden layers with the help of convolutional max pooling and ReLU activation function, and till here are all the feature has been classified and stored in a feature vector. So now the task remains is to classify those features. So here we are basically mapping those features. And this last layer is basically your softmax activation function. Now there are some activation function just like sigmoid activation function. Here you can see the sigmoid activation function. Like if you know, sigmoid activation function is basically used where we are performing a binary classification. Like in the case of COVID 19 or normal, we are just doing a binary classification, like we are classifying an image, either it is positive, COVID or it is negative. So only the two output is there. So in that we are using the sigmoid activation function. If we have more number of the output values, suppose the handwritten digit recognition problem. Here you can see, we have our output 0-9. Like we have ten outputs, zero, one, two, three, four, five, six, 789. So we have ten outputs. So here the sigmoid function we cannot use because this is not a binary classification problem. If we have to classify those digits only 0-1, then we can use Sigmoid. Only 4-5, then we can use Sigmoid. But if we are classifying all those nine, ten values, then we have to use softmax activation function. And here you can see the softmax activation function. So yeah, this is basically your softmax activation function. So in the last layer, since the original VGG architecture, we are not classifying it as a binary classification, we are classifying between 1,000 number of classes like this image dataset contains 1,000 number of output classes. Like those output classes can be bird, dog, cat, snake, bottle, lights, anything. So we are classifying those thousand output layers. That's why we are using the softmax activation function here. Now, this all theory, I hope you understand and now jump to code and we'll build we'll use basically VGG 16 architecture here to classify COVID 19 and normal image. Now, one more thing I missed. Basically, I told you what is transfer learning. So in general, if you see the transparent definition, like it is that focuses on storing knowledge gained while solving one problem and applying it to the different but related problem. Now, what is this? Now, let's say I have created this VG 16 architecture. I have trained it on an image net which contains all the variety of images like medical image, cat, dog, any amount of images. Now, I am applying this stored knowledge. Like, I'm using this, you know, say, pre trained weights, like in neural networks. All the game is all about getting the appropriate weight. Like suppose here W one, weight, one, weigh two, weight, three, weight, four, weight, five, there are so many number of weights here, and we have to calculate those relevant weights, those appropriate weights, which will result in a correct output. Like, this is all the intuition of, you know, deep neural network. So basically, in transfer learning, we IHS, as I've told you, I have created suppose WG 16 and I've trained in on this imagine dataset, and this model has already learned so many amount of features. Now, we do not have to train a model from scratch to learn the features of COVID 19 and normal because it must have been already learned those features. So we'll just simply apply the transfer learning technique. We'll use WIG 16 a pre trained weights, and we'll apply to our promise statement. And it will give a correct output. We can create a model from scratch also, but that is computationally more heavy. So instead, we use transfer learning method only, and we can use. I'll show you transfer learning right now, and this is more like viable option. Like if you train if you create architecture from scratch and then if you are training it to the, let's say, thousand people. But in case of transfer learning, you can achieve those same results with the help of only just two or three epochs because weights have already been trained, you just have to fine tune those. So let's jump back to code. Now this is basically the data spreading I've told you. Let me just clean this code a little bit. Like, I'll add all those libraries importing thing and above only. Yeah. Now let's import. Basically G 16 is already under Keras, the trained weights I have told you. Here you can see WiGig 16. It is already like the weights I have told you image in it, and the classes is number of thousand classifier activation softmax. So already, it has been basically the author who has created the VG 16 architecture. It has trained he has trained on image dataset and saved under Keras. So in Keras, we are already having those architecture. So let us build that like, let me show you how to use those architectures. After this, you can use any architecture in the world. Like VGG, if you want to use inception V three, I'll also tell you how to use inception in case. After this, you can use any of the bateria in any of your problems. Now, let us first import G 16 from Keras. Applications. G 16, Import. How we are getting that. Let me show you that L see from tensorflud ITF is basically tensor flow, tensorflow dot Keras dot applications dot VGG, we are getting this function GG. So yeah, this is basically how we are importing. Let us import that. Yeah, the G 16 is already being imported. Now let us build our model. Like we already are training set validation set and testing set ready. Now let's build our model. Let me put a nice moundown here. Yeah. So firstly, I'll create a basically base model name, and in that, I will import that VGG 16, which has already been reported here, G 16, so I'm just using that function. In the G 16, I have to first pass the input shape. Now, as I've told you, the model will take one input shape, like all those images, all those images in our dataset is already being resized into 224 cross 24. So I'll just pass 224 clus 24 here. Four cross two, n four cross three. Okay, now, what is this three? Basically, every image is, I have told you, three cross three metrics and that image is basically considered as, like, you can see, width, height and RGB channel three. Now, what is this three? This is basically the width of image. This is basically height of the image, and this is three. Now, three for your RGB channels. What is this RGB channel? Any image you see is considered of, like, can be, you know, discriminate between red, green, and blue. This is called as your RGB channels. So this RGB channel is important because every time you are not getting, like, the grayscale image, sometimes you will get, you know, that colorful image. So that colorful image is represented by the RGB channels. So that's why we are passing here 224 cross 224 cross three as a input. Now, let me delete that. And yeah, the next parameter we'll be getting is the weights. Now, as I've told you, this model is already being trained on an image dataset, so we'll just use the image net weights and include top equals force. Top equals force. And let me show you this. Now, let me show you that VGG 16 architecture. So here, as I've told you, we are already training those weight from start to end. And here, that include top equal falls represent that we are not including this last layer. Why we are not including this last layer? Because in this architecture, we are classifying between 1,000 number of classes. So just we are eliminating this last layer and this layer, like the initial feature extractor layer, the classification layer, we are using that. And apart from here, we are just cutting off this layer. And this many train layer, we do not have to, you know, train again and again. So we can use that, and I'll show you how to define that also. Just run that. We are getting that base model. As I've told you, we do not have to train those initial weights. And now, how we can perform that we can perform with a fur loop model layers. To. So in our base model, that is GG, we are already excluded that last layer, include topical false and now we have to freeze all those weights. How we can freeze all those weights, we'll go through one by one each layer and just like every layer contains a parameter called as trainable and we'll just set this trainable parameter as false. We'll just run this and all the initial weights are freeze. Now we come to our next modeling part and we are getting the initial feature extractor layers and the WiGig all set up. Now, as input layer, it's input layer. We are getting our base model dot input. And now, let's say X equals to base model dot output. Let's flatten all those layers. Don't get confused. I'll explain you everything. Now let's flatten all those layers, and let's add a dense layer. As I've told you, like dense layer is used to classify those features which we have extracted through convolutional max pooling and activation layers. And like, as I've told you that function between basically activation function we can use in the hidden layer or reel. Just pass that. Then we'll add a dropout layer also. I'll explain to you what is a dropout layer also 0.5 then I'll create an output final layer with, let's say, dense neuron of two. Y two, because we are getting like we have to only classify between COVID and normal. So like finalizing this final layer out text as two neurons only. We need only two neurons. Either it's COVID 19, then the first neuron will light up and it is normal lima, then the second neuron will light up. And here we cannot use ReLu activation function. As I've told you, we'll use softmax activation function. Now we'll create our final model with our inputs, sorry, inputs as our INP which we have defined earlier, and our outputs is our output neuron. Okay. Wait a second. Here one flat and dense. Wait a second. It is giving an error. Okay, okay, okay, sorry. Like, I haven't I missed here, and the dropout spelling is also Okay, dropout we haven't defined, so let's define here dropout Now dropout is defined. Everything should work fine. Yeah, it is fine. Now, let me explain you what's all this. So basically in the first base model input layer, we are defining an input layer where we'll just pass our images. Then this output layer, like the overall output layer, let me show you this here. From here, we have cut down the layer and this layer we are considering as output for now and we are just taking that output layer. We are flattening. Like this is basically your flatten layer. Now, the flattening layer will convert your whole overall This is basically three cross three metric, three cross three matrix, 33 matrix and the flattened layer will just convert those all three cross three matrix in a single dimensional vector. Like, let me show you this. Yeah. So basically, yeah, as I've told you, this is basically your three cross three matrix, matrix, three cross three matrix, and the flattening will just converse all those layer, the three cross three matrix, three dimensional matrix in a single dimension vector. Why we need to do that, I'll explain to you further. So after flattening those layer, we have mapped those layer with a dense neuron dense layer of 1,000 to 24 neurons consisting of a Lu activation function. Now, what is this? Like, after flattening this layer, we are adding a dense layer here and we are mapping with this dense layer consists of the wait a sec. Yeah. This basically dense layer consists of 1024 neurons. And as I've told you in the hidden layers, we are using Low activation function. Now, the flattening, these all flattened neurons. This is basically one feature of a dataset. This is one feature of a data. This is one feature. Like every neuron is flattened and in a single dimension vector, it will consist of all those features. Now we'll map those features with a dense layer to classify it between a COVID 19 and a normal image. So that we are doing here with a dense layer. And basically this is X output. Then we are taking this X and we are flattening. Then again, this is basically your single dimension vector. Then we are taking that single dimension vector and mapping it with a dense layer, then we are adding a dropout layer. Now, what is this dropout layer? So in neural networks or any machine learning, you have heard of a term called overfitting. Yeah. So this is basically your overfitting. Overfitting is generally like overfitting is considered as basically your training accuracy is very high. Your training accuracy in the training set, you are achieving an accuracy of let's say 99%. Let's say, 99%, you are achieving training accuracy. In the testing accuracy, when you are very much satisfied with the training model and you are saying, Oh, my God, I have got an accuracy of 99, so my model is working very fine. Then you are when you are getting to test your model and you are getting an accuracy of only 92%, then you are like, what just happened? Like, it is only 92%. Like in the training, it was showing 99%. Then why it is showing 92%. For that, this situation is called overfitting. And in neural network, there are many techniques to encounter those overfitting problems. Some have such as called L two regularization. Where I'll not go into detail in this element antigation but this is a method to encounter those overfitting. Now, the best thing which works as a overfitting to overfitting to eliminate those overfitting problems, is a dropout layer. Now what dropout layer will do? Let me explain to you that. Yeah, this is a very nice picture. Yeah. So here you can see this quality is not so clear. Yeah. So here you can see, like this is your input layer. This is basically your hidden layer, and this is your output layer. Now, this, every output will depend on every neurons. And sometimes what happens is the models start emphasizing this neuron or this neuron too much that the model is overfitted. So what dropout does exactly is it eliminates every neuron in every iteration, it eliminates those neuron randomly. Like I one epoch, it will eliminate this and this neuron. In another iteration, it will eliminate this and this. It will just simply eliminate those neurons from the data. And what is the use of that? Like, firstly, the model the model is heavily dependent on this neuron, suppose. And in the next iteration, I'm just removing this neuron. So the accuracy will get down, and the model will adjust those weights accordingly so that if in future this neuron is not present, it would automatically adjust the weights with these three neurons and output the correct value. So the model now that dependency is getting over, the model is not dependent on a single, say a neuron. So it will just uh like the dropout helps in that to eliminate the overfitting by just removing those neurons in every iteration. Here, I have passed 0.5. This means we are eliminating 50% neurons from every iteration. Like in this iteration, it will randomly eliminate 15 neurons. That means total number of neurons is four, then it will randomly eliminate the first two neurons or this first and third neurons or any type of. Like, here we are having 10, two, four neurons in our dens layer, so it will randomly eliminate 512 neurons from every iteration. So that basically eliminates our problem of overfitting. Now the final layer is basically your classification layer. This is your softmax activation function, as I've told you, in activation here we cannot use nu. We can use sigmoid or softmax. Here we are using softmax and two neurons neurons, why we are having these two neurons because there are two number of classes, and those classes you already know, this is COVID 19 and normal class. So those two classes, this is your output neuron. And the final model is created as inputs we are giving input, base model input, and outputs we are output defining. Basically, we are inputting that same data, we are using the WiGig as a WiGig activator for the same input like architecture. But we are just for the sake of using transfer learning, we are changing the output according to our dataset. Like in our dataset, there are two number of classes. I suppose we are classifying between cat, dog, and rabbit, there are three number of classes, so we'll use three here. And in our case, we are using just two. So this is basically your model architecture you have already created. Now, let me run this model. Let me show you this model dot summary. Yeah. So this is our first input layer and input layer, we are inputting 224 cross 224, cross three, which is perfect because all the images we are getting here is 22424 and in the output layer, here you can see the max pooling. This last layer is basically your VGG ends here. Now we are customizing this layer according to our pronounced firstly, we are flattened, so we get total of 25,088 features. And we are mapping those features with a dense layer of 124, then we are simply adding a dropout layer, and then we are simply adding a dense layer of classification. So this is our model not summary, the summary of our overall model. Now we have to compile our model. I'll say what is compiled. I'll explain to you what is compiled. I'll write those functions first, then I'll explain you. Categorical cross entropy is our loss function. The optimizer we are using here is the atom. And the matrix we are using here is the accuracy metric. So yeah, our model is compiled. Now, what is the three things? Firstly, I have inputted this loss equals to categorical cross entropy. Now in the neural network, like the basic neural network concepts I'm hoping you are already familiar with, like, what neural network does it will initialize these weights randomly, like any weights 1111 or 0215 randomly weights, it can like a lot. And after performing every iteration, it has to adjust this weight. Now, how it will adjust this weight? Like, suppose we know the output value already. Like, we know the output value for COVID, suppose we are getting output value of zero. Sorry, in COVID, we are getting suppose one and normal zero. Like, whenever one will output, one is our output value, then it is classified as COVID. If it is zero, then it is classified and normal. So output value we already know these weights we are initializing a randomly, but we have to adjust these ways. Now, overall, the concept of deep learning come here. And it will basically compute those initial weights first. In the first depoch it will compute those weights and it will match it with the actual output. Like, suppose here you are getting 0.8, and actual output we should get here to get a COVID is one. Now there's a error from the difference between the actual output and the preted outputs called an error. So that error basically is one -0.8, and that error will back propagate and solve. So this is basically called as your loss, like how much loss you are getting. So that's why we have to use a loss function called as categorical cross entropy. I can show you this equation. S, categorical cross entropy, the loss function that is used in a multi class classification. So we are using categorical cross entropy. There are many losses, there is not one loss. As you can see, they're under keras. There are many kind of losses here. Binary crossentropy when we have two classes, we can use here binary also because we have only two output, but I'm explaining to you the more generalized for them. Like categorical also works, categorical definition is two or more. So here we are getting as two. So you can use that too sparse categorical poison, binary crossentropy function. These are all many types of loss function we have. So we can use on probar regression if you are using regression you are using deep learning for regression problems. So you can use those regresson losses like mean squared, RMSC those all you have heard. So there are many loss functions. Next is your optimizer. Now what is optimizer? Wait a sec. Optimizer. So in deep learning, basically, there are many types of optimizers, and this optimizers basically optimize your overall model and help your model to train faster. And optimizer is a function of an algorithm that modifies the attributes of intern such as weight and learning grade. So this basically is used to train your weights or you can say train your model even faster. So we are using this optimizer and there are many optimizers in Keras Optimizer Keras. Like the SGD, basically, SGD is your stochastic gradient descent. RMS prop, Adam, Ada Delta, AdamaX Adagrad, FDR, there are many optimizers. We are using Adam here because Adam is the fastest optimizer available. In SGD, sometimes we can get even better accuracy or RMSProp, you can get better accuracy, but Adam also outputs you the similar accuracy work on similar accuracy, and it is very much faster. So we are using Adam here. Now our overall model is compiled and we just have to fit our model. Yeah. Now, wait. Now, model dot fit. Yeah. So firstly, we have to pass our training set like this training data we have created. Now the next parameter will be the best size. Best size is let's say 32. The next parameter is pos Epoch. Huh. Now, how number of epoch we want to perform? Like, let's train our model for just five epox because as I've told you earlier, if we are building the architecture from very scratch, then we need like 100 or thousand number of eBoxs to get the optimum weights. But here we are using transfer learning. So our job will be done by only just five Epo. Or if you want, it will take much longer time, so I'm training it for only five Eboo. But if you want, you can train for like 100 or thousand as many you want. Like, it will depend on your computer hardware as well. Like if you are having a very latest generation GPU suppose RTX or GTX versions. Then it will train much faster. But since I'm having NVDA G nine fortyM which is a little older version of GPU, so it all depends. So I'm training it just for five Ex. Now this is another parameter called validation data. Yeah. So here, we'll get our validation data. Let me cl. Yeah, this is basically your whole modeling part. Now, in model, we are passing our training set on the model which will be trained and the validation set on the model, which will be like validated at after every EPO. Now this is bass size. I've already told you what is bass size. Like, we cannot put all the 3,600 or how many images we have 36 441, three, six, 441 images we cannot put directly at once because it will explode the GPU and it will show us error of out of GPU problem or something. So we are putting in batches, 32 batches. Each time 32 image will be input into the model, and then the model will calculate the error, adjust the weight according, and then the next 32 will get like here also, you can see. Mm. So here, basically 32 neurons, like 32 images will get inputed first. What is verbos? So after every here you can see model dot fit keras. So yeah, model training ABI. So in the model dot fit, as you can see, there is one parameter called as verbos. Now what is bos? Like, let's see here, here. So its value can be zero, one or two. Like, zero means silent. The model will just train and will not show any output. One is basically create your progress bar, like it will show the overall progress of the while training, you can see the real time progress of your model, how the loss is decreasing, how the accuracy is improving, how much loss you are getting in every iteration, how much second is your model, how much second it taking for one epoch to run every detail it will show. And in the two, it will show even more details. So we are using only War boos one because we want one line. We don't know what to fill all those notebooks or our notebook with the details. So we are running modeled outfit. Now, as soon as I hit Enter, it will start training our model. So here you can see. Firstly, it is like it is uploading all the data, all it is creating the batches into the GPU memory. Like in the RAM memory, we cannot train because we are using GPU. So GPU memory it will use, and it's starting training for EPOC number one. So it is taking the initial training is beginning, so it will take some time. Just wait for like 5 seconds, five to 10 seconds. It will start training. In the task manager, let me show you we can see our PC statistics. Let me show you one more thing. Like here. Here you can see that this GPU memory, this is basically your GPU, like four GB of GPU I'm having, and this is basically starting the training in the GPU. This is basically loading our overall data in the GPU first. It is taking some time, but it will start, Basically the first time, the first time when the training is starting, so it takes some time because it fits all those data in the GPU ones and then or let me do one thing. I'll basically restart my kernel and then I'll again, fit that model. Let me do that also. Like, I'll just This is basically a button for where you can interrupt the kernel, and here I am like these are kernel options. Also, we are having Python three and environment, any kernel we can choose. Earned. Like, let's restart our kernel and clear output. Yeah. So kernel is restarted. The output is still visible. Wait. Let me restart and clear output. Yeah, so all the outputs have gone. Now, just run each of those cells again. Each of these cell is just running again. Yeah, this is all undone. Yeah, so model summary models compiled. Now let's just fit the model. I hope this time it will start a little early. As you can see, the graph will just about to the GPU graph. Here you can see the GPU is almost full because It will start the training. Like it will start the training, but it will take some time. So let me, let us see that in next video. After the training will be performed, we'll reconnect, and we'll see in all those night video. Basically, the rain initial training time will take some time, so it will, I'll perform all those and like five Epox after the model has been trained for five epox then we'll proceed further. So let us see you in next video. Thank you. And 27. Project 5.2: Evaluating Model Testing on Real Images Plotting Curves: Hi, welcome back, guys. So in the last video, we were stuck on the training part, but it's been dissolved now, and as you can see, the model has been trained till the five VBox. So basically what I did was uh, I scale the images to 128 comma 128 size. Initially, we were using 224 comma 224, but since my GPAm is only four GB, so I have to scale it down to further 128 comma 128 because you see the total number of operations, it all depends on the Image size. So like 128 into 128 into three. This is the memory requirement into 64 bit because it is one bit requirement. The memory requirement for one image, wait, let me explain you this way. The memory requirement for one image will be like 224 into 224 into three into 64 bit. So this is the memory requirement of I can say, one image. But what I did is, I converted this to 128 comma 128 cross three cross 64. So as you can see, it is taking much shorter amount of memory. And also, like at one bass size as I've told you the concept of bass size. In one bass size, we are putting up 32 images. So it is going to 32. Oh, you see, there are a lot, it requires a lot of GP memory. So either we can decrease the IMS size scale it down to further like 128 bit or, you know, 64 bit or 96 cross 96. Anything we can choose. But it is recommended to use 128 cross 128 or 256256 or 224 cross to 24. So it is recommended to use this. Now, or we can also decrease our bass size to a further extent. Like, initially, like right now we are using a bass size of 32. We can also scale it down to 16 bath size or eight bath size, but that will increase the computation, like the time it takes to train a model. So we don't want that also. Now you must be thinking like, what exactly AmSize do we need to choose for our dataset. So this is a bit of this comes off a bit with theoretical knowledge. So like I can show you with an example. Like, let me show you our dataset first, then you will understand, much more detail. Like, suppose this is our image, COVID 19, right? And this is of Image size like 522 gross, 582, right? And if we scale it down to further like 128 cross 128, we can resize this through 18, it is not affecting much here. Now, you must be thinking like, where it will affect. Like I can choose 128 cross 128 or I can choose every image is 64 cross 64. That's like it is a bit of theoretical concept. Like suppose you are detecting brain tumor from MRI scans, MRI scan. Like I'll tell you. Like, suppose this is the brain tumor. In this MRI scan, this is basically your brain tumor. Let's wait for a sec. Yeah. So basically, this is your brain tumor. Now in this image, if we resize it to, like, a much smaller size, like let's say 64 64 or 96 or 96, if we resize it too much extent, then the tumor will almost disappear from the image. Like, it has already been such a small, part of the image, and if we resize it further, then the tumor will start disappearing. So here, we have to choose a little bit of, like, larger side, larger Img size. But in our dataset COVID 19, if I have selected 224 pro 224, it will give almost same accuracy or 128 ro, 128, it will almost give same accuracy. So here, we can re suggest to, like, a little bit of smaller side as what I did in this like here, 120 eros, 128. I hope you have got some idea where to resize the image, much smaller or where where we shouldn't resize that much smaller. So here, if you train your model, if you have that much GPU Am available in your laptop, you can train it to like 224 cross and you will notice you'll get a nice accuracy with that also. Now, as here you can see, with the transfer learning concept and data augmentation concept, we have already gotten an accuracy of 94% in the first round. The first Epoch only we have gotten an accuracy of 94%. So this is a very great accuracy. And in medical, if you are getting an accuracy above 95 or above 90, it is considered a very good accuracy. So with the help of transfer learning, we have achieved such a nice aresen L in the last iteration, after just only five epoch, like 102nd, roughly, it is taking for one epoch and total five Epoch, it is roughly taking 500 to 600 seconds. And that means like five to 10 minutes. Like, Llore, you are getting to train your model. And in the 10 minutes training time, you are getting an accuracy of 98%. So this is very good. Like, this has only been achievable through the transfer learning concept. If we have trained the model with any, you know, custom architecture. If we start creating an architecture of ourselves, well not get this much high accuracy at the end of five Bo. We'll get a good accuracy. Maybe we'll get very good accuracy, but that will only be possible if we train our model to 500 or 100,000 EBOs. So why to waste so much of computational resources when we have already VGG 16 or any inception V three or any model available in our KR APA. So why to use custom CN. So with the help of transfer learning and data augmentation, we have gotten an accuracy of 98%. Now, you must be thinking, what is this 114? So, in the training set, as you can see here, we have 3641 images. Like three, six, 41 images are getting into the model at once, and we are sending it through 32 bad size. So when you will divide this 32, you will get, like, let me divide this 364, one divide 32. So I'm getting a value of 113.78. So basically, there is 114 number of total batches created. And in the 113 batches, it's like the images are gone, and the rest images, the model put in 100 remaining images of this 0.7. This is not a decimal value. This is the number of images basically remaining value. I put in the 100 114th basically batch. So these are 114 are basically number of batches. So after each batch, after each iteration, after processing through one batch, it will update it weights, then it will send the next batch, then it will update the weights. Then it will send the next batch 114 times it will update the weight in one EPO. And now what is EPOC, basically? So after training it through complete data, we have gotten an accuracy of 94.15%, and we'll simply shuffle those images. Like the three, six, 41 images we randomly shuffle and then again, we'll input into the model. So that is basically your EPOC too. So we have performed like EPOC five, and we have achieved an accuracy of above 95%. Now, this is basically your training accuracies, and this is your training loss, and this is basically your validation accuracies and validation loss. Now, you might also be thinking, what is this history? So basically, in every epoch, there is this value like loss accuracy, validation loss, validation accuracy. Each epoch, it is saving some kind of details. So that detail is basically stored in this history. Like, if you will see if I show you history. So you can see this is callback function, and it is basically let me show you the history when I show you the history, like see. This is basically a dictionary, Python dictionary in which first value is loss, and in that you have this loss like 02.9, 0.05, 0.04 014013. This is the laws. This all the accuracies. Is all the validation loss and validation accuracy. Now, what's the use of that? It is basically used to analyze the model. Like, if we plot a graph, we'll be plotting a graph also, there you will see. But if we plot the graph, we can analyze from where the model accuracy is not changing much. So we can stop our model at that point. So like, this analyzation part, it requires that history dictionary with us. So I have saved the overall model, initially, I forgot to save, but now I have saved this model. Now let's evaluate now. This is basically our training accuracy. This is our validation accuracy. After each iteration, as I've told you, validation set is used to validate our model. So let's evaluate here we have our testing data also. The model which has never seen before. The data which model has never seen before. So let us evaluate our model on those testing set. We'll just print one statement, evaluate test data, and how we can evaluate, we can sort it in a valuable results and the model. The model name here, the model dot evaluate. There's a function called model dot evaluate. In that, we will simply pass our testing set, and again, we have to pass a bass size. So bass size just will take 32 and we'll just simply print that result. Loss Test accuracy. And here is our result. It will output tube values, the loss and the accuracy. Now here you can see it is evaluating on the test data. Here you can see. Till now, the accuracy is 100%. The model hasn't failed anywhere. Hope we'll get a good accuracy at the end of Epoch. The loss is very minimum. Till see accuracy decrease a little bit. N 9.37, 99.43, 9.48, 52, 56. So here you can see, we have gotten an accuracy of 99.56. This is a remarkable accuracy. Generally, we don't get this much higher accuracy with simple applying a CNN. So here we have achieved. And this is all possible because of the transfer learning and the data augmentation concept. Like, firstly, with the help of data augmentation, we have generated a lot of images, so the model will learn to discriminate and learn those features more easily. And then with the robust model, WiGig 16, the pre trained weights, we have used those pre trained weights, and we have applied the concept of transfer learning. And this has given us a very good results. So the overall concept of deep learning, we have a target to decrease this loss function. Like, after one Eboch, the loss value is 0.299, and then the model, again, it rated through whole data and tried to minimize this loss. So here you can see this time the loss is very less. This time, even more loss is much lesser. Then again, it decreases. Then again, its every time the loss should decrease. Like, if it is increasing also by a little margin, it's not a problem, but the model should learn in this way so that the loss will decrease every time. So this is like overall the desired, you know, results we want. So here till here, our model is trained, our model is tested. Now, I future, whenever you want to use this model, this is a very good model you have trained with an accuracy of 199.56. This is a very good accuracy. So we want to save this model. Like in future, we don't want to train this model again and again and waste our, you know, 10 minutes or 15 minutes of training time. So we will save this model. So for that, we'll simply write model dot safe and we have to pass a name.h5. So this is basically the model. The tensor flow model is saved in a.h5 file. Like this is basically extension for the model. So we'll just simply click and yeah. So here you can see this model.h51 52 B H five file. This is saved. So now, I can simply shut down my notebook, and in future, I will simply load my model from here and I can start working. I can start predicting images. So now that's g of this model thing. And now let's plot some graphs. L in deep learning, the overall visualization and overall, analyzing how you have performed like your training has done, how well you have augmented data. Everything is very important to know. And that we can analyze through plotting some of the loss curve, accuracy curve, some matrix like confer matrix or like ROC AUC plot. So yeah, for that we can use. So let's plot some of the graphs. Uh yeah, I'll just write this Marmo down and so yeah. First, let's just plot a simple, let's just write a function for plotting graph, and then we'll plot his loss and accuracy both of the curves because for both of the curves, we have the values of accuracy and loss in our history dictionary. So we'll just write a function. So let's just write a function def plot history. This is the variable we are passing in the history variable. Also, the plotting thing we do generally in machine learning is you must have learned matplot lib and CBO. So yeah, here also, we can use, we'll use Matplotlib only. So import ibt PLT. So yeah, we'll import matplotlib. Now just I'll write a simple function. Fixed size is equal to, let's give us ten com of four. Plt subplot. Here is no bracket. So this is basically your subplot. I'll create two graphs in one single graph. One is for loss and another is of accuracy, and I have given a figure size of ten cross four. Like ten is basically width and four is the height of the image. Axis, zero. But far History and in the history, we have value known as loss. First we'll plot the loss curve and then we'll plot the accuracy curve. And history. Validation loss. In one figure, basically in one figure, we are drawing both the losses. Like this is the training loss and this is the validation loss. Both the losses will plot, and in one figure, we'll plot one accuracy curve and one validation accuracy curve. So yeah because you see wait I'll show you this. So yeah, here you can see, one is loss value. This is our training loss. This is our validation loss. This is of training accuracy, and this is validation all those four value we'll use. Validation. Loss. Line width of Let's give 0.5. We don't want very thick lines. Access zero. Let's give it a title. Let's just name it as title. I misspelled that. Sorry. Let's just give a loss title. Now, let's plot the same thing for accuracy. Let me just copy this one more time. Yeah, so it will be Acess one, and this will be your accuracy key in the dictionary. This will be your val accuracy Again, we won the same line width, and let's just change this name C I see of **** thought. Yeah. So we have our function ready. We have plotted for the loss and validation loss in a single loss curve and accuracy and a validation accuracy in a single accuracy curve. You don't need to remember all those code because simply you will Google if you Google plot accuracy and loss curve deep learning through history, you will get the code somewhere on stack overflow or anywhere. So you don't need to remember that or you can use this code also in your future. So yeah, you do not need to memorize those. So we'll just pass history dot history variable. And here you can see, yeah. So here you can see. In one single curve, we have loss curve and accuracy curve, and in the loss curve here you can see this is for your training and this is for your validation, and this is accuracy curve. This is for your training, and this is for your validation curve. So we have a nice plot here in front of you. And also, you can customize this more. I I'll import, you must be familiar with the C bone and if we are using SNS though. Here you can see. Like we have also customized it a little bit. So this is your loss and accuracy curve. We'll put all this in upward. We don't want to clutter everything. Now in the plotting part, firstly, we have plotted the accuracy and loss now. Let's do some predictions with it. Then after that, we'll, we'll see some more curves like confuson matrix and ROC plots. First, let's do some predictions. So I'll quickly write a markdown. Firstly, to visualize the image, we need a library, CV two. This is basically your OpenCV library in which all of the computer visions function you can use, like CImage, do some image processing in an image, visualize, save a new image. Like many of the operations you can perform with CV two library. Here we are just using read function or OpenCV because to read image, we need like this library also. So let us create an image variable that we write cvto dot read. IMRaD is the function for visualizing the library. Here I'll just write my path of the variables, use go our notebook is in this directory, so we don't need to night the whole path. We'll simply copy this test images. This is a directory where I put some of the images in which we both have the COVID and normal images to testing for testing purposes. So I just simply write this test images directory, and any one image first we'll do the prediction. This COVID 19, firstly let's visualize the COVID 19 image. 1918 dot. Is it a JPEC file or let me see. Yeah, it is a GPG file. So yeah, this is working Perfet. Now, let's just plot this image through the matplot lip show Imho in the IMCo person, we'll pass this image. So here you can see. This is the image we are visualizing here. Let me also give it a title. The title, testing image, let's give a title, testing Image. So yeah, it is we have a title. Like, let's try to remove these lines. Media. It is not recommended, it is not needed to write this Jypa notebook will visualize image without this also. So yeah. So here we can see like we are visualizing this image with the help of OpenCV. Now, let's just predict do some prediction with the real time images. So suppose you are starting from scratch and firstly, you have to load model like the model here which we have saved this model dot at five, suppose we have to load this model again. So for that, we have to write s of flow, Keras dot models. Import load model. This is a function in Keras Load model. So with the help of this, we can load our model. And how to do that? Suppose, let's give you a new name, my model is equal to model dot no wait. Load model. In that simply pass the path of your model. So we have model.h5. Let's load that and my model here you can see anything which we have watched for model dot summary. So we'll get same thing. So our model is loaded in our new my model thing. So now we have our model loaded. Previously, which we have trained, we have loaded the model, and Yeah. So now let's just if we just want to predict the test the model into this image. So let's just import this image into, like, library image. So yeah. Firstly, we'll import this image into our library into our notebook and then we'll perform. So I'll quickly write it down Image Load image. Here we have to give the path of the image we want to test. So for that, I will give the path this. So here, the image name is COVID 1918 dot JPAC and we'll just simply write Oops. Okay. Yeah, for here, we also have to import one more library. It is also under Keras Image p processing library. So I'll simply import that. Processing Import. This is called image. It will perform all the functions with an image. Just wait a second. It it is not loading. Image, it should load. Do image has no attribute image load image. Let's just find this why it is and I don't know what why it is not loading. Let's just search it on Google once. Like this is how you can basically search for any image search for any queries or errors. So let me pre processing load underscore image. I don't know why it is not giving us the output. Okay. Here, you can see image dot Load Image. Okay, we also have to import this pre process input. My bad. Here we are using VGG 16. Still, it is not working. Am I doing any spelling error? Module keras or processing or image. Let's give it a target size. Okay, we are not performing the target size. I'm forwarding target size. That's why I think it's not working. Now it should work. No still it is not working. Okay, okay, okay. Here, here we got we are having a very I'm doing a very silly mistake. This is basically Load IMG. I'm writing here as load IMG, my bad. So this is not required. So yeah, here, basically, image dot LowMG we have our image ready in this image variable. Now, we'll create a variable X, and we have to convert this image into array because as I've explained to you earlier, the neural network cannot understand the value, the image data. It will only understand the numbers and in three by three array form. So we'll simply will convert this image into array. Array, we'll pass this image through D. So yeah, we'll have our X ready, and then we will use the Numbi array to basically expand the dimensions. And this expansion we have to do because the image is currently 28 cross 128, and we require the model input as 128 cross 128 cross three. So we'll expand the dimensions across the x zero. Initially, basically the X will see like this, the three gross three matrix as I've told you. So we'll see our image in this form. But after expansion of this array, we'll see one more bracket here. So, if along the axis, it has expanded. This we have to do a part of pre processing step because the neural network like our model architecture will understand those input in that way. So yeah, for that only we are doing this. And the image here I have input it. So yeah this is required image data. So according to the VGG architecture, we have to pre process this image further so that the model in accordance to the model requirements. So yeah. Now our image data is ready. Like this image data, if we pass into our model, it will give us the prediction. Here you can see. This is basically this pre processing why we have applied because initially, if you remember, we have scaled down all the images into zero to one, and this model has again scaled it's like whatever it is required for the BG 16 architecture, it is again done according to that. So this image data when we'll pass into our model. So it will predict some classes. So let's predict that model dot predict. Sorry, our new model name is my model dot right. So yeah, image underscored data. So this is predicting basically. So yeah, here you can see. We have got this type of output. Now, let me explain this. Like we have passed basically COVID images, COVID image, and here you can see, like, not here, in our dataset. You can see, first class is COVID, second class is normal. So here what you are getting as output, it is predicting for both the class, how much pat since the softmax activation function we have used. Now, this softmax will return us the probability of each class. So our model is giving us the output that the possibility of this image to be a COVID 19 image is 100% and normal image is 0%. So model is predating that this is a COVID 19 image, basically, because it is predating one as a output for the first class that is COVID class and zero for the normal class. So we'll just store it in a variable because we are getting classes here. And yeah, we are just getting this output. Now this is basically array within array, so we require only this first part. Yeah. And sometimes this is like this time we are only getting the value in 100% and zero. Sometimes we can get this value. Suppose this is 0.85 67, and this is somewhere between 0.15 and like this type of values. So we have to convert also this value into inter format. Let me do that classes zero cross zero because we only require this first value. So yeah. A now to predict that, let me write a simple function. If this result equal equal one, then I'll simply print that person is affected by COVID 19 or else, I'll simply write person is normal, or I can say result is normal. So yeah, if you'll pass this, see. Whenever we are passing this image, we are getting this person is affected by COVID 19. And here you can see we have passed the COVID 19 infected image only. So we don't need to print all of this again. I've just printed for your understanding. So I'll remove all this. This we need because sometimes we'll be getting those that. And this is basically a result. So now let's just pass another image. Like, these are the test images we are having. Let's just pass this COVID 1921. This image, yeah. So here you can see the person is affected by COVID 19. This also model as pets. Now, let's just pass normal five image, and let's see what model will do when we are passing normal image, but it will output. See here, result is normal. And let's just pass normal 18. See, result is not. So basically, our model accuracy on the testing data is 99.56. So if you will pass thousand number of images, then in 995 images that will correctly classify. So the model accuracy, since the model accuracy is very high, that's why it is giving every time a correct result. So this is very good for, you know, like this we have done successfully. Now let's just plot confusing matrix because confusing matrix is very important, like how much false positive and how much true positive and everything you are getting. I'll explain that also. What's that? Don't worry. So for the confuson matrix part, let me re another markdown. Yeah, confusing matrix part. Firstly, we have to decide in which part we are creating confuson matrix, which part. So we'll create a confuser matrix for the testing dataset. Like in the testing dataset, how many images are correctly classified and how many images are wrongly classified. So let's just create for that. So we'll create a variable model pred, and model dot predict test test set. It's taking time. So, confusion matrix and this ROC plot is left. So let's just discuss that in next video. Till then here till here you have, I hope you have understood. Like, we have successfully. Firstly, we have augmented the images. We have pre processed those images. We have built the model architecture. We have used the transfer learning concept, and this this training part, we have done, we achieved a 99.56 accuracy, which is a very high accuracy. And with the help of those techniques only we are able to achieve. We have plotted the graph. We have successfully tested it on like real world four images. This video is getting a little bit of longer. So let's just discuss Confuson matrix and the ROC plots in next video. I'll show you there. Till then, thank you. 28. Project 5.3: Confusion Matrix Classification AUC ROC: Hi, welcome back, guys. So till then, we have predicted those, some test images with this like our trained model. We learned how to import like the saved model. We learned how to save a model. We learn how to train a model and those like everything we have covered so far. Now we were doing some plotting and now just let's move to confuson matrix. This is a very important evaluation matrix which were considered in machine learning and deep learning. So firstly, we have to draw the confuser matrix for our testing set like the final evaluation final testing set, we will be knowing how much images have been correctly classified and how much images have been wrongly classified and which images are wrongly classified. So everything will be knowing in this confuson matrix. So let's just plot that. So we have our test set, and we have our model named as M model. So mymdel.in Keras, like we have a function named as predict generator. So in that, if we'll pass this test set. So it will be predicting the output values. Initially I told you in deep learning or machine learning, we provide input and output. Like input, we are providing the images of chest x rays and output we are providing this chest x rays of normal or COVID 19. Now we are just providing the input images and we'll be seeing what our model is predating. So if we'll run this, so it is running. Let's just wait for that. It will take, yeah. So here you can see it has prited all the testing images like we were having total of 455 images in our test set, and for all those 455, it has created the value. Like the first class, how much possibility it is of COVID 19, images, how much possibility is of normal images. So every probabilistic, as I've told you, the softmax function outputs a probabilistic output. So it will tell the probability of occurrence. So if we are passing an image, how much probability is of this image of COVID 19 and how much probability it is of normal image. So we'll apply the Numbi argmax function, we'll store this in Wpread first of all. We'll also apply the Numpi arch Max. Now, what this armax function do? It's just simply round off the value. Like, suppose if we are getting value of suppose, let's say, 0.25, then it will round off to zero. And if we are getting value of 0.85, it will round off to one. So that arch Max function we need and we'll pass it along the excess one. So yeah, let's just see that. Let's just print pread here. Let's wait for it to finish first. So yeah, it is done. And if we see the i pread value, now let's see. The first image which is passed through the training like our model train model, it has pated as zero. Like this is of COVID 19 infect This normal. This of COVID. This is all normal. Now, how we will basically how we will classify, like how we draw the confusion matrix. So this is all the output level of our predicted. Like, the prediction has been done with our model. Now we have to do we have to know the original labels also, which we already know. Like, we already know this image is of COVID, this image is of normal, and this is what our model has predated. So let's just uh know that, that we can know the test set test set dot classes. Like this is original classes. Let's print that. So yeah. Okay. So here, one more thing we have to do. Basically, it is shuffling those data every time. And let's just do this here. In the test set I'll explain to you that why it is outputting like this. In this testing set, basically, we have to pass a variable shuffle equal false Now if we see wet again, we have to do this. Basically, when we create the image generator, when we create the taste set, it shuffles those images. So in the original image, firstly, we have this much of COVID 19 infected like zeroth class and this much of normal image. So we want in that order only, then we can compare those. So now if we see, yeah. So here you can see. Like, these two images, as you can see, is wrongly classified and this image also. This is wrongly classified. This image also. This is wrongly classified. And if you can see here also, this image is wrongly classified. Like this image was of COVID 19, but the model has told this is normal. And this is of normal and the model is told this is okay, COVID 19. So how we can know that. So here, confusing matrix comes into picture. And, firstly, like, we'll import this confuer matrix. This comes under Econ library. Will import confusion matrix. Okay. The spelling, I it. So yeah, we have imported confuson matrix. Now we can draw the confusing matrix of this. For that, we just simply have to use this function we have just imported confusing matrix, and we have to pass first the original labels. These are the original labels, which we already know. That image via pass is of COVID 19, that image a pass is normal. These images are original image, original labels, and then we have to pass what our model has predicted. So for that, we have throwed in pread. So we will simply print this confusing matrix. And we'll give one line space and then CM. So yeah, here you can see. This is our confuser matrix. Now, it is not very easy to visualize, so we'll visualize it in a proper graph using CBonn. So in CBonn we have a function called as heat map. Heat map. And here we'll simply pass this CM variable. And annotation will give it as a true. We want those labels also. And this is FMT, basically the color code, so you can use any here. So yeah, here you can see. This is our nice plot of confusion matrix. Now, what exactly is this? This is basically the This is your true label, and this is your predicted label. So 122 images, the model, like original value we know is of COVID 19, and the model is also saying it is a COVID 19. Six images, the model has wrongly classified of the COVID 19 L the model originally we were saying this is of COVID 19 images, but the model has said that, okay, this is a normal image. So this is basically your false positives. This is your model is saying that this image is normal and the like, uh, sorry, originally, we were saying this is of image of normal and the model is saying it is of COVID 19. So this is also wrongly classified. True, like false negatives. And these are basically your model is also saying normal and initially we were having our label as also positive. So this is basically your confuson matrix. If I will explain you that confusing matrix. So yeah, here you can see a nice diagram of that. So yeah. This is basically your actual no. That means the model is actually COVID 19 positive, and the model has also predicted COVID 19 positive. This is a model is saying the COVID 19 positive, but the model is originally we were saying COVID 19 positive, but the model is pret in no it is not normal. So this is false positive. This is true negative. Like the model is also trying COVID, the normal normally we know this is COVID so this is true negative. This is false positive. Like this is wrongly classified of first class. And this basically the model is saying, Okay, this is normal and the actual image. So, okay, actually it was normal, but the model I said, no, it is of COVID, so this is also wrong. So this basically is your wrongly classified and this basically rightly classified. So there are a lot of, like, formals of evaluation matrix, we say, evaluation matrix. If you see here, the formula, yeah, the accuracy. If you will calculate this is true positive plus true negative plus t by two positive plus e negative plus F false positive plus false negative. If you'll calculate using this formula with the help of the configur matrix, you will get exact same value that 99.56. So here is your configure matrix. One more evaluation matrix comes under Eklon' your classification report from escalon dot matrix Import, classification report. And in that, if you pass classification underscore report, you have to pass your true label first, then your pre trade label. And here also, you have to pass some target names. And here you simply write first target is was your COVID 19 and second, was your normal. Okay. Normal. So yeah, here you can see. COVID 19, the precision was 0.98. Recall was 0.95 FBN score was 0.97. The normal precision was 98 99, and therefore 499. Total COVID 19 images in the testing set was 128 and normal was 327. And the total images was 455. Here you can see also. The original total number of images in the testing data was 455. So this is here, and the accuracy was 98 F one score. And yeah, everything you can see from here. Now, there's one more curve which we plot generally was AUC ROC curve. So let's just plot that also. Uh AUC is basically your area under curve and ROC basically receiver operating characteristic. Let's see. I'll just quickly write of function here. First I'll import some of the libraries. Still down. Reprocessing. Import label binarizer then I'll implode some more libraries here. I'll import ROC curves. AUC, ROC, underscore AUC score. So we'll import those things. Now I'll write a function. You don't need to completely memorize this function. You can just copy praise from here also, or you will get in Net also. It's just I'm explaining you here. Now with the plotting part, just write XLT the subplot and we'll just need one image here. So we'll pass one comma one. Figure size, we'll put it as 128 as usual. Now, the function for ROC. I'll write a function for ROC. It is like I test. Wiped. Macro. And then we'll create object out of this label binariser. I'll just copy paste from here only. We'll create a instance of this function, and that instance will fit basically perform B dot transform pred we'll be giving b dot transform again. We're basically transforming both the sets according to the ROC plots. So yeah, now we'll loop into that. Label. These are all the values we have inputted earlier target value, the ROC curve, basically. False positive rate, C two positive rate, and the thresholds, we'll be getting with the ROC curve function. That will get with IDX. Sip and we'll convert this into It basically. And the red also will say same thing. IDX. Now, we'll plot P we'll convert this into string format. And we'll round through two decimal places this float value. It is done here. Now we'll get back in the back out of the loo, and FPR E minus and the label here is random guessing because like ROC plot, the 0.5 value is of random guessing. I'll explain to you once the curve is plotted. And then we'll return those scores the score score with the Y test and I pread value. Average is basically your average only. So yeah, we'll return this. There's one error. Subplot. Plt dot subplots here basically. Yeah. Now this function is successfully created. Now we'll print the ROC and AUC score that same function we are having here. ROC AUC score. Now we'll pass the function function name is ROC and we'll pass the value of white test and Here, we'll simply write for basically no confusion. We'll write white test and Whitebead only here. It's small because somewhere it was capital and somewhere it was small, so it is a little bit confusing. Here we are having white bread and white test as capital Y. So yeah, it is perfect. Now, we'll just print the score. Okay. It is giving a error. Oh, wait let me see once. Why test and why bread we have profit value. Let me just verify. Why test is perfect and why bread is perfect. But here we are getting an error in think of shouldn't give error, but it is giving an error too many index array in one dimension, but two more indexed. Just like Just wait for a sec. I'll get back to you on this. He, welcome back, guys. So, there is some error in between coding. So I have resolved that. And yeah, so here you can see this is basically your function for this ROC curve. And here I have written that line, C ROC. And here we have written those ROC only. So yeah. This is basically your ROC curves, and this is your basically AOC, this is called as Ada curves and These are some of the evaluation matrix which we need to perform while evaluating the deep learning model. Here, ROC and AOC are not that much required, but in some cases, where the class is imbalance, suppose we are having a COVID 19 image of 200 only, and the normal image of 20,000. So there is a lot of class imbalance here. So at that time, the accuracy must not be very high, but we will measure our results with the AOCRC score. So you need to know that. It's just like you need to know that and yeah. So here is your overall code for ROC, and this is basically we are calculating for ROC and AUC score, and then we are plotting here also. This is your random guessing, and this is your ROC curve AUC curve and this is uh, true positive rate versus false positive rate. So overall, we have done enough of the plotting and we have completed our overall modeling part. So from the start, I'm going to brief you once. Like, firstly, we have imported the libraries, and then we have done the data pre processing thing. We have resize our image into 128 cross 128, and here I've explained to you, why the 128 cross 128 is not affecting the accuracy much. In some cases, it will affect, but generally 128 common 20 is considered standard size, or you can also take 224 cross 24. You can also take 256 depending on your hardware requirements. And then we have done the data augmentation part. Why data augmentation is very important in deep learning. I've explained to you, we have done the model building part. We have completed done our oral process with G 16. Now in future anywhere anytime if you need to change your model. So suppose if you want to use inception V three, then you can see Inception V three also everything is same as we have done in G 16. So you just need to change change the code at two places. Here, firstly, you have to put inception V three, and here you have to import first inception V three from the Keraso application. Like here you can see, kerazod application. And with that, you have to just import wait wait. Let me show you. Here you need to import inception V three from the Keras underscore application. So yeah, it is imported. And just here, you have to change the inception V three, and then you can train the inception three on that. Just two places you have to change. Like, firstly, you have to import the model you want to use, and then at the base model, you have to change. Rest the procedure. Everything will be same. This is the power of transfer and you just everything has already been trained from scratch with big big dataset, and you just have to leverage those weights. So yeah, here, we have done the modeling part. This is the model summary. We have trained the model and we have evaluated and analyzed the model by seeing the loss and accuracy curve. We have done some predictions by first visualizing those images, and then we have also saved and load the model, and then we have done the prediction on a real testing dataset. Then we have plotted the confusing matrix for that, and we have also learned what is true positive, false positive, true negative, and false negative. And we have seen the classification report of our overall training model. We have also plotted the ROC curve. So here, like we have done with the model. We also have our model saved here model.h5. In the next video, I'll explain you, we'll just build the web web application. I suppose anyone want to use your model and want to predict whether an image is COVID 19 or normal. So you cannot simply give this model.h5 file and and say him or her, like, key just like predict from this model. I boltin, you need to just play it, so you cannot do that. You have to deploy it somewhere. Like, you can deploy it on any mobile application or any web application. And then from there, the user will simply upload his or her escrimages and he or she can get output. So we will deploy it overall our model train model in a web application, and in the next video, we'll be building that. Fill them. Thank you. 29. Project 5.4: Web Application Flask Deployment COVID 19 Detector Web App: Welcome back, guys. So in the last video, you have already seen how we have built our model and the techniques, different techniques, the data augmentation and the transfer learning we have applied, and we have successfully achieved the 99.56% of testing accuracy or we can say the final accuracy. And we have also gone through the different evaluation matrices which we generally use in deep learning. And we have also seen like the model has successfully patted all the four images correctly and now, as I've told you, like, if someone else want to use your work, like in this deep learning or any domain, like if someone else want to use what you have done, like the model you have trained or whatever you have done, they just want to use your model and just want to, like, credit the same images without their effort. Like, suppose you are working for a company and the company told you, like, Oh, like this, pandemic has came and, like, just give me a solution where I can just, you know, upload the chest X ray or any X ray images and I can get an output as COVID 19 or normal. My model will basically help me. So just give me that solution. So there you cannot just simply provide, like this this.h5 file. So there you cannot say, take this H five file and you can just load the model and you can just preprocess using OpenCV as we have done here, and you can, like pred whether the person is affected by COVID 19 or result is normal. So you cannot do that. There are what they expect from you is like you deploy this model somewhere, like deployment generally means taking taking your work to the sharing your work with others. So the deployment means, like in your mobile applications, also, there are many mobile applications which are using machine learning and deep learning techniques. So in that mobile applications, like somewhere as someone who has created that application, he has deployed those models trained models into the application. So the deployment means that you are sharing your works with other. So the others can use it seamlessly, so you have to deploy it either on a web app or an Android app. Now we are in this feedm choosing a web application. Why web application is because web application is more versatile than a mobile application. Like for mobile, you know, you have to separately make it for Android or you can say IPO and IOS. So mobile application is the website you can open anywhere, like in Android devices also or mobile devices also. So that's why I have chosen to deploy it on web application. Now in web application, there are basically three things. This is basically your front end. The front end is only visible on the client side. Like the client will just open the web page and it will just upload the image and it will see a output. And there's a web server in between and application server in between. And there is also called as your back end. Back end is basically like in our case, we are not using any database, but in general, like every back end, there is a database. Like, suppose you are ordering some stuff from you are ordering some, let's say, anything from Amazon. And in Amazon, basically, there is a front end side. Like, let me show you for example. Basically in Amazon or any website, there is a front end side in which web pages like it display you like here, you can see different orders and every categories and everything. And here just you can add in your order list, and then you can, like, shop from there. So basically, this is your front end. The order you are placing and you might have noticed one thing like in Amazon or anything, they have order history and every payment details and your card has been saved. So that is basically saving in your back end database. So for that, we can use database. In the COVID 19 detection, also, we can use database, like we can store those chess taxa images in our database, and the result we are getting with the person identity we can store in future, the person can also see those history, but here we are not using any database. So for the back end, like we have in our project, we have that model. Like basically our front end will send image into the web server. The web server will interact with our back end and the back end will just like preprocess all those image and, you know, like secure predict those output and just output output back to the web server, and then web server will post it in the client side, the front end side. The page will simply display the overall prediction and whatever content you want to do. So since this is a project of artificial intelligence, so I'll be only teaching you the back end part like the back end part I've already taught you how we are training model and the application server, how to create a server of, like, machine learning or deepening model that I'm going to teach you in this video. Front end pass, like how to create a website, HTN CSS thing, I'm not going to tell you in this video. I'll just go through with that. So in HTML, as you know, there are three main backbones of in web development, there are three main backbones, HTML, CSS, and JavaScript. So here you can see, like I have created a simple web page which is like COVID 19 detector, and you can see, yeah, the title and the overall page is like COVID 19 detector. And then I have put a button here. Like, first of all, this is basically your upload file like image upload. And here you have button to choose an image, like, to choose an image. And in this, I have given three categories, like these three categories are mainly used in the image format like PNG, JPG, and JPEG. So that these are basically, when we are choosing an image and uploading a file, if these are the images which are being uploaded. So our back end, our page will accept that otherwise it will reject if we are supposed uploading any zip file or, you know, any PDF file on any music MP three file. So it will not accept that because obviously the model cannot run that. So then I have created image preview button, image preview class, which will basically preview the image upload it. Like the image we have uploaded, either it is of COVID or of pneumonia normal image, it will just preview that. Then I have created a button where when we press that button, it will run our overall back end. Like this is basically your main thing. Whenever we press the button, it will interact with the web server and it will interact with the back end, and then it will show the output. And at last, I have shown just the result, what's the result. In this CSS file, it is basically for styling, like the overall page I have styled. So CSS, you do not need to know much about that. You can just if you want to deploy your product or project, you can just simply look at my code also, or you can select take any code from Internet. Like one website I can tell you Yeah, this website here, you can get many of the HTML, CSS, and Java Strip templates where full working app is there. Here you can see. This is a very useful website. Suppose if you want to get any login page. So if you search, sorry, I misspelled that. So if you want to search for any login page. So, here you can see, you are getting different different suppose looking at very cool login page. So as soon as you click that, you will get all those HTML, CSS and JS code from that. And you can just simply download this project here, export, export dot file, and this will basically download your template. So you can select any favorite template from here, and then you can deploy your machine learning models there. So this is or you can just simply look at my code only. And JS is basically, as you know, HTML is like backbone of your if it is a display site, CSS is basically for styling and JS is for functioning, like the overall functioning of your website. Like, suppose in Amazon, this is what you are looking at just HTN and CSS. But when you will click this button, it will suppose I'm clicking this button, fresh. It will redirect to me in a new page or some times you have seen suppose in Firefox, you have this button. I will, you know, select it will show our, like the functioning of this button. So these all functioning happens in your Java script. So here you can see every button I have told you in that base and index template, it has some or other functionality here. Like this image preview, it is also Java function. Like, it will feed in for some seconds input file. Like every function, it is there. This is basically your upload file. This is your form data, overall, and here you can see, yeah, the button dot pride, it will basically predict from it will take basically this function. Ma prediction by calling API. This function is basically fetch the data from your back end part. Now, I hope you have gotten some idea about how the website is working and how the server is working basically. Now let's move to the server. Like this part already this part, back end part we have created, now let's create the web server. In machine learning or deep learning, there are many servers, some of them I can show you, one is fast, one is fast API. One is I can switch Jango like, these are some of the web frameworks which is available in Python, and we use these frameworks to deploy our model. Like, Jango it is, like, very robust model, like very robust framework in Python. Many of the people generally use. In fact, one more interesting fact I want to tell you, like, the Instagram you use that is basically built on the JangoFrameworg. The FAST API, it is basically introduced recently. Like it is not very old, and it is basically an upgraded version of PAS, but FLASK is like more like the most used web server, I can say. Like in machine learning or deep learning when you are deploying your small small project, not on the large scale. Now, what does mean by small scale or large scale? Like, large scale when you are building something for the industry where like millions or billions of people is going to use. So there you have to, like, you know, deploy it on a robust framework. For that, you will use those basically NodeJS or you can say that server. Like NodeJS is also a server. Like, basically, we are dealing everything in Python, but no Js is basically JavaScript server. So yeah. This is a very robust framework. So in company, we can build, like in this. But for our project to deploy, like simple machine learning or deep learning project, we can just simply use FAS. FLASK is very easy to use and easy to use, and it has like WS, GI toolkit, and Jinja templating engine. Like, it's all like you will get to, like, know after some time when we'll actually build this using flask. So this basically is your as I've said, this is basically your web server. And that web server we are creating now using FAS. And the FASFAS is like it is known as microframework, and it is very lightweight and easy to deploy. So let's jump into actually building the code. Till now we've been working on gebra notebook. Now let's work on VS code where we'll actually write some Python code. So yeah. So we'll create two files. One is app dot PI, and let's name another file as covid dot PI. Now, this app dot PI is basically your overall FAS code, like the FAS code, like running the code. And this COVID dot PI is basically your back end where the model processing will go. Now here, I'll import some of the libraries. Import pi P. Firstly, the first step to get some predictions, we have to import our model. We have to load our model. The model we have previously trained, we have to import that. So for that, I will just like model equals root model. And we have to give path. Now, let's jump here. This is our web app. These are the two files I updated just now. In this our static code like CSS and JS, and are temporary base and index file. Now, if I'll open this index dot HTML, it will simply delete this. It has no styling and no back and running. So when I run whole code, you will see now this is our model. Let's put it in a separate folder. We'll name this folder as weights or I can say train weights. So yeah. I the train weights, no, no, I've actually created it in template, so weight. Yeah, here we can see. Like in the train weights, we are basically having our Wall running model. So I'll simply pass that path here. What was that in train weights model.h5. So yeah, here, I have passed. Now let's create a class. You must be aware of what class is an object in programming. Now, this is basically in any Python classes, firstly, we have to create a t function. If nothing will run, then it will simply pass. Suppose none. If the output is nothing, we are calling the class and we are passing it nothing, then it will simply pass. Otherwise it will show error, so it is necessary. Now let's create any other function. In that, I'll simply create model underscore. Predict. I'll pass two things herself, we have to mandatory pass it is no This is compulsion. Basically, we have to pass and we'll pass one more thing image path here because for the model to predict anything, we have to pass an image path. Now, first thing, we have to load our image. Previously, we saw this image dot load Image. Load IMG. Again, I'll not repeat that same thing. I'm sorry, image, thought load image. Okay. Yeah. So in here, image path is the first thing we pass. Also, one more thing, like here, we'll pass HDR. Like the image path we are sending, sometimes it may be of like any other data format. So firstly, we have to convert it to the Python string. So image path I'm passing here. And another variable which we will pass is target size. And the target size the train model size you remember was the 128 cross 120. Remember, here, if you put 256256 or 224 cross 224, it will give an error because the same path you have to follow. Why? So, because our model somebody tells us it will take input as 128 cross 128. So it will not accept any other input because the model is trained according to that. So it is necessary thing. Now where this function is coming, you have already seen in the last video, we have done some predictions, and here you can see this thing here you can see. We are just writing this a dynamic variable. Every time the path will not same. So yeah, we are writing just in a dynamic thing. Next thing we have done is to convert this image into that array because the neural network will not understand an image. It will take anything in it will understand anything which is in numbers. So we have to convert our image into an array. Next we have done, basically we have expanded our dimensions, so NptEpand DIMS and then we have to pre process input X. And then we have to predict our classes. These are things I've shown you in previous video, so it might like it is repetitive only, but we have to do this through Ga prediction. Classes equal mode or pertodimg data and in the result, we are getting in teser value of classes zero comma zero, and now if the result is equal equal one, as I've seen earlier, we will not print here anything. We'll just return. I'll explain you in further video why we are doing that person. Perfected by COVID 19 and result is okay, sorry. Result is normal. So we are done with here, D are done with everything here. So here you can see if result is go one, the person will this we have already seen in previous video, the same thing I have done again. So firstly, we are converting our image into the array. Then we're expanding the dimensions because we need that one more bracket here of array then we are preprocessing the input, like the scaling and everything. Then it will predict the model model we load here, it will predict the image data image data it is getting from here, the function. The function we use in that app dot P. We are just creating a function here. And then the we take the integer value of first class and the result is one, then the person is affected by COVID 19, and the result is normal, it if it is zero, then the result is normal. Now, why we are returning thing here, like why we are not printing. So basically, in that previous case, we need just output here. But in our web app, we need the output in our web app. So basically, we need our output in the app dot P the FAS app. So that's why we are returning. When we'll build the FAS cap, then you will get more clarity about that. Now, let's jump to the FLASH code. So firstly, we'll import from FAS, we'll import floss library, the redirect or you can say the request and the render template. So la this is basically your flaws cap. This is request basically basically, there are two things. One more thing I forgot to tell you. There are get request and post request. You must be aware of that and get sus post. Yeah. So in the G request, basically, here you can see in the G request, basically the client will get client will upload an image, and it will post and request to the web server. And the web server will now post the request to the application server and from there, data will get the client will now get the request, and this is basically a get and post request. So here we are going to use here you can see both transfer data from client server to Shu Protocol. Get carries the request and post carries the requirement in message body. So yeah, that's why we are using Render template is basically after each time you are getting request or getting an output, you have to render that on the front end, like the web page. So that's why we are getting render template. Some more thing we'll import from here, like COVID PI, we have to import this run model function. So from COVID, import this run model function. Now we'll just create a flash cap. Let's create a flash cap. This is the syntax to create a flash cap and here. Thought run. So this basically creates your overall FAS cap. We do not need to do anything further. This basically created your server. I'll just run this code. Let's see. A model is not defined. Oh, let's just import that first. Yeah. C, the server is running. Obviously, it will not display anything now, but the server is running. The value equation of the server, but you go manually, so please check your spy basically, it creates a server here. But since there's nothing to display, so it is like outputting error value. So let's just stop the server Control for stopping the server, you need to press Control C. Now we'll create a home page, how to create a homepage U app or route and define return. See here the render template function will be used. And here you will have to pass index or HTML. The index, the in web page we have created will render that. Let's go to let's run this code. Now I feel refresh, see, the page has come because initially we were not rendering anything. We are basically calling the server, but we are not passing or getting we are not posting a request. So here, you can see, we are entering a template. And this is basically a template. Obviously, it will work, but it will not well create this IFelK it will go into infinite Lou. I will not do anything. Basically, it is posting the request, but it is not getting anything back. So yeah, let's stop our server for now and let's proceed further. Now let's create basically our homepage is working, but that predict button, after giving, okay, it will not work right now. After clicking this predict button, it is not working. So let's make that predict button functional. So for that, I will create another route. And in that method, I'll put both cat and post request as a method. Yeah. Here we go. Now we'll define a function here. This upload function we are defining here. And basically, this will when we choose, this will successfully upload that image into that COVID basically it will send the uploaded image into that COVID 19 and it will basically save in a directory also. So if request, which we have inputed earlier, request that method equal equal post. If the request is basically post, then you have to save your file. Basically, you have to save your file. Like I choose when I click on Choose and I have uploading the image, you have to save this file into a local directory. Then only the model can run. So firstly, we are saving our file request files, I'll show you how to save a file. Yeah. Now for that, the file is being stored in F, but to save it in the directory, we have to do this. This is basically getting your file from the post request. With that, you are getting the file, the post request. Now saving your file to the we have to okay. So we have to define the OS because all the information about computer directory we can get with the OS. So with the OS OST path name, this is basically we'll get the par directory name. So yeah, we're using that only. Well run this file. So it will give the base path. Now, I will give basically the base path where I am currently right now. So to upload it in a separate directory let's create one directory first. Let's create a directory here. It is known as let's name it adds uploads. So let me let us save those files we are getting from the force request to the directory uploads. For that, I path. Os path dot join I will join to pass. The base path we already know, and in here, we are joining this uploads. Basically the folder we have just created now. In the base path, this path we already know this path, we already know in that we are appending this upload part. For current secure file name, what is that name of file we are saving our file with? That is basically your F file name. Secure file name I haven't inputed yet. Yeah, so basically input that because it will show other wile from your tres file name. So this is a function to get the file name because in the upload directory, we have to basically save our file and with our file name. So we are getting that image, but the file name also we want with which we have to save in that directory. Now, this just click F th save the file path in this way of filing. So this is basically we are creating the base path first. Then we are appending that base path into the uploaded file and we are getting the final file path where we have to save our file and we are just saving this file. F is basically the file you have gotten from the post request. Now let's just print this file for now. Then you will get some idea. File path. Let's do that for now, and let's just run the server. If I'll upload this as soon as I predict the file. It is no, it hasn't uploaded. Let let me just check. Everything is fine, I think. Okay, we have to This is basically function, so we have to return anything. As everything, I guess is fine. We are just reading the file base pass and then uploads and secure file ath file name. So arrest everything is fine. It should work now. Let's try again. No. Let's proceed further. Let's see. I hope I guess this is not working right now, but it will work. Let's proceed further for now. We're inputting the right library, I guess, secure file name. Yeah, everything is fine only. Okay, this is not any file name. This is index. Sorry, I'm sorry. There are by mistake, I have put another equal to here, but it's not an equal to. I'm sorry. Now, let's try. Now we'll upload the file and we'll predict, then Mm hmm. Yeah, here you can see. See user Desktop Web App uploads and in COVID 19 GPG, it has successfully saved our file here. So this is all we want. Now this is running, and now our file is saved in a directory. Now let's just predict and return that output. Let me first stop this server. Let's just create a result variable. To predict. You know everything in the run model function, basically, this is the run model function and from that we are creating model dot pad and we have to pass the image path here. So under scoePath here is our file path. This is our file path. Now I've shown you what printing does, so let's remove this from here and let's move the COVID nine. Yeah. So the result we have already gotten here and let's just return, print this result here, string result. Now, one more problem in the COVID nine COVID dot PI, I've created all those functions, but I haven't imported those functions yet. So let us import that as well. Like, let us import directly from the path here only. We have imported everything here now. So these all functions I guess we want. These are functions we want now, it shouldn't give any error. Yeah, that's everything is fine. Let's just run this. Yeah, see. First it loading the model now it will take some time. The first is loading the model and then it will make the model to work. See. Yeah. It's a server running up. I feel refresh and it will choose COVID image, and it will create predict. It is again like loading Okay. Model is getting an error like here. Run model model dot pred, missing one required poisonal argument self. Shouldn't give any error. Wait, let me check. I guess we have to pass every time. Let's just run. Okay. Yeah, let's check again. It is running as perfect, it is basically loading the GPU. Initially, it will take some time. Every time you will see the function either ****** and then we yeah, see here. We have gotten a result, result is normal. And it is showing a lot of errors because the view function did not return a valid function. That's why, if you remember, I told you, don't we don't have to print anything. We have to return a value. And here we are repeating that mistake. We are printing the value. We are returning, we are not returning anything, so it will go into infinite loo. So let's just not do that again and let's just return this value. STR of result. Now let's just perform another try is again running. Let's just predict this image. S here you are getting the output. Person is affected by COVID 19. Here you can see if I upload another COVID image, the person is of by COVID 19. If I upload a normal image, the result is normal. If I upload another normal image, the result is no, here you are getting you successfully built your web application. Now, also one more thing I missed there. Like you have noticed one problem. The first time we are clicking on that predict button, it is taking a much longer time. So why that is happening? Because C, I'll explain you with this cost manager. Let me open my task when I do. Yeah. CPU is already 100%. So yeah, this is our memory, in that our overall data is there. And this is our GPU memory. Like GPU has a four GB of memory, every GPU has some kind of memory. And this is basically a GPU memory. So what deep learning what in deep learning we do is, we are not performing any operations in our RAM. We are performing everything in our GPU memory. So the first time when we run the model, it will basically copy all those data in your RAM through the GPU. That's why I, if you remember, I've told you we use the concept of bass size. Because in the GPU, like the normal memory, we have the memory of 16 GB, but in the GPU it is limited. It is only four GB. So we cannot fit our overall whole data through a GPU in a single time. So we use that batches time. And to activate the GPU ones, like to load the GPU ones, it will take initially some time. So for that, we are getting a delay of only the starting prediction. So let me close down this server once and let me show you show you practically what I'm saying. Yeah, the server is closing, and here you can see the GPU is free. It has only been occupied one GB. It is almost free. So let us start a server first. So yeah, our server has started. Now, let me show you both the things side by side so we will understand better what I'm saying. So if we will choose an image, suppose let's say COVID 19. So as soon as the server has started, let me show you again. I missed it. Sorry. C. The GPU is free right now. But as soon as the server is starting the model here you can see the tens of flow activity. The model is loading. As soon as the model is loading, C, the GPUs go high, first time. And when you are doing this, suppose choose COVID 19 image, whenever you are first time, when the first time you are predicting, C, it will take a longer time. Like, basically, again, it will start those GPU computations and it will activate that GPC. Here we get result. And then next time, C, as soon as we predict will get result. Normal, as soon as we click predict, see, you get the results in milliseconds. You are getting very faster results. S. This is what I'm saying the concept of GPU and CPU memory. So this is your overall project, and with this, we end this project and see here the folder we have created right now, upload. Suppose I delete all those five. And again, I'm starting this server. Suppose I click COVID 19 C, and as soon as I move to follow C, the image is again being saved. What is happening here, basically, this function. This function is basically saving your image to the local directory first. And then the model is running on that local directory. So this is what name. So this is your overall project, we created this application server and the already back end we have created and you have successfully achieved 99.56% accuracy in the COVID 19 detection. That means if I'll give you a hundreds of images, you will classify 99 images correctly. The model will classifying 99 images correctly. So this is a great achievement because there are so many research people like I I'll just search on Google, COVID detection research papers. See, there are so many work is being happening in this domain. See. COVID deep learning detection and diagnosis of COVID 19 using radiologis motivated mortalities another paper deep learning based detection, see this. See this. Deep learning based detection of COVID 19 using lung ultrasound image. So basically, they have created a COVID 19 detection application using the ultrasound images. We are taking chest X ray into consideration. They are taking ultrasound into consideration. One more journal like RC, this fast automated detection of COVID 19 from medical imaging convolutional networks. So as soon as the COVID pandemic has came, there is lots and lots of, like, research is going on the street, and everyone was detecting C. Here, you can see the F one score 96%. We have already beaded that because in the classification report, if I show you, we have gotten 97 99. So yeah, we have gotten better accuracy from them. And the accuracy also like 99.56, hardly anyone achieve those accuracy. So with the help of transfer learning and everything, we can achieve those. Yeah. This is your overall application. Now, this is basically hosted on a local server. So there are a lot of deployment website like Hiroku or you can say Netlify in this video, I'm not going to show this, but suppose Heroku is a cloud platform, Netlify is also a deployment platform. So in that platform, you just have to, you know, upload all this junk of code, like this all junk off code, and you just need to ship your model, this train wights that's model.h5 waits, we have train. You have to ship this along with your code. And this will basically create a link, like this kind of link. Like the Amazon, we are getting a link that Turo amazon.in. So you'll get something link like that, and that link you can share with any person in the world, and that person can like, use your COVID 19 detector and classify the COVID 19 and normal images. And like your model is already been shipped. So yeah, this is the end of the project. And thank you so much. 30. Project 5.6: Bonus Video Custom CNN Architecture: Okay, so welcome back, guys. We have already done the project on this COVID 19 detection using convolution networks, and we have successfully achieved 99.56% of accuracy, and we have created a web app using that also. But in the middle of the PDO, like I've told you once we have used transfer learning. What about the normal CNN architecture? Like, if we just want to train our model, by using any custom architecture, which we are building, basically, in that like no other work we want to use. Like, we want to publish our own work. So what about that? So that I'm going to, like, teach you in this video. Like how to build a custom architecture, like architure of your own. You can do experiments with that architecture, and you can still achieve a very good accuracy. So let's do that in the video. First, I'll upload I'll import some of the libraries. Like, let's say, out layers, I'll import, firstly, c2d layer because as I've told you, convolution layer, like convolution in the CNN, basically, there are three things convolutional layer, max pooling layer and activation layer. So let's import all those things first. Max Polin two D. Now, what is two D and what is three D? What is a two D and what is one D? Like, in cons basically we have both one D and two DLers. But for the image data, we use TDLar. And for any single dimensional data, we can use one D in the signal processing, suppose ECD signals. There are many research work going on in ECD signals, like the detecting sleep disorder using ECG, detecting mias using ECGs. So in that, the data is one dimensional. There is no three dimensional image metrics. So in that we can use c1d also or max pulling one D also. But here since we are dealing with the image data, we are using max pooling and convolution in the two D format only. Then we will import activation layer and also, building the Keras models, we have to import the sequential. I'll show you what is that. Sequential. So this is basically, I'll show you here. This is basically a keras API, like a sequential class in which we create a model and we add up the layers by layers, layers by layers, and this creates the model as well. Like this is sequential class. This is basically stacks the layer as you have seen that PGG 16 architecture. So here you can see, this is stacking layer by layer, layer by layer, layer by layer. So that's stacking we perform using the sequential. So yeah, we have imported that, let's import this. Wait a second. Max. Okay. I misspelled that, Max pin two D. Okay. Now we need that image resizing like 128 plus 128. We need that the data augmentation also we need, and everything we need except with this WG seen. Here we do not need uh, this also we do not need from here, we'll start your work. So here, basically, we'll just I've just removed the pre trade model, the VG 16 from here and let's just build our own custom model here. I've run all those things. Firstly, we'll create a object of the sequential class. Yeah. Now the model is created with a sequential API. Now from here, we'll start appending the stacking process, appending layer by layer, layer by layer. So firstly, let's add model dot. Add firstly, a convolutional layer of let's say 32 neurons. Three is your kernel size input Shape equals What was our input? 128, ro, 128, three. So this is your basically kernel or even strides. Let me show you this also. Yeah. So this is basically firstly the filter. The number of filters we want, that is 32, basically the number of neurons, the kernel si, the stride, and everything, these values we have to put in your convolutional layer. Then we'll just add an activation layer. As I've told you earlier, wherever there is an convolutional layer, we have to add an activation layer. And the activation layer also I've told you in the hidden layers, we will use ReLu activation function. Now let's just add a max pooling layer. Max pulling to D with a pool size. This is the parameter we pass in the max pooling layer. This is basically the pool size. Let me show you. Yeah, this is your pool size. So max pulling, we have to provide a pool size. Like in the CN, we are providing the kernel size. In the max pulling, we are providing the pooling size. Let's add one more set of layers. Let's say this time we'll add off 32 neurons, one more convolutional layer. 64 filter size, let's say, the kernel size will get three for three only. And the kernel initializers, Well performs. Or let's just, let's input that also. So this kernel Ishier is basically initializing the weights like randomly, as you know, in neural networks, the weights are randomly initialized. But these are basically the initializer, like, let me show you here only. Kernel, el kernel, kernel initializer. So these are basically weight matrix. The different weight matrix we want to initialize. So you can experiment with all those parameters, you can take different number of filter, different number of strides, differ kernel size, pulling size, hey uniform, you can use somewhere something else. You can experiment with all that. Then we'll just copy this activation function here from here and we'll copy this max pulling also. Of course, I see. Then let's suppose here this is our feature extractor. Let's suppose we have extracted all of the features successfully that obviously we can see in the training procedure how well it is performing. But let's just ignore for that. And let's just flatten all those layers. So a flattened layer. Now, as I've told you, this is your feature extracting layers, like the feature extractor, and now we'll add the classification layer where all the classification will be performing. Let's just add a dense layer. Of let's say 64 neurons only because we do not have very much larger data set. We are only classifying between two classes, COVID and normal. So in the hidden layer, as I've told you, we will use only ReLU activation function. It's not compulsion that we are using Lo activity. You can use TNH or any other activation also, but Lu is more recommended in the hidden layers. Sorry, drop out layer, I'm adding to basically prevent the overfitting. Now at the last, now it comes with the last part of the model, we'll add dense layer of two neurons, which we have done earlier also. And the activation function here, we will not use ReLu. We'll use softmax activation function. So yeah, this is basically the end of our modeling part. Now, sorry, kernel spelling I have misspelled kernels kernel. So yeah, successfully done. Now let's see the model summary. So yeah, wait a second. Yeah. So basically, this is our convolution layer one. Basically, this 126 you are getting because of 120 is getting kernel with three cross three. So don't worry that. I will get input shape as 11108 only. Now activation layer, then a max pulling layer, then again, a convolutional one CNN, then another CNN, and then we have flattened layer and 57,000 features we have extracted from here. Then we are just flattening and we are just applying dense layer with a relu function and then dropout layer to prevent the overfitting. And then again, the last dense layer to just, you know, classify all those features into a COVID or a normal image. Now we'll just compile Armond and rest all the steps will be the same. Let's just train it for five Epo. Let's see how well it is performing. Here you are in the VGG, we have gotten an accuracy of above 94%, I guess, in the first epoch. Now, let's just see how well this custom architecture will perform. Just wait till one epoch, then we'll proceed further. We can use you can experiment with these architectures anytime, you can just you know, add more number of layers. You can increase this neuron value. You can increase this or decrease this dropout value. If you feel like there's no overfitting, so you can decrease this dropout value. You can add more number of CNN basically this convolutional activation and max pooling layers. You can increase this filter size or you can experiment with all this. This is all like how appropriate it is working. This comes from experimentation only. As you will experiment, you will build a robust architecture only. So basically, after end of one epoch, we are getting an accuracy of roughly I'll say 89.8, roughly 90%. And with the help of transfer learning, we have achieved an accuracy of 94 in the first three box. Let's just see what's the validation accuracy. Oh, validation, we have gotten 94.73. So yeah, it's pretty nice. It's pretty decent. Like we have added so many layers, that's why it's performing much more. Well, if we do not add this many layers for feature extractor or this many layer for the classification, then it might not perform well, but here it is performing well enough. But in many of the cases where we have large dataset or a large number of classes, the transfer learning is much more recommended. Here you can see in the first EPOC only, we have got an accuracy of 94. And with the second Epoch, we are getting like roughly around 99 above. And with the help of customs CNN architecture, we are getting in the first EB 90%, and then it improves still like 96 roughly. I don't know where it will go, but it is like 96%. So I'll just pause here and I'll wait till the training finish. So I'll get back to you when the training finishes. So here you can see, guys. I have trained the training procedure is completed, and we have achieved an accuracy of 97% roughly after five people. And with the VG 16, I remember we have achieved about 99% at the end of five. So in this architecture also, if we train it further for more number of epochs, then I guess we'll achieve the same accuracy as VG 16, but this is the basically power of transfer learning. After two epochs only, we have achieved above 99. And after five epoch we are achieving only 97%. Let's just test it on the test data first. So it is 97 98 So, yeah, it is basically roughly around 97 only 96.392. And with the gi Gi, we have achieved 99.56, roughly 3% more accuracy than this. And it has taken almost same amount of training time and the like same number of epochs we have trained. Now, if we'll save the model ah five, one thing you'll notice here strange that this model size is very less like 40 toMB because in the VDG, we are having 16 layers, like 16 layers we are having and here you can see we are having this number of layers. Like this is basically counted as one layer only. Like one con, two convolutional, dense activation one dense dropout and tendens. Like only four or five layers we are having. So the model size is very less. So this is a good part of the custom training. Like while shipping your model or while uploading it somewhere or deploying it somewhere, it is much more easier. That's why in industry, because in the industry, people generally focuses on the speed also. Like, here we are just focusing the accuracy, but people generally, focus on the speed and the shipping cost and everything. Like, as the model size will increase, the cost will also increase. So yeah, here, you can perform everything and you will get the same results. So yeah, this is basically done. We have successfully built the custom architecture and we have trained on that and we have plot the graph, and I will do this also, it is testing image. And if I load my model again and test this, yeah. So see when we are inputting the normal, it is classifying it as a normal image and let me just input COVID 19 positive image. Okay, so yeah, here you can see. Here the model is misclassifying it. I have inputted the COVID 19 image, and it is predicting it as a normal. C. This is basically power of transfer learning. With the help of transfer learning, we have classified all those four images successfully. But here, the I'm inputting the COVID 19 image and it is classifying it as a normal image. So yeah. This is basically the problem of transfer learning the customer architecture. Let me just run the saves to show you the confusion matrix too. Let's just wait for a sec. So yeah, here you can see the confusing matrix, the seven images are wrongly classified, the model has classified them as normal, but they are COVID positive. So this is basically more dangerous. Like, you know, these are COVID 19 infected images, but our model is saying, no, this is normal. So this is more dangerous. This is generally false positive is considered most dangerous. Like, this is not much dangerous because the model is like I am saying that this person image is normal. But the model is saying, no, it is COVID positive. So like no worries, you can get your test done for better security. But this is more dangerous. Like, okay, I'm believing the model and model is saying, no, you are COVID free. And actually, I was COVID positive. So this is more dangerous. We calcrate you can see EVs score of COVID 19 became a little less than earlier. We plot the ROC and AC curve also ROC score also decreased by a little margin because obviously the accuracy is not very high. So yeah, all those things we can perform further, we can again deploy this model in the flash model and preys. So yeah, this is basically done. This part has been done. And with this way, you can create your own customer model. Okay, then thank you.