Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Key Takeaways
This video demonstrates how to build a self-driving car in a simulated environment using PyGame and the Keras machine learning library, covering the basics of self-driving cars and implementing a simple self-driving car using Q-learning.
Full Transcript
I'm glad I can book a self-driving Uber now hey this car isn't self-driving and it will never [Music] be hello world it's SJ and in this episode we're going to talk about how self-driving cars work then Implement our own self-driving car in a simulated environment self-driving cars aren't in the realm of Science Fiction anymore real companies like Toyota and Ford have millions of dollars in R&D pouring into this technology services like uber and lyt thatr pay human drivers will soon deploy entire fleets of self-driving cars so prepare for Skynet just kidding in 2 or 3 years we're going to start seeing hundreds of thousands of self-driving cars being sold to regular consumers get your self-driving trucks right here but how do they work well when we humans are in the driver's seat we're observing our environment by receiving an input of our surroundings and simultaneously processing it in order to make a decision of which way to move the steering wheel this can be translated into a machine problem known as slam slam or simultaneous localization and mapping and it's something all self-driving cars do a self-driving car is usually outfitted with a GPS unit an inertial navigation system and a range of sensors it uses the positional information from the GPS and navigation system to localize itself and the sensor data to build an internal map of its environment once it has its position in its internal map of the world it can use that map to find the optimal path to its destination that avoids any kind of obstacles be that dead babies or Pokémon once the car has determined the optimal path to take that decision is then broken down into a series of motor commands which are fed into the car's actuators that's a highle description of how they work but roads are complex it's not just about avoiding obstacles there are weather conditions that require changes in the way you accelerate different types of road signs and situations that you probably couldn't ever predict a recent paper came out just this year called long-term planning for short-term prediction these guys proposed a planning algorithm for self-driving cars specifically one that would be able to make immediate actions so as to optimize a long-term objective an example they used was a roundabout when a car tries to merge in a roundabout it should decide on an immediate acceleration or breaking command while the long-term effect of the command is a success or failure of the merge traditionally planning for self-driving cars is done via reinforcement learning the car learns to continuously correct its driving capability over time through trial and error when training the car or agent observes a state s that is a scene that it observes and takes an action a and depending on whether whether or not the action was good however we Define good it can receive a reward R then it moves to the next state s and the process repeats the goal is to maximize the reward and that depends on a policy which Maps state to action that it learns over time the state action value function is called q and it helps find the optimal policy but it can be super hard to learn Q in an environment as dynamic as roads with multiple cars it's not just a problem of predicting your own car's actions you have to be able to predict other cars actions as well so to solve this problem of learning que they used a deep recurrent neural network to learn a policy and the input to the neural net was a vector that contained both the predictable part the speed of the car and an unpredictable part the speed of other cars so it could learn from both they applied it to just two features adaptive cruise control and merging roundabouts but is there a way to make one learning algorithm that can learn everything from the ground up the technical term for this is end to end and an even fresher paper that was released about 3 months ago tried it a team from Nvidia put three cameras on a car windshield to receive input data fed this video data to a convolutional neural network and features were learned by themselves they didn't explicitly decompos the problem into subm modules for different scenarios their CNN mapped what it saw from the input directly to steering commands it was first trained in a simulation with pre-recorded video then trained by a human driver they got great results but it was hard for the paper authors to differentiate the feature extractor part of the neural network from the controller part so it was difficult to test each that's why most real world car manufacturers have decided it's not yet possible to test and verify an endtoend system they end up just making software where each module is separate and can be tested on its own a hacker named George Hots built a self-driving car in his garage with just a couple of cell phone cameras and the total cost turned out to be just 1,000 bucks let's train our own self-driving car using q-learning to drive itself without running into obstacles after we declare our Imports let's write our training function for our car first it'll take in a neural net with a set of hyper M as the parameters then we'll Define some variables for the number of frames we want to observe for both training and testing we'll then Define our positional variables for localization we'll create a new game instance and get the first state of the game instance we'll also set a timer for tracking purposes then when we start building experience replay we'll update our positional variables then choose an action depending on the state randomly if the random variable is outside of our constraints we'll get the Q values for each action to help us find the optimal policy we'll take that action and if it is valid we will get a reward once it's done observing the game and building experience replay we'll start training sampling The Experience replay memory and getting the training values it'll then train the model on this batch that is a neural network then update the starting State and if the car dies log the distance and reset the car's life finally we want to save the model every 25,000 frames in the weights file let's see how it looks in a simulated environment it constantly tries to avoid obstacles through a mix of reinforcement learning and a neural net once you've got it work working in the simulator you could Port it to a real RC car and have it self drive all over your room links down below for more info definitely subscribe for more ml videos I've got to go descend some gradients so thanks for watching
Original Description
Let's build a self driving car! In this video, I talk about how self driving cars work, then dive into 2 fresh papers that add modern improvements to autonomous vehicles. The self driving car that we build is in a simulated environment and is built using PyGame and the Keras machine learning library.
The code in the video is here:
https://github.com/llSourcell/Self-Driving-Car-Demo/
I created a Slack channel for us, sign up here:
https://wizards.herokuapp.com/
Paper 1: Long term Planning for Short Term Prediction
http://arxiv.org/pdf/1602.01580v1.pdf
Paper 2: End-to-End Learning for Self-Driving Cars
https://arxiv.org/pdf/1604.07316v1.pdf
More on Reinforcement Learning:
http://www2.hawaii.edu/~chenx/ics699rl/grid/rl.html
https://www.quora.com/Artificial-Intelligence-What-is-an-intuitive-explanation-of-how-deep-Q-networks-DQN-work
http://www2.econ.iastate.edu/tesfatsi/RLUsersGuide.ICAC2005.pdf
I love you guys! Thanks for watching my videos, I do it for you. I left my awesome job at Twilio and I'm doing this full time now.
I recently created a Patreon page. If you like my videos, feel free to help support my effort here!:
https://www.patreon.com/user?ty=h&u=3191693
Much more to come so please subscribe, like, and comment.
Follow me:
Twitter: https://twitter.com/sirajraval
Facebook: https://www.facebook.com/sirajology Instagram: https://www.instagram.com/sirajraval/ Instagram: https://www.instagram.com/sirajraval/
Signup for my newsletter for exciting updates in the field of AI:
https://goo.gl/FZzJ5w
Hit the Join button above to sign up to become a member of my channel for access to exclusive content! Join my AI community: http://chatgptschool.io/ Sign up for my AI Sports betting Bot, WagerGPT! (500 spots available): https://www.wagergpt.xyz
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Siraj Raval · Siraj Raval · 29 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
▶
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is Bitcoin?
Siraj Raval
5 Ways to Use Bitcoin
Siraj Raval
BTC Fever - Siraj [Music Video]
Siraj Raval
5 Reasons to Build Decentralized Apps
Siraj Raval
The Interplanetary File System
Siraj Raval
How to Build a Dapp in 3 min
Siraj Raval
Life Before Smartphones
Siraj Raval
4 Ways to Use Smart Contracts
Siraj Raval
3 Dapps You HAVE to See
Siraj Raval
Char's Life as a BitTorrent Engineer
Siraj Raval
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
Build a Neural Net in 4 Minutes
Siraj Raval
Sentiment Analysis in 4 Minutes
Siraj Raval
The Hackathon Life
Siraj Raval
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
Build a Chatbot - ML for Hackers #6
Siraj Raval
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
Build a Recurrent Neural Net in 5 Min
Siraj Raval
Build a Simulation in 5 Min
Siraj Raval
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
Tensorboard Explained in 5 Min
Siraj Raval
Generate Music in TensorFlow
Siraj Raval
Build a Game Bot (LIVE)
Siraj Raval
Deep Learning Frameworks Compared
Siraj Raval
Introduction - Learn Python for Data Science #1
Siraj Raval
Build a Neural Network (LIVE)
Siraj Raval
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
Pong Neural Network (LIVE)
Siraj Raval
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
Visualizing Data with D3.js (LIVE)
Siraj Raval
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
Enter Siraj [Music Video]
Siraj Raval
Build a Web Scraper (LIVE)
Siraj Raval
Why is P vs NP Important?
Siraj Raval
How to Make a Neural Network (LIVE)
Siraj Raval
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
How to Make an Amazing Video Game Bot Easily
Siraj Raval
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
The Best Way to Prepare a Dataset Easily
Siraj Raval
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval
More on: LLM Engineering
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
I Spent Weeks Looking for a Research Gap Before I Realized I Was Searching the Wrong Way
Medium · AI
ICMI 2026 Reviews [D]
Reddit r/MachineLearning
Workshop submission for main conference paper under review [D]
Reddit r/MachineLearning
Kept context-switching between arxiv, OpenReview, GitHub, and HuggingFace for every paper, so I built this. Chrome extension + website with everything inline, plus citation graph + SPECTER2 neighbors. 3M papers, free, feedback welcome [P]
Reddit r/MachineLearning
🎓
Tutor Explanation
DeepCamp AI