<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Decode Ways - Medium]]></title>
        <description><![CDATA[A collection of thoughts, stories and ideas from a computer science student. - Medium]]></description>
        <link>https://medium.com/decode-ways?source=rss----bbb3e5495055---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Decode Ways - Medium</title>
            <link>https://medium.com/decode-ways?source=rss----bbb3e5495055---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:13:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/decode-ways" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hacktorial: Building a Self-Driving Car with Deep Learning]]></title>
            <link>https://medium.com/decode-ways/hacktorial-self-driving-car-df81dde2bc25?source=rss----bbb3e5495055---4</link>
            <guid isPermaLink="false">https://medium.com/p/df81dde2bc25</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Sujith Vishwajith]]></dc:creator>
            <pubDate>Sun, 24 Feb 2019 20:27:46 GMT</pubDate>
            <atom:updated>2018-01-16T04:15:59.227Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hacktorial #1: Building a Self-Driving Car with Deep Learning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eHGmEX0YRvJwUOT-p30CnQ.jpeg" /><figcaption>Google’s Self-Driving Car</figcaption></figure><p>This post is a written adaptation of the Terrapin Hackers Hacktorial presented at the University of Maryland. The original slides from the presentation are available to view <a href="http://goo.gl/XtIBNg">here</a>.</p><p>In this hacktorial, we will learn how to build deep learning models in Python to train a self-driving car from scratch using <a href="https://github.com/udacity/self-driving-car-sim">Udacity’s car simulator</a>. This is originally a challenge from <a href="https://www.udacity.com/course/self-driving-car-engineer-nanodegree--nd013">Udacity’s Self-Driving Car Engineer Nanodegree</a>. Specifically, we will use a framework called end-to-end learning which I will discuss later on in more detail.</p><blockquote>The Github repo containing all the code is located <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial"><strong>here</strong></a><strong>.</strong></blockquote><blockquote>Follow along on the Jupyter notebook <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial/blob/master/Behavioral-Cloning-Tutorial.ipynb">Behavioral Cloning Self-Driving Car Guide</a> which contains all the project code and explanations.</blockquote><h4>Agenda:</h4><ol><li>Intro</li><li>Goal</li><li>Approach</li><li>Installation</li><li>Implementation</li></ol><p>This hacktorial assumes you have some familiarity and experience with Python and Convolutional Neural Networks (CNNs). For those new to deep learning or computer vision, here are some good blog posts to give you a solid basis for understanding convolutional neural networks, max pooling, etc. Included is a sample tutorial which guides you through installing Keras and guides you through creating a CNN that recognizes handwritten digits.</p><ul><li><a href="http://colah.github.io/posts/2014-07-Understanding-Convolutions/">Chris Olah’s blog on CNNs</a> by Chris Olah</li><li><a href="https://adeshpande3.github.io/adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/">A Beginners’s guide to CNNs</a> by Adit Deshpande</li><li><a href="https://ujjwalkarn.me/2016/08/11/intuitive-explanation-convnets/">Intuitive Explanation of CNN</a> by Ujjwal Karn</li><li>Machine Learning Mastery: A tutorial on sample handwritten digit recognition using Keras <a href="http://machinelearningmastery.com/handwritten-digit-recognition-using-convolutional-neural-networks-python-keras/">here</a>.</li><li>PyImageSearch: A great resource for computer vision tutorials that are easy to follow in Python <a href="http://www.pyimagesearch.com/">here</a>.</li></ul><h3>Intro</h3><p>Deep learning has been around since the 1980’s as a research interest of Geoffrey Hinton, Yann LeCun, and many others. The combination of an increased computational power and large storage capacity of modern day computers has allowed deep learning to gain immense success. In fact, deep learning has made its way somehow or another into many of our everyday technologies such as in our email, on search engines, hospitals, and more!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*8OB1hzNhn4zp96tI_bNoGw.jpeg" /><figcaption>From Left to Right: Yann LeCun, Geoff Hinton, Yoshua Bengio, Andrew Ng</figcaption></figure><p>One area where deep learning is making a huge contribution is in computer vision and robotics. Without deep learning, scientists generally had to perform manual feature engineering which is a fancy term for manually identifying all the features that might be relevant towards the current task. As you can imagine, this was an extremely cumbersome and slow task that has many limitations. With deep learning however, computers could now teach themselves what features were important in the task at hand. For the case of image recognition, deep learning models learnt what combinations of shapes and features belonged to certain classes and allowed for a substantial improvement in image recognition. For more information on deep learning check out our some of our other posts.</p><p>Self-driving cars have always been a central vision in our future. With Google, Uber, and other tech-companies making huge advancements in the past couple years it’s not surprising if we see them on the road soon. There are many approaches developed over the past years to build these self-driving cars. While the ones developed by the companies highlighted above are massive complex systems, they often boil down to key algorithms and components. With the rapid democratization of AI, we too can harness the power of these algorithms and apply them to build our own self-driving cars (simulated…..for now).</p><h3>Goal</h3><p>The end goal is to build a machine learning model that can steer a car around a track without any human intervention. The model should ideally work on any test track and can start at any given location. We also want to avoid writing a lot of code to keep everything simple. Our model should take in images of what the car sees and output the correct steering angle (and maybe even the throttle).</p><p>By utilizing deep learning, we should also be able to avoid manual feature engineering in the code. It also has a lot of edge-cases where features are computed incorrectly or additional features are required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-0Rj-nKTnkokctdI4vIQ4g.gif" /><figcaption>Sample of our desired result. GIF from <a href="https://medium.com/self-driving-cars/more-udacity-self-driving-car-students-in-their-own-words-193b99ee66eb">here</a>.</figcaption></figure><h3>Approach</h3><p>There are many approaches to developing self-driving cars used by companies today. We will briefly go through an overview of some of the popular approaches and then select the best one suited for our goal (certain approaches are better than others for certain tasks). There are many other approaches out there which this article doesn’t discuss such as Inverse Reinforcement Learning and Adversarial Networks.</p><h4>Hard-Coded Rules and Features</h4><p>This was one of the first approaches to developing autonomous vehicles and probably what we all imagined it to be like. The rules go something like this: If you see a stop sign, stop the car. If you see a pedestrian, stop the car. If you are in a lane, make sure you are in the center, and on and on. The major problem with this is that there are too many rules to keep track of and write. In some scenarios (like an impeding accident), these rules don’t even apply. This approach also requires a lot of sensors to keep track of the car.</p><p><strong>Good: </strong>You know exactly what the car is doing and why.</p><p><strong>Bad:</strong> Too many rules and sensors required to keep track of.</p><h4>Reinforcement Learning</h4><p>This is one of the more popular approaches that have existed for a while but recently publicized by companies like DeepMind. The approach is an area of machine learning inspired by behaviourist psychology. It relies on letting an agent (the car) learn what actions to take based on a reward function (driving well). This approach often works extremely well and doesn’t require humans to teach it to drive. The issue is that in order to learn, the agent has to experiment with millions of actions to learn which is gives it the best reward in each scenario. Since we can’t let a car roam around a city crashing into people and only after realizing the mistake, we are forced to train it in a simulator. One of the biggest problems here is that</p><blockquote>Simulations are doomed to succeed. — George Hotz</blockquote><p>This means that no matter what, eventually our car is going to succeed at driving in the simulation we give it as the environment in the simulation is pre-programmed. This is a problem as we can never ensure that the simulation is real enough due to the amount of variance in the real world which we can’t control.</p><p><strong>Good:</strong> Extremely good and optimal at driving in trained situations</p><p><strong>Bad:</strong> ‘Simulation is doomed to succeed’</p><h4><strong>End-To-End Learning (</strong>Behavioral Cloning)</h4><p>This approach is probably the simplest approach of them all. The idea behind it is that neural networks are extremely good at learning patterns. The question we want to answer is</p><blockquote>If we showed a car how to drive, could it learn to drive like us?</blockquote><p>This approach to self-driving cars was recently successfully implemented by Nvidia in their paper <a href="https://arxiv.org/abs/1604.07316">End to End Learning for Self-Driving Cars</a>. Since this paper is a core foundation of the rest of the tutorial, it’s recommended you give it a quick read.</p><p>The intuition behind this approach is that a user drives a car around for a long period of time in ideally diverse scenarios (e.g. a city, freeway, etc.) and collects data about their driving (usually images of what’s in front of the car, speed, acceleration, etc.). Then we take the data and feed it into a neural network and try to let it learn why you took the specified action for each data point. For example if you consistently turned when the road was curved, it would learn that an image of a road curving in front of you should mean turn in the direction of curve. An issue here is that the model will always learn to drive like you drive. So if you decided to drive like an uber-aggressive New York driver; the model will too!</p><p><strong>Good:</strong> Fast to train, easy to code, and generally works well.</p><p><strong>Bad: </strong>Data focused and lack of interpretability.</p><p>Since our simulator lets us drive the car around different tracks ourselves and collect data from our run, the end-to-end learning approach works best for us.</p><h3>Installation</h3><p>Let’s get our hands dirty. First, let’s install everything we need in order to run and develop this project.</p><p>To run the models and code make sure <a href="https://www.python.org/downloads/">Python</a> is installed. All the setup should ideally be done inside a <a href="https://conda.io/docs/">Conda</a><em> </em>environment as well as to avoid any conflicts when running the model but this is optional if you know what you are doing.</p><p>Clone the repo onto your local machine and cd into the directory.</p><pre>git clone https://github.com/sujithv28/Behavioral-Cloning-Hacktorial.git<br>cd Behavioral-Cloning-Hacktorial</pre><p>Here you can create the conda environment if you wish to use one. At the time of development, we used Python 2.7 but Python 3 should work.</p><pre>conda create -n hacktorial python=2.7<br>source activate hacktorial</pre><p>Install TensorFlow following the instructions for your system <a href="https://www.tensorflow.org/install/">here</a>. With conda you can install TensorFlow simply by running:</p><pre>conda install -c conda-forge tensorflow</pre><p>Install all the Python dependencies:</p><pre>pip install -r requirements.txt</pre><p>Set Keras to use TensorFlow as backend:</p><pre>python<br>import keras<br>quit()<br>nano ~/.keras/keras.json</pre><p>Change your values to look like this:</p><pre>{<br>    &quot;image_dim_ordering&quot;: &quot;tf&quot;, <br>    &quot;epsilon&quot;: 1e-07, <br>    &quot;floatx&quot;: &quot;float32&quot;, <br>    &quot;backend&quot;: &quot;tensorflow&quot;<br>}</pre><p>Also make sure you have the library opencv-python installed either through pip or homebrew. You can check if this works by running and making sure nothing complains:</p><pre>python<br>import cv2</pre><p>You can download the simulator <a href="https://github.com/udacity/self-driving-car-sim">here</a>.</p><p>Finally, download Udacity’s training data and extract it to the main directory by running in the directory (optional but initially reccomended).</p><pre>wget https://www.dropbox.com/s/3cwc2atg1qorzg4/data.zip?dl=0<br>unzip -a data.zip?dl=0<br>rm data.zip?dl=0</pre><p>If you wish to use your own training data, open the simulator and select any track and the training option. All the data will be saved to the location you specify. Follow the instructions <a href="https://github.com/udacity/self-driving-car-sim">here</a> to learn more on how to use the simulator.</p><p>After this point you should be good to go for developing the model. If you encounter any issues feel free to check <a href="https://stackoverflow.com/">Stack Overflow</a> or comment on the post below.</p><h4>Simulator Overview</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dNUdB30lEXFiMG3aN8vmSw.png" /><figcaption>Udacity Simulator</figcaption></figure><p>The simulator has two options upon opening it: training mode and autonomous mode. For testing the model, the autonomous mode is used as it takes in inputs from a program and lets it drive the car. If you want to get your own training data or drive the car for fun, select the training mode. The data will be saved as a CSV file where each row corresponds to a single frame from the training run. Each row contains paths to three images from the car’s perspective (left, right, and center), the speed of the car, and the throttle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*pXbpdtCGIAZrW4hKnVlzLg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*rwfS4rwT6yrZlpO2Z7jLBA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*Y-Bz5nOvbsf8Kf-hb-9fow.jpeg" /><figcaption>Sample training images of left, center, and right cameras from a random frame.</figcaption></figure><h3>Implementation</h3><p>The <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial/blob/master/model.py">template.py</a> is a template for the hacktorial and the only code we will be modifying. The final code as a reference is available to view in <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial/blob/master/model.py">model.py</a>. The file <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial/blob/master/drive.py">drive.py</a> is from Udacity and contains the code needed to connect your model trained in <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial/blob/master/model.py">model.py</a> with the simulator.</p><p>The training data is only comprised of the first track. The second track which is a different setting is meant to be used as a test track to see how well your model generalizes.</p><blockquote>All the code with explanations is located in the Jupyter notebook <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial/blob/master/Behavioral-Cloning-Tutorial.ipynb">Behavioral Cloning Self-Driving Car Guide</a>.</blockquote><h4>Data Augmentation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*UMRmOrcYF61VV20oNG1mTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*fNsgzZTZ_Tz85ztrqr3AuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*pmWrFUr8Ckod053QXM9gKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*XzKuQeggTn5imZZu0F_d_g.png" /><figcaption>Augmented Images from the original Image</figcaption></figure><p>Data augmentation is a strategy used by many data scientists to improve performance. By flipping a picture of a road turning right and negating the steering angle, we now have an example of a road turning left. We can apply more tricks such as tinting the image to look like you are driving at night time, and even jittering the image so it looks like you are on a different spot on the road (although it is important to adjust the steering angle accordingly here).</p><h4>Model architecture</h4><p>The model we implemented is based off of Nvidia’s model described in their paper <a href="https://arxiv.org/abs/1604.07316">End to End Learning for Self-Driving Cars</a>. The differences between their model and ours is that we add a Maxpooling layer after every Convolutional layer to speed up computation and also have more fully-connected (dense) layers. We also add BatchNormalization to speed up computation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*EbvrQT775rdcEh1MI_VmYg.png" /><figcaption>Nvidia’s End to End Learning model</figcaption></figure><p>The model will take in an image (either from the left, center, or right camera) and output a single number between -1 and 1 representing the steering angle.</p><p>We used <a href="https://keras.io/">Keras</a> to implement the model. Keras is a deep learning library that runs on Tensorflow or Theano and is best for fast prototyping. For more intensive deep learning tasks, <a href="http://pytorch.org/">PyTorch</a> or <a href="https://www.tensorflow.org/">TensorFlow</a> may be a better option.</p><h4>Training the model</h4><p>To train the model and save the parameters, simply run:</p><pre>python model.py</pre><h4>Testing the model</h4><p>To run your trained model on the simulator, open up the simulator application and start an autonomous session on either track (recommended to initially try it out on the first track since that is where the training data is from). Then run</p><pre>python drive.py model.json</pre><p>Your car should begin driving itself around the track! If the car ever gets out of control and leaves the track, you can manually drive it using the WASD keys.</p><h4>Considerations</h4><ul><li>Try changing the image quality in the settings of the simulator for higher resolution training data. Retrain the model and see how it affects the performance of the car.</li><li>How does the car perform on the second track? What are some differences between the two tracks and how can we overcome them in our data augmentation step?</li><li>What happens if a car goes out of the track? Does it know how to correct itself? How can we fix that?</li></ul><h4>Here’s a challenge</h4><p>In this project we solely predicted steering angles for the car while it drove at a constant speed. Experiment with the implementation to see if you can learn to determine what throttle to give the car. Theoretically, this will help the car drive smoother around the track.</p><h4>Other resources</h4><p>Here are some other great blogs written going over their approach to the Udacity Behavorial Cloning Project and explaining the logic behind their approach.</p><ul><li><a href="https://medium.com/udacity/udacity-self-driving-car-nanodegree-project-3-behavioral-cloning-446461b7c7f9#.9asxk3lyu">Udacity Self-Driving Car Nanodegree Project 3 — Behavioral Cloning</a></li><li><a href="https://medium.com/udacity/how-udacitys-self-driving-car-students-approach-behavioral-cloning-5ffbfd2979e5#.q00ni6o4j">How Udacity’s Self-Driving Car Students Approach Behavioral Cloning</a></li><li><a href="https://medium.com/self-driving-cars/6-different-end-to-end-neural-networks-f307fa2904a5#.ef5pz6i3f">6 Different End-to-End Neural Networks</a></li></ul><p>The final project can be found on my GitHub here: <a href="https://github.com/sujithv28/Behavioral-Cloning-Hacktorial">https://github.com/sujithv28/Behavioral-Cloning-Hacktorial</a></p><h4>Finally…</h4><p><em>If you enjoyed this post, give it a </em>👏<em> below so other people can enjoy it too.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df81dde2bc25" width="1" height="1" alt=""><hr><p><a href="https://medium.com/decode-ways/hacktorial-self-driving-car-df81dde2bc25">Hacktorial: Building a Self-Driving Car with Deep Learning</a> was originally published in <a href="https://medium.com/decode-ways">Decode Ways</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>