Build a Self Driving Car in 5 Min - Fresh Machine Learning #6

Siraj Raval · Beginner ·📄 Research Papers Explained ·9y ago

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 What is Bitcoin?
What is Bitcoin?
Siraj Raval
2 5 Ways to Use Bitcoin
5 Ways to Use Bitcoin
Siraj Raval
3 BTC Fever - Siraj [Music Video]
BTC Fever - Siraj [Music Video]
Siraj Raval
4 5 Reasons to Build Decentralized Apps
5 Reasons to Build Decentralized Apps
Siraj Raval
5 The Interplanetary File System
The Interplanetary File System
Siraj Raval
6 How to Build a Dapp in 3 min
How to Build a Dapp in 3 min
Siraj Raval
7 Life Before Smartphones
Life Before Smartphones
Siraj Raval
8 4 Ways to Use Smart Contracts
4 Ways to Use Smart Contracts
Siraj Raval
9 3 Dapps You HAVE to See
3 Dapps You HAVE to See
Siraj Raval
10 Char's Life as a BitTorrent Engineer
Char's Life as a BitTorrent Engineer
Siraj Raval
11 4 Reasons AlphaGo is a Huge Deal
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
12 Build a Neural Net in 4 Minutes
Build a Neural Net in 4 Minutes
Siraj Raval
13 Sentiment Analysis in 4 Minutes
Sentiment Analysis in 4 Minutes
Siraj Raval
14 The Hackathon Life
The Hackathon Life
Siraj Raval
15 Your First ML App - Machine Learning for Hackers #1
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
16 Build an AI Composer - Machine Learning for Hackers #2
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
17 Build a Game AI - Machine Learning for Hackers #3
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
18 Build a Movie Recommender - Machine Learning for Hackers #4
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
19 Build an AI Artist - Machine Learning for Hackers #5
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
20 Build a Chatbot - ML for Hackers #6
Build a Chatbot - ML for Hackers #6
Siraj Raval
21 Build an AI Reader - Machine Learning for Hackers #7
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
22 Build an AI Writer - Machine Learning for Hackers #8
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
23 Build a Chatbot w/ an API - ML for Hackers #9
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
24 One-Shot Learning - Fresh Machine Learning #1
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
25 Generative Adversarial Nets - Fresh Machine Learning #2
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
26 Tone Analysis - Fresh Machine Learning #3
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
27 Generate Rap Lyrics - Fresh Machine Learning #4
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
28 Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
30 Build an Antivirus in 5 Min - Fresh Machine Learning #7
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
31 TensorFlow in 5 Minutes (tutorial)
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
32 Build a Recurrent Neural Net in 5 Min
Build a Recurrent Neural Net in 5 Min
Siraj Raval
33 Build a Simulation in 5 Min
Build a Simulation in 5 Min
Siraj Raval
34 Build a TensorFlow Image Classifier in 5 Min
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
35 Tensorboard Explained in 5 Min
Tensorboard Explained in 5 Min
Siraj Raval
36 Generate Music in TensorFlow
Generate Music in TensorFlow
Siraj Raval
37 Build a Game Bot (LIVE)
Build a Game Bot (LIVE)
Siraj Raval
38 Deep Learning Frameworks Compared
Deep Learning Frameworks Compared
Siraj Raval
39 Introduction - Learn Python for Data Science #1
Introduction - Learn Python for Data Science #1
Siraj Raval
40 Build a Neural Network (LIVE)
Build a Neural Network (LIVE)
Siraj Raval
41 Twitter Sentiment Analysis - Learn Python for Data Science #2
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
42 Recommendation Systems - Learn Python for Data Science #3
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
43 Predicting Stock Prices - Learn Python for Data Science #4
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
44 Pong Neural Network (LIVE)
Pong Neural Network (LIVE)
Siraj Raval
45 Deep Dream in TensorFlow - Learn Python for Data Science #5
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
46 Visualizing Data with D3.js (LIVE)
Visualizing Data with D3.js (LIVE)
Siraj Raval
47 Genetic Algorithms - Learn Python for Data Science #6
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
48 Enter Siraj [Music Video]
Enter Siraj [Music Video]
Siraj Raval
49 Build a Web Scraper (LIVE)
Build a Web Scraper (LIVE)
Siraj Raval
50 Why is P vs NP Important?
Why is P vs NP Important?
Siraj Raval
51 How to Make a Neural Network (LIVE)
How to Make a Neural Network (LIVE)
Siraj Raval
52 How to Make an Amazing Tensorflow Chatbot Easily
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
53 How to Make an Amazing Video Game Bot Easily
How to Make an Amazing Video Game Bot Easily
Siraj Raval
54 How to Make a Tensorflow Neural Network (LIVE)
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
55 How to Make a Simple Tensorflow Speech Recognizer
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
56 Joel Shor - Really Quick Questions with an Awesome Google Engineer
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
57 How to Make a Path Planning Algorithm Easily (LIVE)
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
58 The Best Way to Prepare a Dataset Easily
The Best Way to Prepare a Dataset Easily
Siraj Raval
59 Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
60 How to Make a Tic Tac Toe Neural Network Easily (LIVE)
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval

This video teaches how to build a self-driving car in a simulated environment using PyGame and Keras, covering the basics of self-driving cars and implementing a simple self-driving car using Q-learning. The video demonstrates how to use reinforcement learning and neural networks to create an autonomous vehicle.

Key Takeaways
  1. Import necessary libraries
  2. Define the training function for the self-driving car
  3. Create a new game instance and get the first state
  4. Update positional variables and choose an action
  5. Take the action and get a reward
  6. Train the model using experience replay
  7. Save the model every 25,000 frames
💡 The video demonstrates how to use reinforcement learning and neural networks to create an autonomous vehicle, highlighting the potential of machine learning in autonomous vehicles.

Related AI Lessons

I Spent Weeks Looking for a Research Gap Before I Realized I Was Searching the Wrong Way
Learn how to effectively find research gaps by changing your approach, a crucial skill for AI researchers and academics
Medium · AI
ICMI 2026 Reviews [D]
Learn how to interpret ICMI 2026 reviews and improve your paper's acceptance chances
Reddit r/MachineLearning
Workshop submission for main conference paper under review [D]
Learn how to navigate submitting a paper to a non-archival workshop before the final decision of a main conference like ECCV
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]
Streamline your research with a new Chrome extension and website that integrates 3M papers from arxiv, OpenReview, GitHub, and HuggingFace, including citation graphs and SPECTER2 neighbors, and provide feedback to improve it
Reddit r/MachineLearning
Up next
Beyond Big Vendors: ERP Systems Explained #shorts
Digital Transformation with Eric Kimberling
Watch →