Lane detection using A deep learning model | hands-on tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
automatic Lane detection is a crucial technology that Ena self-driving cars to properly position themselves in a multi-lane urban driving environments many computer vision methods have been developed to the purpose of solving the lane detection problem however these traditional techniques of which many tutorials are being posted on YouTube requires a lot of computation not to mention the complexity of the code needed for their implementations that's why in this video I'm going to show you how you can create your own intelligent and efficient Lane detection system using chor flow and caras in the past few decades deep learning has proved to be a very powerful tool because of its ability to handle large amounts of data the interest to use hidden layers has surpassed traditional techniques especially in pattern recognition one of the most popular deep neural networks is convolutional neural networks CNN are commonly applied to image processing and Analysis they are composed of multiple layers of artificial neurons each layer extract an increasingly complex set of features starting from simple lines to more complex corners and edges and finally arriving at the final prediction of faces objects and so on but before the image is fed to these neuron layers it has to pass through several convolution and pulling layers these layers are responsible for reducing the spatial size of the features in order to decrease the computational power required to process the data supervised machine learning projects are often separated into two phases the first one concerns the training process where the agent learn to achieve a certain task given labeled examples of the task as inputs at the end of this phase the CNN model is saved and can be then deployed to real life applications without the need to retrain the model all over again in this video which is the first of a two-part series about Lane detection we will start by the second phase in the description box below you will find the link for all the necessary files we are going to use among those you will find the file named model H5 this file contains an already trained Lane detection CNN model that's why we will first learn how to deploy and test this model by giving it a video of our choice as input in the second video of this series I'm going to show you how you can properly train and save this model providing a scalable code that you can benefit from even in other machine learning projects so let's get started in machine learning projects you usually have two choices the first one is using your own machine to train and run the AI agent to do this you will need to download several libraries such as tensor flow which can be a little bit annoying if you don't have good internet connection not to mention the somewhat High Hardware requirements the second choice is using the Google collab platform that enables you to escape escape the hardware problem but still you have to upload and download the input and output videos don't worry I'm going to explain both of these methods in detail and you can choose whatever method is more suitable for your case the second link I provided in the descriptions take you to Google collab after opening a new notebook you will get this window where most of our work will be done change the name of the notebook to something more suitable and let's start the first step is to import the Google collab files module this module will allow us to upload files from the PC to the Google collab project running this command will prompt a popup window on where we can choose which file to upload if you click the file tab you should see the uploaded file shown there next you have to install this version of the scipi module since the current existing version will not work don't forget to execute every piece of code as shown here next these modules have to be imported I'll explain each one of them in details when we use it so don't worry just yet we will now import the lane detection CNN model we just uploaded a second ago using curas models method called load model the next step is to create a class called lanes and Define the init method of this class that will contain only two lists the recent fit list which is responsible for storing the most recent predictions and the a fit that will contains their average the predictions we are talking about look something like this the CNN model will predict whether each pixel in the frame belongs to the lane or not it will do this for every frame of the input video of course and that's it this is all what the lane class contains now it is time to define a function that does some sort of pre-processing to the input video frame by frame we will call it Road Lanes first of all we need to resize each frame using IM resize that we imported earlier and make it 80 by 160 this third dimension represents the RGB layers and that means our image is colored the small image is then turned into a lumpi array which will make the code more efficient and after that we proceed in adding another dimension to the image in this Dimension the prediction for each pixel in the image will be stored the pre-processing is basically done now all we have to do is to feed the image to the CNN model by using this method of course we will keep only the predictions part by specifying the zero index and since the prediction will be between zero and one we have to multiply by 255 in order to be able to use it as an image otherwise it will will be so dark the prediction is appended to the recent fit list of the Lan glass as we mentioned earlier and if the length of this list exceed five then we will discard the first element of the list each time and that means the list will only contains the maximum of five elements this moving window of five predictions will be averaged using the mean method from lpai as shown in here producing a black and white image where the brightness of each pixel in indic Ates the probability of this pixel being a part of the lane or Not Another Matrix / image blanks is created this Matrix will be identical in shape to the average prediction Matrix but initialized to zero for the moment next we will use the method daack that will stack the average Matrix that contains the prediction between two layers of blanks and this will create our RGB image we already said that we need three layers in an image image the red layer the Green Layer and the blue layer we chosen our predictions layer to be the middle one that means it will be shown as green in the final video we will resize the image again to match the input size the final step will be to Overlay our output image over the input image using ad weighted method from the open CV given the two images the same weight and we return the result we are almost done we just have to use the function we just created first of all we will upload the input video to the project the same way we uploaded the CNN Model A few moments later and then we read this file using the video file clip function from the movie P module and assign a name for the output video and finally use the filter function Road Lanes by passing it as an argument to the FL image method that will filter each and every frame of the input using the road lines function after this final portion of the code is executed which may takes from several seconds to to several minutes depending on the size of the input video a few moments later the final result will be located in the files tab in the sidebar we can then download it and view it in our computer as you can see here this looks good the lane is being detected using very little computational power which demonstrates the true power of new networks there is a little bit of noise but this can be avoided by training a better agent either by changing the model structure or the quality and amount of data used in the training phase we will do this in the second video but for now let me show you how you can do the same process in your local machine instead of the Google collab platform personally I prefer this second method over the first one for working with videos because uploading to Google collab usually is a slow process in P charm create a new new project us in a new environment make sure to have a python 3.6 because this will not work with python 3.8 after the project is created we start installing the necessary modules and libraries using the terminal we start with open CV by typing this command I already installed these libraries so this won't take much time and then install tensorflow by typing pip install tensorflow this will take the longest since it's about 400 megabytes then we install movie pie and after movie pie we install this version of scipi exactly like we did in the Google collab environment when you finish go ahead and past the folder you downloaded from the first link below to the CNN project path and create a python file inside this we will call it Lane detection main the path of the model and the input files can be extracted easily just by right clicking on them and choose copy absolute path like this we will need this later the hard part is over now we just need to repeat what we did in Google collab after importing the modules we need the kiras load model method is called make sure to pass the correct absolute path to the CNN model of course there is no need for uploading anything since all the files are already present in our project the lanes class and the road lines function will be exactly the same as Google collab and also the few lines of code beneath the only difference this time is that we will not call the upload line for importing the input video all right the code now is done all we have to do is to create a configuration file like this to run the script easily or you can run it from the terminal it's your choice when executing the script make sure you have internet connection because the movie Pi module requires it when writing the final output video when the script is executed you will find the result in the same folder just copy the absolute path and open the folder using window Explorer and congratulations now you have a working Lane detection system that you can use easily with the script a quick disclaimer I found the original file of this script in GitHub when I was looking for inspiration for a beginner friendly project in deep learning I only had to make some minor modifications and debugging but in general this project is a great way to start in deep learning for beginners all I have left to tell you now is stay safe see you in another video with another idea goodbye
Info
Channel: Mouad Boumediene - Hobby Coding
Views: 57,214
Rating: undefined out of 5
Keywords: deep learning, neural networks, convolutional neural network, tensorflow, python, lane detection, self driving, tesla, keras, pooling, convolution, coding, education, artificial intelligence, machine learning
Id: KzRkS-8oNtc
Channel Id: undefined
Length: 13min 40sec (820 seconds)
Published: Fri Jul 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.