<?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[Stories by Prateek Sawhney on Medium]]></title>
        <description><![CDATA[Stories by Prateek Sawhney on Medium]]></description>
        <link>https://medium.com/@sawhney-prateek97?source=rss-5a206a1caae6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qmpeeoRn6fwBQR_BNlhtHw.jpeg</url>
            <title>Stories by Prateek Sawhney on Medium</title>
            <link>https://medium.com/@sawhney-prateek97?source=rss-5a206a1caae6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:49:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sawhney-prateek97/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introduction to Keras & Transfer Learning for Self Driving Cars]]></title>
            <link>https://sawhney-prateek97.medium.com/introduction-to-keras-transfer-learning-for-self-driving-cars-fbf2e1463481?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbf2e1463481</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transfer-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 12 Sep 2022 12:55:46 GMT</pubDate>
            <atom:updated>2022-09-12T12:55:46.950Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction to Keras and the use of Transfer Learning in the development of Deep Learning architectures</h4><p>In this medium article, I’m going to explain the basics concepts behind Keras, Transfer Learning and Multilayer Convolutional Neural Network. I’ll be introducing an interface that sits on top of TensorFlow, and allows us to draw on the power of TensorFlow with far more concise code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*usw-GFcNL0gqazOK6mWMUw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@lamoune?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Vincent Ghilione</a> on <a href="https://unsplash.com/s/photos/self-driving-car?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>That’s right. In this medium article, we’ll be building a deep neural network using a new set of tools. We’ll still have <strong>TensorFlow</strong> under the hood, but with an interface that makes testing and prototyping much faster.</p><h4>Deep Learning Framework</h4><p>Deep neural networks have been a big focus of work in <strong>Autonomous Driving. </strong>We’re exploring whether we can get a car to drive itself, using only deep neural networks and nothing else. Sometimes we call that <strong>behavioral cloning </strong>because we’re training the network that clone <strong>human driving behavior. </strong>Well, sometimes it’s called<strong> end-to-end learning </strong>because the network is learning to predict the correct steering angle and speed, using only the inputs from the sensors. Deep learning isn’t the only approach to building a self-driving car. For a number of years, people have been working on a more traditional sort of<strong> robotics approach. </strong>So, <strong>why go with deep learning over robotics approach?</strong></p><h4>Difference between the deep learning approach versus the robotics approach while developing a self driving car</h4><p>The robotics approach in building self-driving cars involves a lot of detail knowledge about <strong>sensors, controls and planning.</strong></p><blockquote>With the deep learning approach, we don’t have to program all that detail knowledge into the vehicle. We simply feed all the information we have into the network, and then we let the network figure out on its own what’s important. Also, deep learning allows us to build a feedback loop where the more we drive, the more data we can collect, which in turn allows us to learn how to drive even better.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6zmuub6p1dv2yMcysq4WsQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@yanshulee?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Yanshu Lee</a> on <a href="https://unsplash.com/s/photos/self-driving?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Now the question arises if we actually can drive a real vehicle with just a deep neural network? <strong>We can</strong>. A startup in US recently drove 20 miles down the highway in San Francisco to the airport and back, without touching the steering wheel once. <strong>Wow. So it really works. Well then, let’s get started building a deep neural network.</strong></p><h4>Introduction to Transfer Learning</h4><p>Deep Learning and Computer Vision is an amazing set of skills with a wide range of applications. However, deep learning engineers often don’t actually start with a blank slate when they’re building neural networks. Starting from scratch can be time-consuming. It’s not just architecting the network, but also experimenting with it, training it and adjusting it, which can take days or even weeks.</p><p>To accelerate the process, engineers often begin with a <strong>pre-trained network </strong>and then modify it. Fine-tuning an existing network is a powerful technique because improving a network takes much less effort than creating one from scratch. Going even further, we can take an existing network and re-purpose it for a related but different task. Re-purposing a network is called <strong>Transfer Learning, because we’re transferring the learning from an existing network to a new one.</strong></p><h4>Role of GPU’s</h4><p>GPUs have also become extraordinarily important for deep learning. GPUs are optimized for high throughput computation. Whereas CPUs are mostly optimized for latency, running a single thread of instructions as quickly as possible, GPUs are optimized for throughput, running as many simultaneous computations as possible. Throughput computing is important for <strong>computer graphics </strong>because we want to update lots of pixels on the screen at the same time. And it turns out that throughput computing is also important for deep learning because the computations fundamental to deep learning have a lot of parallelism. What level of acceleration do you typically see when you move from training a network on a <strong>CPU to a GPU?</strong></p><p>It depends on a lot of factors, including how the software we’re running has been designed, and the precise CPU and GPU we’re comparing. For example, the low power processor in our laptop is going to be much slower than a big server processor. <strong>But a rule of thumb would be that networks train about five times faster on a GPU than on a CPU.</strong> That’s similar to what I’ve seen, and I know from my own experience that it’s just so much faster and easier to make progress when my network is training five or ten times faster, and I have all that extra time to experiment with new approaches and get fast feedback on how they work. Another good approach for getting fast feedback is to use transfer learning, to take advantage of networks that have already been trained instead of just starting from scratch every time.</p><h4>Deep Learning History</h4><p>Neural Networks go back all the way to the 1950s. That’s a great point. One of the fascinating things about neural networks, at least to me, is how long they’ve taken to become an overnight success. As far back as the late 90s there was a network called the <strong>LeNet built by Yann LeCun </strong>that the post office and banks used to read digits on mail and checks and it was incredibly important. But even after LeNet, not a lot of interest picked up in neural networks. Deep learning has only really taken off in the last five years. <strong>It’s kind of a puzzle why it took so long. Yeah, that’s a good question.</strong></p><p>The answer boils down to the increased availability of label data along with the greatly increased computational throughput of modern processors. For a long time, we didn’t have the huge label data sets that we needed to make deep learning work. Those data sets only became widely available with the rise of the Internet which made collecting and labeling huge data sets feasible. But even when we had big data sets, we often didn’t have enough computational power to make use of them. It’s only been in the last five years that processors have gotten big enough and fast enough to train large scale neural networks.</p><h4>Pre-trained Networks</h4><p>When we’re tackling a new problem with a neural network, it might help to start with an existing network that was built for a similar task and then try to fine-tune it for our own problem. There are a couple of good reasons to do this. First, existing neural networks can be really useful. If somebody has taken days or weeks to train a network already, then a lot of intelligence is stored in that network. Taking advantage of that work can accelerate our own progress. Second, sometimes the data set for the problem we’ll work on might be small. In those cases, looking for an existing network that’s designed for a problem similar to our own. If that network has already been trained on a larger data set, then we can use it as a starting point to help our own network generalize better. In order to do this, it makes sense to learn a little bit about the most prominent pre-trained networks that already exist.</p><h4>ImageNet</h4><p>From the past 5 years, the Internet had made it easier to generate and collect images, storage costs had dropped so that it was cheap to save large collections of images, and services like <strong>Amazon’s Mechanical Turk</strong> had even made it more cost-effective to label images. That confluence of factors gave rise to ImageNet, a huge database of hand-labeled images. And the <strong>ImageNet </strong>database gave rise to the <strong>ImageNet Large Scale Visual Recognition Competition.</strong></p><p><a href="http://www.image-net.org/">ImageNet</a></p><p>The ImageNet Large Scale Visual Recognition Competition is most famous as an annual competition, where teams from industry and academia try to build the best networks for object detection and localization. Kind of like this image. <strong>Is this a dog or a horse?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dnJptwFvrC9y4doXNDfEcw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@wildlittlethingsphoto?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Helena Lopes</a> on <a href="https://unsplash.com/s/photos/horse?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>It’s a horse.</blockquote><p>Anyway, this spurred really intense competition between teams in industry and academia to produce the best image classification network. And as these teams published their approaches, we learned a lot about the best ways to build neural networks. The first big breakthrough was in 2012, when the winning submission really changed the field. It was called <strong>AlexNet</strong>, and it looked a lot like Yann LeCun’s neural network from way back in 1998.</p><h4>AlexNet</h4><p>AlexNet was developed at the<strong> University of Toronto. </strong>Although the fundamental architecture of AlexNet resembled LeNet from 1998, AlexNet was a breakthrough in several respects. First and foremost, AlexNet used the massive parallelism afforded by GPUs to accelerate training. Using the best GPUs available in 2012, the AlexNet team was able to train the network in about a week. Additionally, AlexNet pioneered the use of Rectified Linear Units as an activation function and dropout is a technique for avoiding overfitting. In 2011, the year before AlexNet was developed, the winner of the ImageNet competition successfully classified 74% of images, or in the terminology of the competition, its error was 26%. The next year, AlexNet lowered its error to 15%. This was a huge leap forward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nL-huRg13PoL8vZp9ub3tQ.png" /><figcaption>AlexNet (Image by author)</figcaption></figure><blockquote>AlexNet is still used today as a starting point for building and training neural networks. Actually, engineers typically use a simplified version of AlexNet because in recent years we’ve discovered that some of AlexNet’s features aren’t really necessary, and so they’ve been removed. But most implementations of AlexNet that we’ll find online reflect these changes. Since AlexNet, a number of newer networks have been developed with even higher accuracy. But AlexNet is still one of the best understood and most widely used starting points for computer vision.</blockquote><h4>VGG</h4><p>In 2014, two different groups nearly tied in the ImageNet competition with the seven percent classification error. One of those networks is called VGGNet, or sometimes just VGG, and it came from the <strong>Visual Geometry Group at Oxford University.</strong> VGG has a simple and elegant architecture, which makes it great for transfer learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*FE6oU4srgZDEYLjO8oQZKw.png" /><figcaption>VGG Network (Image by author)</figcaption></figure><p>The VGG architecture is just a long sequence of three-by-three convolutions, broken up by two-by-two pooling layers, and finished by a trio of fully-connected layers at the end. Lots of engineers use VGG as a starting point for working on other image classification tasks, and it works really well. The flexibility of VGG is one of its great strengths.</p><h4>GoogleNet</h4><p>In 2014, Google published its own network in the ImageNet competition and in homage to Yann LeCun and LeNet, Google named their network, GoogLeNet. It’s spelled like GoogleNet but it’s pronounced GoogLeNet. In the ImageNet competition, GoogLeNet performed even a little better than VGG: 6.7% compared to 7.3% percent, although at that level, it kind of feels like we’re splitting hairs. GoogLeNet’s great advantage is that it runs really fast. The team that developed GoogLeNet developed a clever concept called an Inception module, which trains really well and is efficiently deployable.</p><blockquote>Do you remember inception?</blockquote><p>It’s called an <strong>inception module.</strong> It’s going to look a little more complicated. The idea is that at each layer of your ConvNet, we can make a choice, have a pooling operation, have a convolution and then we need to decide, is it the one by one convolution or a three by three or five by five. All of these are actually beneficial to the modeling power of our network. So why choose? Let’s use them all. <strong>Here’s what an inception module looks like.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*-IFLcE73UtmVz1w-lI0xgA.png" /><figcaption>The Naive Inception Module. (Source: <a href="https://arxiv.org/pdf/1409.4842v1.pdf">Inception v1</a>)</figcaption></figure><p>Instead of having a single convolution, we have a composition of average pooling followed by one by one, then a one by one convolution, then a one by one followed by a three by three, then a one by one followed by a five by five and at the top we simply concatenate the output of each of them. It looks complicated but what’s interesting is that we can choose these parameters in such a way that the total number of parameters in our model is very small, yet the model performs better than if we had a simple convolution. The inception modules create a situation in which the total number of parameters is very small. This is why GoogLeNet runs almost as fast as AlexNet. And of course GoogLeNet has great accuracy. Like I mentioned earlier, it’s ImageNet error was only 7%. GoogLeNet is a great choice to investigate if we need to run our network in real time, like maybe in a self-driving car.</p><h4>ResNet</h4><p>The 2015 ImageNet winner was a network from <strong>Microsoft Research</strong> called <strong>ResNet</strong>. ResNet claim to fame is that it has a massive <strong>152 layers</strong>. For contrast, AlexNet has eight layers, VGG has 19 layers, and GoogLeNet has 22 layers. ResNet is kinda like VGG and that the same structure is repeated again and again for layer after layer. The main idea was to add connections to the neural network that skip layers. So that very deep neural networks could practically be trained. ResNet achieves a loss of only three percent on ImageNet which is actually better than normal human accuracy.</p><h4>Conclusion</h4><p>AlexNet, VGG, GoogLeNet and ResNet are important neural network architectures we might want to use in future projects. And even if we build our own neural network from scratch, we’ll still want to fine-tune it. We can save our network as we train and then come back later to experiment with new data and additional layer or different hyperparameters.</p><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbf2e1463481" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Neural Networks For Self Driving Cars (Foundational Concepts — Part 2)]]></title>
            <link>https://sawhney-prateek97.medium.com/introduction-to-neural-networks-for-self-driving-cars-foundational-concepts-part-2-5963413460a6?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5963413460a6</guid>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 16:43:08 GMT</pubDate>
            <atom:updated>2022-09-08T16:43:08.408Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to Neural Networks For Self Driving Cars (Foundational Concepts — Part 2)</h3><h4>Foundational concepts in the fields of Machine Learning, Deep Neural Networks and Self Driving Cars</h4><p>Welcome to this Medium Article. This article is an extended version of the <strong>Introduction to Neural Networks For Self Driving Cars</strong> (Foundational Concepts Part — 1) 😀</p><p><a href="https://sawhney-prateek97.medium.com/introduction-to-neural-networks-for-self-driving-cars-foundational-concepts-part-1-4f696ec3ecd2">Introduction to Neural Networks For Self Driving Cars (Foundational Concepts Part — 1)</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*LSh88wi-dFEcwEUV_yJ6ZA.png" /><figcaption>Image by <a href="https://pixabay.com/users/ahmedgad-9403351/">ahmedgad</a> on <a href="https://pixabay.com/">Pixabay</a></figcaption></figure><h4>One-Hot Encoding</h4><p>So, as we’ve seen so far, <strong>all our algorithms are numerical</strong>. This means we need to input numbers, such as a score in a test or the grades, but the input data will not always look like numbers.</p><p>Let’s say the module receives as an input the fact that you got a gift or didn’t get a gift. <strong>How do we turn that into numbers?</strong> Well, that’s easy. If you’ve got a gift, we’ll just say that the input variable is 1. And, if you didn’t get a gift, we’ll just say that the input variable is 0. But, what if we have more classes as before or, let’s say, our classes are Duck, Beaver and Walrus?</p><blockquote>What variable do we input in the algorithm?</blockquote><p>Maybe, we can input a 0 or 1 and a 2, but that would not work because it would assume dependencies between the classes that we can’t have. So, this is what we do. We will come up with one variable for each of the classes. <strong>That’s one variable for Duck, one for Beaver and one for Walrus</strong>. Now, if the input is a duck then the variable for duck is 1 and the variables for beaver and walrus are 0. Similarly for the beaver and the walrus. We may have more columns of data but at least there are no unnecessary dependencies. <strong>This process is called The One-Hot Encoding</strong> and it will be used a lot for processing data.</p><h4>Maximum Likelihood</h4><p>So we’re still in our search for an algorithm that will help us pick the best model that separates our data well. Well, since we’re dealing with probabilities then just use them in our favor. Let’s say I’m a student and I have two models. One that tells me that my probability of getting accepted is <strong>80%</strong> and one that tells me the probability is<strong> 55%.</strong> Which model looks more accurate?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JlievuCMeFOn5lBrbRd4sA.jpeg" /><figcaption>A Sample Neural Network (Image by author)</figcaption></figure><blockquote>Well, if I got accepted then I’d say the better model is probably the one that says <strong>80%.</strong> What if I didn’t get accepted? Then the more accurate model is more likely the one that says <strong>55 percent</strong>. But I’m just one person. What if it was me and a friend? Well, the best model would more likely be the one that gives the higher probabilities to the events that happened to us, whether it’s acceptance or rejection. <strong>This sounds pretty intuitive.</strong></blockquote><p>The method is called <strong>maximum likelihood.</strong></p><p>What we will do is pick the model that gives the highest probability for the existing labels. Thus, by <strong>maximizing the probability,</strong> we can pick the best possible model.</p><h4>Cross-Entropy</h4><p>Cross entropy really says the following.</p><blockquote>If I have a bunch of events and a bunch of probabilities, how likely is it that those events happen based on the probabilities? If it’s very likely, then we have a <strong>small cross entropy</strong>. If it’s unlikely, then we have a <strong>large cross entropy.</strong></blockquote><h4>Gradient Descent</h4><p>So now let’s study <strong>gradient descent</strong>. So we’re standing somewhere in <strong>Mount ABC</strong> and we need to go down. So now the <strong>inputs of the functions are W1 and W2 </strong>and the <strong>error function is given by E.</strong> Then the gradient of E is given by the vector sum of the partial derivatives of E with respect to W1 and W2.</p><blockquote>This gradient actually tells us the direction we want to move if we want to increase the error function the most. Thus, if we take the negative of the gradient, this will tell us how to decrease the error function the most. And this is precisely what we’ll do.</blockquote><p>At the point we’re standing, we’ll take the negative of the gradient of the error function at that point. Then we take a step in that direction. Once we take a step, we’ll be in a <strong>lower position</strong>. So we do it again, and again, and again, until we are able to get to the bottom of the mountain. So this is how we calculate the gradient.</p><p>But what matters here is the <strong>gradient of the error function.</strong> The gradient of the error function is precisely the vector formed by the partial derivative of the error function with respect to the weights and the bias. Now, we take a <strong>step in the direction of the negative of the gradient.</strong> As before, we don’t want to make any dramatic changes, so we’ll introduce a smaller learning rate alpha. For example, 0.1. And we’ll multiply the gradient by that number. Now taking the step is exactly the same thing as updating the weights and the bias as follows.</p><blockquote>The weight <strong>Wi will now become Wi prime</strong>. Given by <strong>Wi minus alpha times the partial derivative of the error, with respect to Wi.</strong> And the bias will now become <strong>b prime</strong> given by <strong>b minus alpha times partial derivative of the error with respect to b</strong>. Now this will take us to a prediction with a lower error function. So, we can conclude that the prediction we have now with weights W prime b prime, is better than the one we had before with weights W and b. This is precisely the gradient descent step.</blockquote><h4>Gradient Descent vs The Perceptron Algorithm</h4><p>So now let’s compare the <strong>Gradient Descent algorithm and the Perceptron algorithm.</strong> In the Gradient Descent algorithm, we take the weights and change them from <strong>Wi to Wi + alpha * Y_hat-Y * Xi.</strong></p><p>In the Perceptron algorithm, not every point changes weights, only the misclassified ones. Here, if X is misclassified, we’ll change the weights by adding Xi to Wi if the point label is positive, and subtracting if negative. <strong>Now the question is, are these two things the same?</strong></p><p>Well, let’s remember that in that Perceptron algorithm, the labels are one and zero. And the<strong> predictions Y_hat are also one and zero</strong>. So, if the point is correct, classified, then<strong> Y — Y_hat = 0 because Y is equal to Y_hat.</strong></p><p>Now, if the point is labeled blue, then Y=one. And if it’s misclassified, then the prediction must be Y_hat=0. So Y_hat-Y=(-1). Similarly, with the points labeled red, then Y=0 and Y_hat=1. So, Y_hat-Y=1.</p><p>But let’s study Gradient Descent even more carefully. Both in the Perceptron algorithm and the Gradient Descent algorithm, <strong>a point that is misclassified tells a line to come closer because eventually</strong>, it wants the line to surpass it so it can be in the correct side. Now, what happens if the point is correctly classified?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*BtE9LPkd9_aYLOaFbf2mYg.png" /><figcaption>A Sample Illustration of weights (Image by author)</figcaption></figure><p>Well, the Perceptron algorithm says do absolutely nothing. In the Gradient Descent algorithm, you are changing the weights. But what is it doing? Well, if we look carefully, what the point is telling the line, is to go farther away. And this makes sense, right? <strong>Because if you’re correctly classified, say, if you’re a blue point in the blue region, you’d like to be even more into the blue region, so your prediction is even closer to one, and your error is even smaller. </strong>Similarly, for a red point in the red region. So it makes sense that the point tells the line to go farther away. And that’s precisely what the Gradient Descent algorithm actually does.</p><blockquote><strong>The misclassified points asks the line to come closer and the correctly classified points asks the line to go farther away.</strong> The line listens to all the points and takes steps in such a way that it eventually arrives to a pretty good solution.</blockquote><h4>Multiclass Classification</h4><p>It seems that neural networks work really well when the problem consist on classifying <strong>two classes</strong>. For example, if the model predicts a probability of receiving a gift or not then the answer just comes as the output of the neural network. <strong>But what happens if we have more classes?</strong></p><p>Say, we want the model to tell us if an image is a <strong>duck, a beaver, or a walrus. </strong>Well, one thing we can do is create a neural network to predict if the image is a duck, then another neural network to predict if the image is a beaver, and a third neural network to predict if the image is a walrus. Then we can just use Softmax or pick the answer that gives us the highest probability. But this seems like overkill, right?</p><blockquote>The first layers of the neural network should be enough to tell us things about the image and maybe just the last layer should tell us which animal it is. As a matter of fact, this is exactly the case. So what we need here is to add more nodes in the output layer and each one of the nodes will give us the probability that the image is each of the animals. Now, we take the scores and apply the Softmax function that was previously defined to obtain well-defined probabilities. <strong>This is how we get neural networks to do multi-class classification.</strong></blockquote><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5963413460a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Neural Networks For Self Driving Cars (Foundational Concepts Part — 1)]]></title>
            <link>https://sawhney-prateek97.medium.com/introduction-to-neural-networks-for-self-driving-cars-foundational-concepts-part-1-4f696ec3ecd2?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f696ec3ecd2</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 05 Sep 2022 14:46:11 GMT</pubDate>
            <atom:updated>2022-09-05T14:46:11.350Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to Neural Networks For Self Driving Cars (Foundational Concepts Part — 1)</h3><h4>Foundational concepts in the fields of Machine Learning and Deep Neural Networks</h4><p>Welcome to this Medium Article. Perhaps the hottest topic in the world right now is <strong>artificial intelligence</strong>. When people talk about this, they often talk about machine learning, and specifically, neural networks. What people have done in the last decades kind of abstracted the theory into a basis set of equations that emulate a network of artificial neurons. Then people have invented ways to train these systems based on data. So, rather than instructing a machine with rules like a piece of software, these neural networks are trained based on data. So, now we’re going to learn the very basics for, <strong>perception</strong>,<strong> error-functions</strong>, terminology that doesn’t make sense yet, but by the end of this medium article, you should be able to write and train your own neural network. That’s a ton of fun.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*xNrO9Ll88Ri8EqseWvcjpA.jpeg" /><figcaption>Introduction to Neural Networks (Image by author)</figcaption></figure><h3>Introduction</h3><p>Now we will learn how to use one of the most exciting tools and self-driving car development, deep neural networks. A deep neural network is just a term that describes a <strong>big multi-layer neural network</strong>. And a neural network is a machine learning algorithm that you can train using input like camera images or sensor readings and generate output like what’s steering angle the car should set or how fast it should go on the road. The idea is that the neural network learns from observing the world. You don’t have to teach it anything specific.</p><blockquote><strong>Deep learning</strong> is just another term for using deep neural networks to solve problems and it’s become really important for self-driving cars. But deep learning is relatively new. Until the last few years, computers simply weren’t fast enough to train deep neural networks effectively. Now, however, automotive manufacturers can apply deep learning techniques to drive cars in real time.</blockquote><p>Because deep learning is so new, automotive engineers and researchers are still experimenting with just how far it can take us, but deep learning has already revolutionized segments of autonomous driving like computer vision and it has the potential to entirely change the way we develop self-driving cars. Some of the most important recent breakthroughs in the performance of self-driving cars, have come from machine learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*PH56rlQ669mMy1cC8hUfNw.png" /><figcaption>A Sample Neural Network (Image by <a href="https://pixabay.com/users/gdj-1086657/">GDJ</a> on <a href="https://pixabay.com/">Pixabay</a>)</figcaption></figure><h4>Foundational concepts in the fields of machine learning and deep neural networks</h4><p>Machine learning is a field of artificial intelligence that relies on computers to learn about the environment from data, instead of relying on the rule set by computer programmers. Deep learning is an approach to machine learning, that uses deep neural networks. Deep learning uses this one tool to accomplish an amazing array of objectives, from speech recognition, to driving a car.</p><p><strong>Perceptron</strong>, which is the fundamental unit of a neural network. We will learn how to combine these units into a simple neural network. Before we start learning about neural network though, let’s go over the basics of machine learning 😄</p><h4>So you may be wondering why are these objects called neural networks?</h4><p>Well, the reason why they’re called neural networks is because perceptions kind of look like neurons in the brain. And what the perception does, it calculates some equations on the input and decides to return a one or a zero. In a similar way neurons in the brain take inputs coming from the dendrites. These inputs are <strong>nervous impulses.</strong> So what the neuron does is it does something with the nervous impulses and then it decides if it outputs a nervous impulse or not through the axon. The way we create neural networks in our development is by concatenating these perceptions so we’ll be mimicking the way the brain connects neurons by taking the output from one and turning it into the input for another one.</p><h4>What are Error Functions?</h4><p><strong>An error function</strong> is something that tells <strong>how far we are from the actual solution.</strong> For example, if I’m here and my goal is to get to a nearby plant, an error function will just tell me the distance from the plant. My approach would then be to look around myself, check in which direction I can take a step to get closer to the plant, take that step and then repeat. Here the error is simply the distance from the plant.</p><h4>Here is obvious realization of the error function:</h4><p>We’re standing on top a mountain, <strong>Mount ABC</strong> and I want to descend but it’s not that easy because it’s cloudy and the mountain is very big, so we can’t really see the big picture. What we’ll do to go down is we’ll look around us and we consider all the possible directions in which we can walk.</p><blockquote>Then we pick a direction that makes us descend the most. So we take a step in that direction. Thus, we’ve decreased the height. Once we take the step and start the process again and again always decreasing the height until we go all the way down the mountain and thus, minimizing the height. In this case the key metric that we use to solve the problem is the height of the mountain. We’ll call the height the error.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*wcJyRtbr8yTKIrUPbsqfkA.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/susnpics-10235783/">susnpics</a> on <a href="https://pixabay.com/">Pixabay</a></figcaption></figure><p>The error is what’s telling us how badly we’re doing at the moment and how far we are from an ideal solution. And if we constantly take steps to decrease the error then we’ll eventually solve our problem, descending from Mt. ABC. Some of you may be thinking, wait, that doesn’t necessarily solve the problem. What if I get stuck in a valley, <strong>a local minimum,</strong> but that’s not the bottom of the mountain. This happens a lot in machine learning! It’s also worth noting that many times a local minimum will give us a pretty good solution to a problem. <strong>This method is called gradient descent.</strong></p><h4>Softmax Function</h4><p>Let’s say we have a machine learning model that will predict if we receive a gift or not. So, the model use predictions in the following way. It says, the probability that we get a gift is 0.8, which automatically implies that the probability that we don’t receive a gift is 0.2.</p><blockquote><strong>And what does the model do?</strong></blockquote><p>What the model does is take some inputs. For example, is it your birthday or have it been good all year? And based on those inputs, the ML model calculates a linear model which would be the score. Then, the probability that we get the gift or not is simply the <strong>sigmoid function</strong> applied to that score generated by the model. Now, what if you had more options than just getting a gift or not a gift? Let’s say we have a model that just tell us<strong> what animal we just saw,</strong> and the options are a duck, a beaver and a walrus. We want a machine learning model that tells an answer along the lines of, the probability of a duck is 0.67, the probability of a beaver is 0.24, and the probability of a walrus is 0.09. <strong>Notice that the probabilities need to add to one</strong>. Let’s say we have a linear model based on some inputs. The inputs could be, does it have a beak or not? Number of teeth. Number of feathers. Hair, no hair. Does it live in the water? Does it fly? We will a calculate linear function based on those inputs, and let’s say we get some scores. So, the duck gets a score of two, and the beaver gets a score of one, walrus gets a score of zero. And now the question is, how do we turn these scores into probabilities?</p><blockquote>The first thing we need to satisfy with probabilities is as we said, they need to add to one. So the two, the one, and the zero do not add to one. The second thing we need to satisfy is, since the duck had a higher score than the beaver and the beaver had a higher score than the walrus, then we want the probability of the duck to be higher than the probability of the beaver, and the probability of the beaver to be higher than the probability of the walrus.</blockquote><p>Here’s a simple way of doing it. Let’s take each score and divide it by the sum of all the scores. The two becomes two divided (2+1+0), the one becomes one divided by (2+1+0), and the zero becomes zero divided (2+1+0). This kind of works because the probabilities we obtain are two thirds for the duck, one third for the beaver, and zero for the walrus. That works but there’s a little problem. Let’s think about it. <strong>What could this problem be?</strong></p><blockquote><strong>The problem is the following.</strong></blockquote><p>What happens if our scores are negative? This is completely possible since the scores are linear function which could give negative values. What if we had, say, scores of 1, 0 and (-1)? Then, one of the probabilities would turn into one divided by (1+0+(-1)) which is zero, and we know very well that we cannot divide by zero. This unfortunately won’t work, but the idea is good.</p><p>How can we turn this idea into one that works all the time even for negative numbers? Well, it’s almost like we need to turn these scores into positive scores. How do we do this? Is there a function that can help us?</p><blockquote><strong>The answer is Softmax.</strong></blockquote><p>The <strong>softmax</strong> function is a function that turns a vector of K real values into a vector of K real values that sum equal to 1. The input values can be positive, zero, negative, or greater than one, but the <strong>softmax</strong> transforms them into values between 0 and 1, so that they can be interpreted as probabilities 😀</p><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f696ec3ecd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Convolutional Neural Networks]]></title>
            <link>https://sawhney-prateek97.medium.com/introduction-to-convolutional-neural-networks-c56c057e24e9?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c56c057e24e9</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Sat, 03 Sep 2022 16:11:16 GMT</pubDate>
            <atom:updated>2022-09-03T16:11:16.187Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introductory concepts in the field of Image Recognition using Convolutional Neural Networks</h4><p>One of the very popular ways to structure a <strong>neural network</strong> is called a <strong>Convolutional Neural Network.</strong> It was invented by <strong>Yann LeCun</strong> about 30 years ago, but it’s become incredibly popular for things like image processing, and processing large datasets. So, let’s talk about Convolutional Neural Networks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tPKC0gdEBLAlWPNgczCucQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@qrupt?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Victor Grabarczyk</a> on <a href="https://unsplash.com/s/photos/dog?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>Statistical Invariance</h4><p>Here’s an example. We have an image, and we want our network to say it’s an image with a <strong>cat</strong> in it. It doesn’t really matter where the cat is, it’s still an image with a cat. If our network has to learn about kittens in the left corner, and about kittens in the right corner independently, that’s a lot of work that it has to do. How about we telling it, instead explicitly, that objects and images are largely the same whether they’re on the left or on the right of the picture.</p><p>That’s what’s called <strong>translation invariance.</strong> Different positions, same kitten. Yet another example. Imagine we have a long text that talks about kittens. <strong>Does the meaning of kitten change depending on whether it’s in the first sentence or in the second one?</strong> Mostly not, so if we’re trying to network on text, maybe we want the part of the network that learns what a kitten is to be reused every time we see the word kitten, and not have to re-learn it every time. The way we achieve this in our own networks, is using what’s called <strong>weight sharing.</strong> When we know that two inputs can contain the same kind of information, then we share their weights. And train the weights jointly for<br>those inputs. It’s a very important idea. Statistical invariants, things that don’t change on average across time or space, are everywhere. For images, the idea of weight sharing will get us to study cnn’s. For text and sequences in general, it will lead us to embeddings and recurrent neural networks.</p><h4>Convolutional Neural Networks (CNN)</h4><p>Let’s talk about Convolutional Networks, or<strong> ConvNets</strong>. ConvNets are neural networks that share their parameters across space. Imagine we have an image. It can be represented as a flat pancake. It has a width, a height, and<br>because we typically have red, green, and blue channels, it also has a depth. In this instance, depth is three. That’s our input. Now, imagine taking a small patch of this image, and running a tiny neural network on it, with K outputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*ZCjPUFrB6eHPRi4eyP6aaA.gif" /><figcaption>Convolution Operation (Image by author)</figcaption></figure><p>Now, let’s slide that little neural network across the image without changing the weights. Just slide across invertically like we’re painting it with a brush. On the output, we’ve drawn another image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPYnP1OA_t214eEF2M_RuA.png" /><figcaption>Patch over a dog image (Image by author)</figcaption></figure><p>It’s got a different width, a different height. And more importantly, it’s got a different depth. Instead of just R, G, and B, now, we have an output that’s got many colored channels, K of them. This operation is called the <strong>convolution.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YUGQvzLoZ003qvfsM9_CKQ.png" /><figcaption>Shifted Patch over a dog image (Image by author)</figcaption></figure><p>If our patch size were the size of the whole image, it would be no different than the regular layer of a neural network. But because we have this small patch instead, we have many fewer weights and they are shared across space. A convolutional neural network is going to basically be a deep network where instead of having stacks of matrix multiply layers, we’re going to have stacks of convolutions. The general idea is that they will form a pyramid. At the bottom, we have this big image, but very shallow just R, G, and B. We’re going to apply convolutions that are going to progressively squeeze the spacial dimensions while increasing the depth which corresponds roughly to the semantic complexity of your representation.</p><p>At the top, we can put our classifier. We have a representation where all this spacial information has been squeezed out, and only parameters that map to content of the image remain. So that’s the general idea. If we’re going to implement this, there are lots of little details to get right, and a fair bit of lingo to get used too. We’ve know the concept of <strong>Patch and Depth.</strong> Patches are sometimes called <strong>Kernels.</strong> Each pancake in our stack is called a feature map.</p><blockquote>Another term that we need to know is <strong>stride. It’s the number of pixels, so that we’re shifting each time we move our filter</strong>. The stride of one makes the output roughly the same size as the input. <strong>A stride of two means it’s about half the size.</strong> I say roughly because it depends a bit about what we do at the edge of our image.</blockquote><p>Either we don’t go pass the edge, and it’s often called valid padding as a shortcut. Or we go off the edge and pad with zeros in such a way that the output map size is exactly the same size as the input map. That is often called <strong>same padding </strong>as a shortcut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*fQPS6ZGiCteIdGDgDBZQ4g.jpeg" /><figcaption>Hierarchy Diagram showing detection at various layers of a convolutional neural network (Image by author)</figcaption></figure><p>That’s it, we can build a simple convolutional neural network with just this. Stack up our convolutions which thankfully we don’t have to implement ourselves. Then use triads to reduce the dimensionality and increase the depth of our network layer after layer. And once we have a deep and narrow presentation, connect the whole thing to a few regular, fully connected layers, and we’re ready to train our classifier. You might wonder what happens to training and to chain rule, in particular, when you use shared weights like this. Nothing really happens, the math just works. You just add up the derivatives for all the possible locations on the image.</p><h4>Exploring the Design Space</h4><p>Now that we’ve seen what a simple convolutional neural network looks like, there are many things that we can do to improve it. We’re going to talk about two of them:</p><ol><li><strong>Pooling</strong></li><li><strong>1x1 Convolutions</strong></li></ol><p>The first improvement is a better way to reduce the spatial extent of our future maps in the convolutional pyramid. Until now, we’ve used <strong>striding </strong>to shift<br>the filters by a few pixels each time and reduce the feature map size. This is a very aggressive way to down sample an image. <strong>It removes a lot of information. </strong>What if instead of skipping one in every two convolutions, we still run with a very small stride, say for example, one but then took all the convolutions in a neighborhood and combine them somehow?</p><blockquote>That operation is called<strong> pooling,</strong> and there are a few ways to go about it. The most common is the max pooling. At every point of on the feature map, look at a small neighborhood around that point and compute the maximum of all the responses around it. There are some advantages to using <strong>max pooling.</strong></blockquote><p><strong>First,</strong> it doesn’t add to our number of parameters, so we don’t risk an increase in over fitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*GksqN5XY8HPpIddm5wzm7A.jpeg" /><figcaption>Max Pooling (Image by author)</figcaption></figure><p><strong>Second,</strong> it simply often yields a<strong> more accurate model.</strong> However, since the convolutions that went below run at lower stride, the muddle then becomes a lot more expensive to compute. And now, we have even more hyper parameters to worry about, the pooling region size and the pooling stride. And no, they don’t have to be the same. <strong>A very typical architecture for a cnn is a few layers alternating convolutions and max pooling, followed by a few fully connected layers at the top</strong>. The first famous model to use this architecture was <strong>Lenet-5 designed by Yan Lecun</strong> to do character recogniztion back in 1998. Modern convolutional networks, such as<strong> AlexNet, </strong>which famously won the competitive ImageNet object recognition challenge in 2012, used the same architecture with a few wrinkles.</p><p>Another notable form of pooling is <strong>average pooling</strong>. Instead of taking the max, just taking an average over the window of pixels around a specific location.</p><h4>1x1 Convolutions</h4><p>Also, I want to introduce you to another idea. It’s the idea of <strong>1 x 1 convolutions. </strong>You might wonder, why one would ever want to use 1 x 1 convolutions?</p><p>They’re not really looking at a patch of the image just that one pixel. Look at the classic convolution setting, it’s basically a small classifier for a patch of the image but it’s only a linear classifier. But if we add a 1 x 1 convolution in the middle, suddenly we have a mini neural network running over the patch<br>instead of a linear classifier. Interspersing our convolutions with 1 x 1 convolutions is a very inexpensive way to make our models deeper and<br>have more parameters, without completely changing their structure.</p><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><p><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c56c057e24e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localization Overview for Self Driving Cars]]></title>
            <link>https://sawhney-prateek97.medium.com/localization-overview-for-self-driving-cars-49297ad796e7?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/49297ad796e7</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[localization]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 04:52:58 GMT</pubDate>
            <atom:updated>2022-09-03T16:46:50.783Z</atom:updated>
            <content:encoded><![CDATA[<h4>Localization overview for autonomous vehicles or self driving cars</h4><p>Welcome to this medium article based on Artificial Intelligence for Robotics. In this medium article we’ll cover the localization concepts and study about total probability and sense and move methodology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ukn11PZBk-POS-wgPQEWHA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@plhnk?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Paul Hanaoka</a> on <a href="https://unsplash.com/s/photos/cars-3d?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>Introduction</h4><p>The very first problem based on perception is called localization. It involves a robot that’s lost in space. It could be a car. It could be a mobile robot. So there is an environment, and the poor robot has no clue where it is. Similarly, we might have a car driving on a highway, and this car would like to know where it is. Is it inside the lane or outside? Now the traditional way to solve this problem is by using satellites. Cars perceive the signals emitted by satellites. That’s known as GPS, short for “global positioning system,” and it’s what we have in your dashboard if we have a car with GPS that shows us the maps and shows us where we are. The only disadvantage of GPS is that its not very accurate. It’s really common for a car to believe to be here but it has 2 meters all the way up to 10 meters of error. So if we try to stay in the lane with 10 meters of error, we’re far off, and we’re driving right over here, and we crash. So for the autonomous vehicles, to be able to follow localization, the error should be very less like 2–10 centimeters. Then we can drive with GPS in lanes. Now the main question is, what can we use to figure out where are we with an accuracy of 10 cm?</p><p>That’s the localization question.</p><p>Localization plays a key role in self driving cars. We record images of the road surface and then use the techniques I’m just about to mention here to find out exactly where the robot is. It does so within a few centimeters of accuracy. Also, makes the self driving vehicle stay inside the lane even if there are no lane markings. So localization has a lot of math, but before diving into mathematical detail, I want to give you an intuition for the basic principles.</p><h4>Total Probability</h4><p>Let us begin the visualization with a robot. Let’s assume the robot doesn’t know where it is. Then we would model this with a function where the vertical axis is the probability for any location in this world, and the horizontal axis corresponds to all the places in this 1-dimensional world. The confusion of the robot is given by the robot’s current belief about where it might be. This could be modeled by a uniform function that assigns equal weight to every possible place in this world. It’s called the state of maximum confusion. For the process of localization, the world must have some distinctive features. Let’s assume there are 3 different landmarks in the world. There are three doors.</p><p>For the sake of the argument, let’s assume they all look alike, so they’re not distinguishable, but we can distinguish the door from the non-door area — from the wall. Now, let’s figure out how the robot will perform the localization process all by itself by assuming it senses, and it senses that it’s standing right next to a door. So all it knows now is that it is located, likely, next to a door. How would this affect our belief?</p><p>Here is the critical step for localization. If we understand this step, we would clearly understand localization. <strong>Our belief function is transformed by the measurement of a door, defined over possible locations, to a new function. All the other locations have a decreased belief whereas for the three locations adjacent to the doors, we have an increased belief.</strong></p><blockquote>This is a probability distribution that assigns higher probability for being next to a door, and it’s called the <strong>posterior belief where the word “posterior” means it’s after a measurement has been taken</strong>.</blockquote><p>Now, the key aspect of this belief is that we still don’t know where we are. There are 3 possible door locations, and in fact, it might be that the sensors were erroneous, and we accidentally saw a door where there’s none. So there is still a residual probability of being in these places over here, but these three bumps together really express our current best belief of where we are. This representation is absolutely core to probability and to mobile robot localization. Now let’s assume the robot moves.</p><p>Say it moves to the right by a certain distance. Then we can shift the belief according to the motion. Obviously, the robot knows its heading direction. It’s moving to the right for example, and it knows roughly how far it moved. Now, robot motion is somewhat uncertain. We can never be certain where the robot moved. <strong>The process of moving those beliefs to the right side is technically called a convolution.</strong> Let’s now assume the robot senses again, and for the sake of the argument, let’s assume it sees itself right next to a door again, so the measurement is the same as before.</p><h4>Sense and Move</h4><p>Now, localization is nothing else but the iteration of “sense” and “move.” There is an initial belief that is tossed into this loop. Localization cycles through these — move, sense, move, sense, move, sense, move, sense, move, sense cycle. Every time the robot moves, it loses information as to where it is. That’s because robot motion is inaccurate. Every time it senses it gains information. That is manifest by the fact that after motion, the probability distribution is a little bit flatter and a bit more spread out. And after sensing, it’s focused a little bit more. In fact, as a foot note, there is a measure of information called “entropy.”</p><p>Here is one of the many ways you can write it: [-Ʃp(xi)log p(xi)] as the expected log (logarithmic) likelihood of the probability of each grid cell. Without going into detail, this is a measure of information that the distribution has, and it can be shown that the update step, the motion step, makes the entropy go down, and the measurement step makes it go up.</p><h4>Summary</h4><p>We learned that localization maintains a function over all possible places where a road might be, where each cell has an associated probability value. The measurement update function, or “sense,” is nothing else but a product in which we take those probability values and multiply them up or down depending on the exact measurement. Because the product might violate the fact that probabilities add up to 1, there was a product followed by normalization. Motion was a convolution. This word itself might sound cryptic, but what it really means is for each possible location after the motion, we reverse engineered the situation and guessed where the world might have come from and then collected, we added, the corresponding probabilities. Something as simple as multiplication and addition solves all of localization and is the foundation for autonomous driving.</p><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49297ad796e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Object Detection for Self Driving Cars]]></title>
            <link>https://sawhney-prateek97.medium.com/introduction-to-object-detection-for-self-driving-cars-8c4c78b853f9?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c4c78b853f9</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 04:52:10 GMT</pubDate>
            <atom:updated>2022-09-03T16:47:43.682Z</atom:updated>
            <content:encoded><![CDATA[<h4>Foundational concepts like Gradient features, Sliding window protocol, Color Histogram features and Training a Classifier</h4><p>In previous medium articles, we’ve accomplished the task of finding what we’re looking for in images. <strong>Check in references.</strong> For the most part we used colors and gradients. Now that we’re familiar with some popular classifiers, we’re going to go deeper into our exploration of colors and gradients to see how we can locate and classify objects in images. Image classification is tricky. And it becomes even trickier when we don’t know exactly where in an image our objects of interest will appear or what size they’ll be or even how many of them we might find.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pbj8pQ_SyJQj7JWEWmN0VQ.jpeg" /><figcaption>Image by <a href="https://unsplash.com/@danielcgold?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Dan Gold</a> on <a href="https://unsplash.com/s/photos/car?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Coming up, we’ll focus on the task of detecting vehicles in images taken from a camera mounted on the front of a car. But the same principles apply to pedestrian detection, or traffic sign detection, or identifying any object we might be looking for in an image. In this medium article, we’ll practice searching for objects in images. And we’ll explore what features are the most useful input for our classifier. With those tools, we can then work on tracking vehicles in a video stream.</p><h4>Introduction</h4><p>Knowing where the other vehicles are on the road and being able to anticipate where they’re heading next is essential in a self-driving car. Also, determining things like how far away they are, which way they’re going, and how fast they’re moving. Much the same way as we do with our own eyes as we drive. <strong>Object detection and tracking is a main concept in advance computer vision.</strong> We’ll first explore what kind of visual features we can extract from images in order to reliably classify vehicles. Next, we’ll look into searching an image for detections. And then we’ll track those detections from frame to frame in a video stream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4KJ9-orMVqxG40fGecMoPA.jpeg" /><figcaption>Image by <a href="https://unsplash.com/@ev25?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Evgeny Tchebotarev</a> on <a href="https://unsplash.com/s/photos/car?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>With traditional computer vision approaches we basically tune all the parameters by hand. Which gives us a lot of intuition about what works and why. When it comes to things like <strong>image classification</strong>, in many cases a deep learning approach works even better for the same tasks. But can seem like kind of a black box. We’re not quite sure why it works. By learning both approaches, we can gain maximum insight and get the best performance in our algorithms.</p><h4>Object Detection Overview</h4><p>Recognizing what’s in an image is the essence of computer vision. When we look at the world through our own eyes, we’re constantly performing classification tasks with our brain. And in the case of self-driving cars, reliable object detection and classification are essential to giving the car to see the world just like we do. We’ll also come across with the methods for separating false positives from real detections and in track the real detections from one frame to the next. Well, like any good machine learning problem, it all begins with feature extraction. So, first we’ll look at how to compute features that we can use to reliably identify cars in our images.</p><h4>Introduction to Features</h4><p>We need to figure out what differentiates the objects of interest from the rest of the image. We’ve already seen that things like colors and gradients can be good differentiators but let’s give them an identity. All of these potential characteristics are features that we could use. What features are more important may depend upon the appearance of the objects in question. In most applications, we’ll end up using a combination of features that give us the best results.</p><h4>Color Features</h4><p>The simplest feature we can get from images consists of raw color values. For instance, here is an image which contains a car.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lFTfhH2ACGQa7aXQx3iDHQ.jpeg" /><figcaption>Sample Image (Image by author)</figcaption></figure><p>Let’s say you want to find out whether some region of a new test image contains a car or not.<strong><em> What do we do?</em></strong></p><blockquote>Well, using our known car image as is, you can simply find the image difference between the car image and the test region, and see the difference is small. This basically means subtracting the corresponding color values, aggregating the differences and comparing it with the threshold.</blockquote><p>Alternatively, we could compute the correlation between the car image and test region and check if that is high. Either way, this general approach is known as <strong><em>template matching</em></strong>. Our known image is the template or model and we try to match it with regions of the test image. Template matching does work in limited circumstances but isn’t very helpful for our case. <strong>Can you guess why?</strong></p><h4>Color Histogram Features</h4><p>In template matching, we depend on raw color values laid out in a specific order, and that can vary a lot, so we need to find some transformations that are robust to changes in appearance.</p><blockquote><strong>An image template is useful for detecting things that do not vary in their appearance much. For instance, icons or emojis on the screen. But for most real world objects that do appear in different forms, orientation, sizes, this technique doesn’t work quite well.</strong></blockquote><p>Once a transform is to compute the histogram of color values in an image. When we compare the histogram of a known object with regions of a test image, locations with similar color distributions will reveal a close match. Here, we have removed our dependents on structure, that is, we are no longer sensitive to a perfect arrangement of pixels. Therefore, objects that appear in slightly different aspects and orientations will still be matched. Variations and image size can also be accommodated by normalizing the histograms. However, note that we are now solely relying on the distribution of color values which might match some unwanted regions.</p><h4>Color Spaces</h4><p>Whether we use raw colors directly or build a histogram of those values, we still haven’t solved the problem of representing objects of the same class that can be of different colors. That is, we still haven’t achieved color and variance. If we take an image of a car and look at analyse how its color values are distributed in the RGB color space. That is, using red, green, and blue intensities as three coordinates. Sometimes, the red and blue cars’ pixels are clustered into two separate groups. Although we could come up with a scheme to identify these groups using RGB values, it can get complicated very quickly as we try to accommodate different colors.</p><h4>Gradient and HOG Features</h4><p>So, far we’ve been manipulating and transforming color values. But they only capture one aspect of an object’s appearance. When we have a class of objects that can vary in color, structural ques like gradients or edges might give us a more robust presentation. Let’s look at this realistic image, for example, this 64 by 64 pixel image of a car. And let’s compute the gradient magnitudes and directions at each pixel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/1*VmBM_2PRHOopk1kmgGPGyg.png" /><figcaption>64 x 64 Pixel Image of a car (Image by author)</figcaption></figure><p>Now, instead of using all these individual values, let’s group them up into small cells, say, of size 8 by 8 pixels each. Inside each cell is where the magic happens. We will compute a histogram of gradient directions or orientations from each of the 64 pixels within the cell. The gradient samples are distributed into, say, nine orientation bins, and summed up. We typically won’t need any more accuracy at this small scale. A better way to visualize the histogram for an individual cell would be to add up the contributions for samples in each orientation bin to get a sort of star with arms of different lengths. The direction with the longest arm is the dominant gradient direction in the cell. Note that the histogram is not strictly a count of the number of samples in each direction. Instead, we sum up the gradient magnitude of each sample. So stronger gradients contribute more weight to their orientation bin, and the effect of small random gradients due to noise, etc., is reduced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4V-wynxhetTifFSL7o4vA.jpeg" /><figcaption>Color L Channel and HOG Visualization (Image by author)</figcaption></figure><p>In other words, each pixel in the image gets a vote on which histogram bin it belongs in based on the gradient direction at that position. But the strength or weight of that vote depends on the gradient magnitude at that pixel. When we do this for all the cells, we begin to see a representation of the original structure emerge. As demonstrated with simpler shapes before, something like this can be used as a signature for a given shape. This is known as a histogram of oriented gradients, or HoG feature.</p><blockquote>The main advantage now is that we have built in the ability to accept small variations in the shape, while keeping the signature distinct enough. How accommodating or sensitive the feature is can be tweaked by varying parameters such as the number of orientation bins, grid of cells, cell sizes, adding any overlap between cells, etc. A number of other enhancements are used in practice, including normalizing for intensity across small blocks of cells, etc.</blockquote><h4>Combining Features</h4><p>As noted before, it’s not necessary to use only one kind of feature for object detection. We can combine both color-based and shape-based features. After all, they complement each other in the information they capture about a desired object. In fact, a variety of features can help us design a more robust detection system. However, we do need to be careful about how we use them. For example, assume that we are using HSV values as one input feature with the flatten vector containing<strong> a elements. </strong>And HoG as the other feature with<strong> b elements</strong>. The simplest way of combining them is to concatenate the two. HSV and HoG into a long <strong>a + b element vector</strong>. If we visualize this vector as a simple bar plot, we might notice a difference in magnitude between the color-based and gradient-based features. This is because they represent different quantities. <strong>A normalization step may prevent one type from dominating the other in later stages.</strong> Also note that there might be a lot more elements of one type than the other. This may or may not be a problem in itself, but it’s generally a good idea to see if there are any redundancies in the combined feature vector. For instance, could use a decision tree to analyze the relative importance of features, and drop the ones that are not contributing much.</p><h4>Building a Classifier</h4><p>A classic approach is to first design a classifier that can differentiate car images from non-car images, and then run that classifier across an entire frame sampling small patches along the way. The patches that classified as car are the desired detections. For this approach to work properly, we must train our classifier to distinguish car and non-car images.</p><p>To train any classifier, we need labeled data. Lots of it. In this case, the two classes we would like to distinguish are car and non-car images. So we need samples of both. If we only have full video frames available, we need to crop out regions and scale them to a fixed size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQ258ZKPGwG7FZsA7F5ZJQ.jpeg" /><figcaption>A kind of Dataset needed (Image by author)</figcaption></figure><p>Ideally we want a balanced data set. That is the number of car and non-car images should be roughly equal. If that’s not the case, we’re under risk of the classifier trying to predict everything as belonging to the majority class. There are some techniques for handling imbalanced data sets, for example, <strong>duplicate some samples from the smaller class to balance the counts. For vehicle classification, if we don’t have enough non-car images we could simply extract more from video frames</strong>. Okay, once we have a sizable data set, we need to split it into two collections. <strong>A training set and a test set.</strong> As the names suggest, we will only use images from the training set when training our classifier and then check how it performs on unseen examples from the test set. To avoid any possible ordering effects in the data, we should <strong>sample or shuffle the data set</strong> randomly when splitting it for training and testing. Even within the training and test sets, we should aim for a balance between the number of car and non car images. All of this <strong>preprocessing </strong>might seem like a lot of work but machine learning algorithms work on a principle of garbage in, garbage out. So we need to be careful about what we feed them.</p><h4>Training a Classifier</h4><p>The training phase essentially consists of extracting features for each sample in the training set, and supplying these feature vectors to the training algorithm, along with corresponding labels. The training algorithm initializes a model, and then tweaks its parameters using the feature vectors and labels. Typically, this involves an iterative procedure where one or more samples are presented to the classifier at a time, which then predicts their labels. The error between these predicted labels and ground-truth is used as a signal to modify the parameters. When this error falls below a certain threshold, or when enough iterations have passed, we can consider the model to have been sufficiently trained. Now, we can verify how it performs on previously unseen examples using the test set.</p><p>The error on the test set is typically larger than that on the training set, which is expected. Also, both errors typically decrease the more we train our model. However, we have to be careful about one thing. <strong>If we keep training beyond a certain point, our training error may keep decreasing, but our test error will begin to increase again. This is known as overfitting. </strong>Our model fits the training data very well, but is unable to generalize to unseen examples. One thing we haven’t talked about yet is the choice of what classifier to use. That’s because it might require some experimentation to figure out what classifier works best for a given problem. In this case, we’re going to start with support vector machines. But we’re free to choose what classifier we ultimately use. It could even be a combination or ensemble of multiple classifiers.</p><h4>Sliding Windows Approach</h4><p>Okay, so now we’ve decided which features to extract from each image, and we’ve trained a classifier using label data. Great work. The next step is to implement a method of searching for objects, in this case, for vehicles in an image.</p><blockquote>So how are we going to do that?</blockquote><p>Well, we’ve seen that we can consider cutouts or subregions of an image, and run our classifier on each subregion to see if it contains the object we’re trying to detect. So what we’ll do next is implement a <strong>sliding window technique, </strong>where we’ll step across an image in a grid pattern and extract the same features we trained our classifier on in each window. We’ll run our classifier to give a prediction at each step. And with any luck, it will tell us which windows in our image contains cars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*F2yYW_EFmaCbgqbjYO0bbQ.jpeg" /><figcaption>Sliding window technique (Image by author)</figcaption></figure><p>In general, we won’t know what size our object of interest will be in the image we’re searching. <strong>So makes sense to search in multiple scales.</strong> In this case, it’s good idea to establish a minimum and a maximum scale at which we expect the object to appear, and then reasonable number of intermediate scales to scan as well. <strong>The think to be careful about here is that the total number of windows we’re searching can increase rapidly which means our algorithm will run slower</strong>. We’re looking for vehicles, so it makes sense through restrict our search to the only areas of the images where vehicles might appear. <strong>Furthermore, when it comes to scale, we know for example that vehicles that appear small will be near the horizon. So search in a small scales could be restricted to even narrow a strip across the image.</strong></p><h4>False Positives</h4><p>We now have a scheme for searching across the image for possible detections, but we’ll notice that our classifier is not perfect. In some cases, it will report multiple overlapping instances of the same car or even report cars where there are none.<strong> These are known as duplicates and false positives</strong>, and we’ll need to filter them out. In correctly combining duplicate detections and rejecting false positives, we are performing the task of identifying where vehicles are on the road. But equally important where they are not. False positives that are not properly filtered out can lead to taking actions like emergency breaking when it’s not necessary and potentially, to causing an accident. In order to avoid running into another car, we would like to get the best estimate possible for the position and size of the cars we detect. That means whether it’s a single detection or multiple detections on the same car, a tight bounding box for each car is what we’re aiming for. These bounding boxes are ultimately going to be used by your path-planning or motion control algorithms, to try to cause the steer is clear of the other vehicles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*VR0a4VK7JeWBOwLFaT5ZNg.png" /><figcaption>Bounding boxes over the detections (Image by author)</figcaption></figure><h4>Tracking Pipeline</h4><p>Okay, let’s summarize our overall tracking pipeline.</p><ol><li>In each frame of the video, we will run a search for vehicles using a sliding window technique.</li><li>Wherever our classifier returns a positive detection, we’ll record the position of the window in which the detection was made.</li><li>In some cases we might detect the same vehicle in overlapping windows or at different scales. In the case of overlapping detections we’re going to assign the position of the detection to the centroid of the overlapping windows.</li><li>We also have false positives which we’ll filter out by determining which detections appear in one frame but not the next. Once we have a high confidence detection we can record how it’s centroid is moving from frame to frame and we eventually estimate where it will appear in each subsequent frame.</li></ol><h4>Summary</h4><p>First we need to decide what features to use. We’ll want to try some combination of color and gradient based features. But keep in mind that this might require some experimentation to decide what works best. Next, we’ll need to choose and train a classifier. <strong>A linear SVM is probably our best bet for an ideal combination of speed and accuracy.</strong> We’ve chosen features and trained a classifier. Next, we’ll implement a sliding window technique to search for vehicles in some test images. We can try multiscale search or different tiling schemes to see what works best. <strong>But keep in mind, we’d like to minimize the number of search windows. So, for example, we probably don’t need to search for cars in the sky and the treetops. </strong>Once we’ve got a working detection pipeline, we’ll try it on a video stream. And implement tracking to follow, detect vehicles. And reject spurious detections.</p><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c4c78b853f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Autonomous Vehicle Architecture]]></title>
            <link>https://sawhney-prateek97.medium.com/autonomous-vehicle-architecture-b802f30283fa?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b802f30283fa</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[autonomous-cars]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 04:51:36 GMT</pubDate>
            <atom:updated>2022-09-03T16:48:26.004Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction to System Integration, Sensor Subsystem, Perception Subsystem, Planning Subsystem and Control Subsystem</h4><p>Welcome to this medium article around System Integration. In this medium article we’ll be discussing the system architecture used in self-driving cars so that we can fit all of the pieces together. A self driving car has four major subsystems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c9Yc0RmpykMFHRUBg5fRHg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@gaberce?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Gabe Pierce</a> on <a href="https://unsplash.com/s/photos/self-driving-cars?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The first subsystem is the sensor subsystem, which consists of the hardware components that gather data about the environment like lidar, radar, cameras and GPS sensors. The second subsystem, the perception subsystem, consists of software to process sensor data. Meaningful information is processed from the sensor data in the perception subsystem. The planning subsystem is the third subsystem on the vehicle. It uses the output from perception for behavior planning and for both short and long range path plan. The subsystem which ensures that the vehicle follows the path provided by the planning subsystem is the control subsystem. It also sends control commands to the vehicle.</p><h4>Perception Subsystem</h4><p>The perception subsystem, processes data from sensors into structured information that can eventually be used for path planning or control. This is where environment analysis takes place by the vehicle. So we can think of the perception subsystem as the vehicle center of understanding about its environment. Broadly speaking, we can further divide the perception subsystem itself into two underlying subsystems;</p><ol><li>Detection</li><li>Localization</li></ol><p>Using sensor and map data to determine the vehicle’s precise location is done by the localization subsystem. The detection subsystem is responsible for understanding the surrounding environment. This subsystem includes software components such as;</p><ol><li>Lane detection</li><li>Traffic sign and traffic light detection classification</li><li>Object detection and tracking</li><li>Free space detection.</li></ol><p>Different components in the detection and localization subsystems draw information from different sensors. Additionally, the localization subsystem requires map data which it uses to identify the vehicle’s location. The perception subsystem passes the data from localization and detection to the planning subsystem. The planning subsystem determines what maneuver the vehicle should undertake next.</p><h4>Planning Subsystem</h4><p>The vehicle uses the information processed by the perception subsystem to plan its path. There are several components of the planning system like route planning, which is the high level path of the vehicle between two points on a map; prediction, which is what identifies which maneuver other objects on the road might take; behavior planning, which decides what maneuver our vehicle should take; and trajectory generation, which plots the precise path we’d like our vehicle to follow.</p><p>The planning subsystem takes in data from all of the components of the perception subsystem. Additionally, map data is used for long range planning. Once the vehicle has a planned trajectory the next step is to execute that trajectory. This is the responsibility of the control subsystem.</p><h4>Control Subsystem</h4><p>The last subsystem in the vehicle is the control subsystem. It contains the software components which makes sure that the exact path is followed by the vehicle which is specified by the Planning Subsystem. The control subsystem may include components such as PID controllers, model predictive controllers, or other controllers. As we know that the control subsystem sends acceleration, braking, and steering commands to the vehicle, this completes the chain of information from sensors to actuation and allows the vehicle to drive.</p><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b802f30283fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a People Counter Application at the Edge Using Intel OpenVINO Toolkit]]></title>
            <link>https://sawhney-prateek97.medium.com/deploying-a-people-counter-application-at-the-edge-using-intel-openvino-toolkit-7979b4b69b4d?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7979b4b69b4d</guid>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[intel]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 04:51:00 GMT</pubDate>
            <atom:updated>2021-09-17T16:19:15.090Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using Intel OpenVINO Toolkit to create awesome applications!</h4><p>The people counter application demonstrates how to create a smart video IoT solution using Intel® hardware and software tools. The application detects people in a designated area, providing the number of people in the frame, average duration of people in frame, and total count. This project is a part of <a href="https://www.udacity.com/course/intel-edge-ai-for-iot-developers-nanodegree--nd131">Intel Edge AI for IOT Developers Nanodegree program by udacity</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FE9hvkBaylk0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DE9hvkBaylk0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FE9hvkBaylk0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d8730632b69a242a1750fe1f8fa2792/href">https://medium.com/media/3d8730632b69a242a1750fe1f8fa2792/href</a></iframe><h3>Intel OpenVINO Toolkit</h3><p>Open Visual Inference and Neural Network Optimization is a toolkit provided by Intel to carry out faster inference of deep learning models. It contains two main parts i.e. Model Optimizer and Inference Engine. OpenVINO toolkit can deploy many types of computer vision and deep learning models at the Edge. Thus, mainly dependent on Convolutional Neural Networks and Computer Vision models for carrying out the predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*on-T20Y-7Kh6R27Udb6raQ.png" /><figcaption>OpenVINO (Image credit: <a href="https://01.org/openvinotoolkit">OpenVINO™ toolkit | 01.org</a>)</figcaption></figure><p>Also, OpenVINO supports various types of devices like CPU, GPU, TPU, <a href="https://software.intel.com/content/www/us/en/develop/hardware/neural-compute-stick.html">Neural Compute Stick</a> and <a href="https://www.intel.in/content/www/in/en/products/programmable.html">FPGA</a>. In this project, OpenVINO CPU toolkit is used to identify people in a particular frame of the video. Also, the average duration of a particular person is evaluated and displayed in the output video.</p><p><a href="https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit/get-started.html">Get Started with the Intel® Distribution of OpenVINO™ Toolkit</a></p><h3>Model Optimizer and Inference Engine</h3><p>The two main components of OpenVINO toolkit are Model Optimizer and Inference Engine. In short, the Model Optimizer takes in a pre-trained model, optimizes the model and converts it into its intermediate representation (.xml and .bin file). Generally, a pre-trained model is one which is used previously on some similar problem set. The time that would be saved in building the model from scratch, would be used in optimizing the model for better results and accuracy. The IR (Intermediate Representation) is fed into the Inference Engine which is a library written in C++ and provides an API to read the Intermediate Representation. On the other hand, the Inference Engine helps in proper execution of the model on different devices. It manages the libraries required to run the code properly on different platforms.</p><h3>How the application works?</h3><p>The counter uses the Inference Engine included in the <a href="https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit/choose-download.html">Intel® Distribution of OpenVINO™ Toolkit</a>. The model used is be able to identify people in a video frame. The application counts the number of people in the current frame, the duration that a person is in the frame (time elapsed between entering and exiting a frame) and the total count of people. It then sends the data to a local web server using the <a href="https://pypi.org/project/paho-mqtt/">Paho MQTT Python package</a>.</p><p>The architecture diagram of the application including the Main, Mosca Server, UI and FFmpeg is clearly shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHmtB06xPnzoQBvu61ntjw.png" /><figcaption>Fig 1: Architecture diagram of application (Image by author)</figcaption></figure><h3>Application Requirements</h3><h4>Hardware Requirements</h4><ul><li>6th to 10th generation Intel® Core™ processor with Iris® Pro graphics or Intel® HD Graphics.</li><li>OR use of Intel® Neural Compute Stick 2 (NCS2)</li></ul><h4>Software Requirements</h4><ul><li>Intel® Distribution of OpenVINO™ toolkit 2019 R3 release</li><li>Node v6.17.1</li><li>Npm v3.10.10</li><li><a href="https://pypi.org/project/cmake/">CMake</a></li><li>MQTT Mosca server</li><li>Python 3.5 or 3.6</li></ul><h3>Setup</h3><ul><li><a href="https://github.com/prateeksawhney97/People-Counter-Application-Using-Intel-OpenVINO-Toolkit/blob/master/linux-setup.md">Install Intel® Distribution of OpenVINO™ toolkit</a></li><li><a href="https://github.com/prateeksawhney97/People-Counter-Application-Using-Intel-OpenVINO-Toolkit/blob/master/linux-setup.md">Install Nodejs and its dependencies</a></li><li><a href="https://www.npmjs.com/get-npm">Install npm</a></li></ul><p><a href="https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit/choose-download.html">Choose &amp; Download Intel® Distribution of OpenVINO™ Toolkit</a></p><p>There are three components that need to be running in separate terminals for this application to work:</p><ul><li><a href="https://www.npmjs.com/package/mosca">MQTT Mosca server</a></li><li><a href="https://nodejs.org/en/docs/guides/getting-started-guide/">Node.js* Web server</a></li><li><a href="https://www.ffmpeg.org/">FFmpeg server</a></li></ul><p>To start the three servers in separate terminal windows, following commands should be executed from the main directory:</p><ul><li>For MQTT/Mosca server:</li></ul><pre>cd webservice/server<br>npm install</pre><ul><li>For Web server:</li></ul><pre>cd ../ui<br>npm install</pre><ul><li>For FFmpeg Server:</li></ul><pre>sudo apt install ffmpeg</pre><h3>Explaining Model Selection</h3><p><a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md">TensorFlow Object Detection Model Zoo</a> contains many pre-trained models on the coco dataset. For this project, various classes of models were tested from the TensorFlow Object Detection Model Zoo. SSD_inception_v2_coco and faster_rcnn_inception_v2_coco performed good as compared to rest of the models, but, in this project, faster_rcnn_inception_v2_coco is used which is fast in detecting people with less errors. Intel openVINO already contains extensions for custom layers used in TensorFlow Object Detection Model Zoo.</p><p>Downloading the model from the GitHub repository of Tensorflow Object Detection Model Zoo by the following command:</p><pre>wget <a href="http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz">http://download.tensorflow.org/models/object_detection/faster_rcnn_inception_v2_coco_2018_01_28.tar.gz</a></pre><p>Extracting the tar.gz file by the following command:</p><pre>tar -xvf faster_rcnn_inception_v2_coco_2018_01_28.tar.gz</pre><p>Changing the directory to the extracted folder of the downloaded model:</p><pre>cd faster_rcnn_inception_v2_coco_2018_01_28</pre><p>The model can’t be the existing models provided by Intel as a part of the <a href="https://udacity.com/">Udacity</a> acceptance criteria of the Nanodegree project. So, converting the TensorFlow model to Intermediate Representation (IR) or OpenVINO IR format. The command used is given below:</p><pre>python /opt/intel/openvino/deployment_tools/model_optimizer/mo.py --input_model faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --tensorflow_object_detection_api_pipeline_config pipeline.config --reverse_input_channels --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/faster_rcnn_support.json</pre><h3>Comparing Model Performance</h3><h4>Model-1: Ssd_inception_v2_coco_2018_01_28</h4><p>Converted the model to intermediate representation using the following command. Further, this model lacked accuracy as it didn’t detect people correctly in the video. Made some alterations to the threshold for increasing its accuracy but the results were not fruitful. Changed the threshold to 0.4 instead of 0.6, but the results were not up to the mark.</p><pre>python /opt/intel/openvino/deployment_tools/model_optimizer/mo.py --input_model ssd_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --tensorflow_object_detection_api_pipeline_config pipeline.config --reverse_input_channels --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/ssd_v2_support.json</pre><h4>Model-2: Faster_rcnn_inception_v2_coco_2018_01_28</h4><p>Converted the model to intermediate representation using the following command. Model-2 i.e. Faster_rcnn_inception_v2_coco, performed really well in the output video. After using a threshold of 0.4, the model works better than all the previous approaches.</p><pre>python /opt/intel/openvino/deployment_tools/model_optimizer/mo.py --input_model faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb --tensorflow_object_detection_api_pipeline_config pipeline.config --reverse_input_channels --tensorflow_use_custom_operations_config /opt/intel/openvino/deployment_tools/model_optimizer/extensions/front/tf/faster_rcnn_support.json</pre><h4>Comparison of the two models</h4><p>Compared the two models i.e. ssd_inception_v2_coco and faster_rcnn_inception_v2_coco in terms of latency and memory, several insights were drawn. It could be clearly seen that the Latency (microseconds) and Memory (Mb) decreases in case of OpenVINO as compared to plain Tensorflow model which is very useful in case of OpenVINO applications or Edge computing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*mrEkwyN4Lw7vzVz4xyvCeQ.png" /><figcaption>Fig 2: Comparison in terms of Latency &amp; Memory (Image by author)</figcaption></figure><h3>Model Use Cases</h3><p>This application could keep a check on the number of people in a particular area and could be helpful where there is restriction on the number of people present in a particular area. Further, with some updations, this could also prove helpful in the current COVID-19 scenario i.e. to keep a check on the number of people in the frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIljTJJobuDyXVjY3CsJVA.png" /><figcaption>Fig 3: Implementation in Udacity Workspace (Image by author)</figcaption></figure><h3>Running the Main Application</h3><p>After converting the downloaded model to the OpenVINO IR format, all the three servers can be started on separate terminals i.e.</p><ul><li>MQTT Mosca server</li><li>Node.js* Web server</li><li>FFmpeg server</li></ul><h4>Setting up the environment</h4><p>Configuring the environment to use the Intel® Distribution of OpenVINO™ toolkit one time per terminal session by running the following command:</p><pre>source /opt/intel/openvino/bin/setupvars.sh -pyver 3.5</pre><p>Further, from the main directory:</p><h4>Step 1 — Starting the Mosca server</h4><pre>cd webservice/server/node-server<br>node ./server.js</pre><p>The following message is displayed, if successful:</p><pre>Mosca server started.</pre><h4>Step 2 — Starting the GUI</h4><p>Opening a new terminal and executing below commands:</p><pre>cd webservice/ui<br>npm run dev</pre><p>The following message is displayed, if successful:</p><pre>webpack: Compiled successfully</pre><h4>Step 3 — FFmpeg Server</h4><p>Opening a new terminal and executing below command:</p><pre>sudo ffserver -f ./ffmpeg/server.conf</pre><h4>Step 4 — Running the code</h4><p>Opening a new terminal and executing below command:</p><pre>python main.py -i resources/Pedestrian_Detect_2_1_1.mp4 -m faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.xml -l /opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libcpu_extension_sse4.so -d CPU -pt 0.4 | ffmpeg -v warning -f rawvideo -pixel_format bgr24 -video_size 768x432 -framerate 24 -i - <a href="http://0.0.0.0:3004/fac.ffm">http://0.0.0.0:3004/fac.ffm</a></pre><h4>Implementation on Local Machine</h4><p>The project is implemented on Udacity’s workspace. If the same project is to be implemented on the local machine, some changes have to be made in “constants.js” file located at the given path from the root directory of the project:</p><pre>webservice/ui/src/constants/constants.js</pre><p>In the “constants.js” file, “CAMERA_FEED_SERVER” and “MQTT_SERVER” are configured according to the Udacity’s workspace configuration. The value of these two properties should be changed to the following for proper implementation:</p><pre>CAMERA_FEED_SERVER: &quot;http://localhost:3004&quot;<br>...<br>MQTT_SERVER: &quot;ws://localhost:3002&quot;</pre><h3>References</h3><p>This project borrows the boiler-plate code from the Intel OpenVINO fundamentals project starter repository from Udacity on GitHub which can be found on the link below.</p><p><a href="https://github.com/udacity/nd131-openvino-fundamentals-project-starter">udacity/nd131-openvino-fundamentals-project-starter</a></p><p>To explore other exciting projects by Intel, check out the Intel IoT Developer Kit on GitHub which includes IoT Libraries &amp; Code Samples from Intel.</p><p><a href="https://github.com/intel-iot-devkit">Intel® IoT Developer Kit</a></p><p>The project can be found on my <a href="https://github.com/prateeksawhney97/People-Counter-Application-Using-Intel-OpenVINO-Toolkit">GitHub repository</a> with detailed instructions. <a href="https://github.com/prateeksawhney97/People-Counter-Application-Using-Intel-OpenVINO-Toolkit/blob/master/main.py">Main.py</a> and <a href="https://github.com/prateeksawhney97/People-Counter-Application-Using-Intel-OpenVINO-Toolkit/blob/master/inference.py">inference.py</a> contains detailed code about the functioning of the application.</p><p>And with that, we have come to the end of this article. Bundle of thanks for reading it!</p><p>My <a href="https://prateeksawhney97.github.io/">Portfolio</a> and <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97/People-Counter-Application-Using-Intel-OpenVINO-Toolkit">prateeksawhney97/People-Counter-Application-Using-Intel-OpenVINO-Toolkit</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7979b4b69b4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Computer Vision & Camera Calibration for Self Driving Cars]]></title>
            <link>https://sawhney-prateek97.medium.com/introduction-to-computer-vision-camera-calibration-for-self-driving-cars-a69d7912229?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a69d7912229</guid>
            <category><![CDATA[lane-detection]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 04:50:33 GMT</pubDate>
            <atom:updated>2022-09-03T16:40:58.386Z</atom:updated>
            <content:encoded><![CDATA[<h4>Camera Calibration, Perspective Transform and Distortion Correction for Self Driving Cars Development</h4><p>Welcome to this medium article. Computer Vision can essentially be broken down into a three step cycle. Sensing the world around is the first step by the self driving car. Based on that perception of the world, the self driving car decides what to do. In the last stage, the autonomous car performs an action based on the decision it made in the previous step. This constitutes the whole computer vision used by the self driving car.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*GZCc9hQ1oRUXOEavw2Fwzg.gif" /><figcaption>Detecting Lane Lines (Image by author)</figcaption></figure><blockquote>Computer vision is a major part of the perception step in that cycle. 80% of the challenge of building a self-driving car is perception. Computer vision is the technique of recognizing the world around us through images or videos. For the self driving cars or the autonomous vehicles, computer vision performs most important steps or processes like detecting lane markings, vehicles or pedestrians, and other elements like Traffic signs, etc.</blockquote><p>Self-driven cars employ a suite of sophisticated sensors, but humans do the job of driving with just two eyes and one good brain. In fact, we can even do it with one eye closed. Indeed, we can. So, let’s take a closer look at why using cameras instead of other sensors might be an advantage in developing self-driving cars. <strong>Radar and Lidar see the world in 3D</strong>, which can be a big advantage for knowing where we are relative to our environment. <strong>We know that a camera only sees 2d world around it</strong>, but at much higher spatial resolution than Radar and Lidar. Due to this, it’s actually possible to infer depth information from camera images. The big difference, however, comes down to cost, where cameras are significantly cheaper.</p><p>Readings like how much the lane is curving are important for the cameras to perform the required thing. But, in order to get this perspective transformation right, we first have to correct for the effect of <strong>image distortion</strong>. Well hopefully, the distortion we’re dealing with isn’t quite that bad, but yes, that’s the idea. Cameras don’t create perfect images. Some of the objects in the images, especially ones near the edges, can get <strong>stretched or skewed in various ways</strong> and we need to correct for that. Cool, let’s jump into step one, how to undistort our distorted camera images.</p><h4>Distortion Correction</h4><p>Distortion correction comes into play when we want to retrieve the information that is left by our camera which is located on the hood of the car. This is because, an image taken by a camera suffers distortion. A camera looks at 3d objects and converts them into 2d image. <strong>This transformation isn’t perfect.</strong> For example, here’s an image of a road and some images taken through different camera lenses that are slightly distorted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*joY__CABUWRsVGyCvLa17g.jpeg" /><figcaption>Distorted image (Image by author)</figcaption></figure><p>In this distorted image, we can see that the edges of the lanes are bent and sort of rounded or stretched outward. And distortion is actually changing what the shape and size of these objects appears to be. This is a great problem because we want our self driving vehicle to be accurate on the road so that there are less accidents. But if the lane is distorted, <strong>we’ll get the wrong measurement for curvature in the first place and our steering angle will be wrong. </strong>So, first of all, we should eliminate this distortion by computer vision which is caused by the cameras located on the hood of the car. Below is an image which is distortion corrected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*l8UeESU3XD8iLIgL2FWOqw.png" /><figcaption>Distortion Corrected (Image by author)</figcaption></figure><h4>Pinhole Camera Model and Types of Distortion</h4><p>Before start correcting for distortion, let’s get some intuition as to how this distortion occurs. Now, lets take a look at the <strong>pinhole camera model</strong>. When the camera forms an image, it’s looking at the world similar to how our eyes do. In the pinhole camera model, the image it forms here will be upside down and reversed because rays of light that enter from the top of an object will continue on that angled path through the pinhole and end up at the bottom of the formed image. Similarly, light that reflects off the right side of an object will travel to the left of the formed image.</p><p>We need undistorted images that accurately reflect our real world surroundings. Luckily, this distortion can generally be captured by five numbers called <strong>distortion coefficients,</strong> whose values reflect the amount of radial and tangential distortion in an image. In severely distorted cases, sometimes even more than five coefficients are required to capture the amount of distortion. If we know these coefficients, we can use them to calibrate our camera and undistort our images.</p><h4>Camera Calibration Using Chessboard Images</h4><p>The first step will be to read in calibration images of a chessboard. There should be at least 20 images to perform calibration. They should be taken at different angles and distances. Each chessboard here has eight by six corners to detect. I’ll go through the calibration steps for the first calibration image in detail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1xoja4OF9QfiEa4I-_t4w.png" /><figcaption>Camera Calibration performed on the Image (left) to get the distortion corrected image (right)</figcaption></figure><h4>Lane Curvature</h4><p>Now that we’ve learned about camera calibration and correcting for distortion, we can start to extract really useful information from images of the road. One really important piece of information is lane curvature. While driving on the highway, we press the gas or break to go with the flow and take a look at the traffic. And, based on such information we steer the wheel.</p><blockquote><strong>Now, how does this work for a self-driving car?</strong></blockquote><p>Autonomous vehicles must be supplied by the correct steering angle so that they can turn left or right and we can easily calculate this angle.</p><blockquote><strong>To determine the curvature, we’ll go through the following steps.</strong></blockquote><p>First, we’ll detect the lane lines using some <strong>masking and thresholding techniques.</strong></p><p>Then, perform a<strong> perspective transform to get a birds eye view of the lane. </strong>This let’s us fit a polynomial to the lane lines. Which we couldn’t do very easily before.</p><p>Then, we can extract the curvature the lines from this polynomial with just a little math. So let’s start by learning more about the perspective transform.</p><h4>Perspective Transform</h4><p>In an image, perspective is the phenomenon where an object appears smaller the farther away it is from a viewpoint like a camera, and parallel lines appear to converge to a point. It’s seen in everything from camera images to art. Many artist use perspective to give the right impression of an object’s size, depth, and position when viewed from a particular point. And let’s look at perspective in this image of the road.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*C3o4au6tpsJxZ8xE1_LNow.png" /><figcaption>Sample undistorted image for implementing perspective transform (Image by author)</figcaption></figure><p>As you can see, the lane looks smaller and smaller the farther away it gets from the camera, and the background scenery also appears smaller than the trees closer to the camera in the foreground. A perspective transform of an image gives us the same image but from another view point like the bird’s eye view, etc. It forces the same image to change it’s view point and warps the new image over it. The Perspective Transform of the above is given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*kwrP5_69YKuNV-7KoN2vZA.png" /><figcaption>Perspective Transform or the Bird’s eye view (Image by author)</figcaption></figure><blockquote>By doing a perspective transform and viewing this same image from above, we can see that the lanes are parallel and both curve about the same amount to the right. So, a perspective transform let’s us change our perspective to view the same scene from different viewpoints and angles. This could be viewing a scene from the side of a camera, from below the camera, or looking down on the road from above. Doing a bird’s-eye view transform is especially helpful for road images because it will also allow us to match a car’s location directly with a map, since map’s display roads and scenery from a top down view. The process of applying a perspective transform will be kind of similar to how we applied undistortion. But this time, instead of mapping object points to image points, we want to map the points in a given image to different desired image points with a new perspective.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*8bimKfjJoMXnWtEW9lIR0g.gif" /><figcaption>Detected Lane Lines (Image by author)</figcaption></figure><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a69d7912229" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Safety Management for Self Driving Cars]]></title>
            <link>https://sawhney-prateek97.medium.com/introduction-to-safety-management-for-self-driving-cars-dc715f2f57d1?source=rss-5a206a1caae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc715f2f57d1</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Prateek Sawhney]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 04:50:05 GMT</pubDate>
            <atom:updated>2022-09-03T16:40:10.724Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction to concepts like Safety Culture, Safety Lifecycle, Safety Management, Development Interface Agreement and Confirmation Measures</h4><p>Hello. Welcome to this medium article. We read about functional safety in the previous medium articles. Before analyzing a system under <strong>ISO 26262</strong>, we need to create a plan. Designing a safe vehicle requires more than a methodical analysis of hardware and software components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sP2sI-_zb2md_wQz_-i3hg.jpeg" /><figcaption>Image by <a href="https://unsplash.com/@fotoplastikon?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jakub Puchalski</a> on <a href="https://unsplash.com/s/photos/fiat?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Vehicles are complex systems with both sociological and technical requirements. <strong>If our company or team does not take safety seriously, how can we expect to design a safe vehicle?</strong> If roles and responsibilities haven’t been defined, important design steps might be missed. So our first step in functional safety is to write a safety plan. The safety plan forces us to define roles then outline the steps we will take to achieve functional safety. In this lesson I will discuss the basic parts of a safety plan so that we can document our own.</p><h4>Safety Culture</h4><p>It’s important to understand that technology malfunctions are not the only source of vehicle accidents. Social and organizational factors play a role as well. An organization should develop clear policies and strategies to support the development, production, and operation of safe systems. Imagine what would happen if our manager told us to skip a few software integration tests in order to meet a deadline?</p><blockquote><strong>Would we feel comfortable telling our manager no? Does our company have clear policies about what to do if we encounter design problems that aren’t our responsibility?</strong></blockquote><p>Decisions about technology after all, are made by humans. And humans are fallible. Good safety culture, put safety as the highest priority over competing constraints, like cost and productivity. Design decisions need to be well documented and traceable back to the people who made those decisions. Companies should reward achieving safe systems and penalize taking shortcuts. Without a good safety culture, functional safety is difficult to achieve. Our safety plan will need to include information about how our company promotes a safe culture.</p><h4>Tailoring the Safety Lifecycle</h4><p>Let’s look again at the steps contained in the <strong>V-model</strong> discussed in the previous medium article. I have included the image here for reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JDRY9V2EEKj_S2eRL33iLA.png" /><figcaption>V Model (Image by author)</figcaption></figure><p>The V-model shows the entire safety life cycle, starting from the concept phase through the product development and ending in production. In general, a functional safety manager will need to coordinate and document the entire cycle. Ask yourself, is my product new or am I modifying an existing product? If we are designing a new product, we’ll have to follow and document the entire safety lifecycle. If we are modifying a product that already exist, we might not have to implement all of the steps in the safety lifecycle. New functionality perhaps only impacts certain parts of the concept phase or product development phase, so we can tailor the safety lifecycle to include only the parts impacted by the new functionality. That way, we can reuse some of the work that has already been done.</p><p>Let’s say, for example, that we are working on updating an automatic braking system that already exists. Our company has decided to use a new electronic control unit with a faster, more powerful processor. However, the break system’s functionality has not changed. Our first step is to make sure the new ECU really would not affect the braking system. If the new ECU has no effect, we might not have to change anything in the design. We could also reuse part of the original functional safety analysis. However, we would still need to run tests to make sure the new electronic control unit integrates with the rest of the system. In the safety plan, we would need to discuss if the product being developed is new or just a modification. Then we tailor the safety lifecycle and discuss what sections of the V-model need to be included. Tailoring the safety lifecycle allows us to focus on the parts of the product that are new.</p><h4>Safety Management roles and responsibilities</h4><p>Another part of the safety plan, involves defining roles and responsibilities. One person would not be expected to do all of the work required by ISO 26262. In fact, developing the functional safety of a product can involve multiple teams, both within a company and across different companies. Some of the most important roles in a safety related project include, the <strong>Project Manager </strong>who ensures all of the necessary resources are available to the project. <strong>The safety manager,</strong> who would write the safety plan and then monitor the project progress against that plan. <strong>A safety engineer,</strong> would be responsible for architectural designs and implementation steps like integration and testing. <strong>The safety auditor</strong>, makes sure that the company implements processes according to the functional safety standard.<strong> The safety assessor,</strong> acts as an independent judge as to whether the project has made the vehicle safer. <strong>A test manager</strong>, plans the tests that determine whether the system works as expected. Clearly defined roles in the safety plan, ensure that each member of the team knows what to do. Defining roles, also ensures that every activity has a team member assigned to it.</p><p><a href="https://www.datadriveninvestor.com/2020/11/19/how-machine-learning-and-artificial-intelligence-changing-the-face-of-ecommerce/">How Machine Learning and Artificial Intelligence Changing the Face of eCommerce? | DataDrivenInvestor</a></p><h4>Development Interface Agreement</h4><p>The automotive supply chain is generally divided into three players:</p><ol><li><strong>OEMs</strong></li><li><strong>Tier 1 suppliers</strong></li><li><strong>Tier 2 suppliers</strong></li></ol><p><strong>OEM stands for, Original Equipment Manufacturer</strong>. These are the brand name automotive companies that sell cars to consumers, but OEMs do not necessarily develop all of their vehicle systems in-house. OEMs outsource some development to what are called Tier 1 suppliers. The OEM and Tier 1 supplier, then take on a customer supplier relationship. The OEM might provide requirements for what a vehicle system needs to do and then, the Tier 1 supplier develops and produces the system for the OEM. Or, the OEM might provide a preliminary product design and then, the Tier 1 will finish the details. Tier 1 companies, oftentimes outsource their own work to Tier 2 companies. A common example would be, a Tier 1 that sources an electronic control unit from a Tier 2 company. Then, the Tier 1 supplier uses the electronic control unit to develop an automatic braking system for the OEM.</p><blockquote><strong>In the safety plan, there is a section called the Development Interface Agreement, or the DIA. The DIA, delineates the design and production responsibilities between the OEM and the Tier 1 supplier, or the Tier 1 supplier and the Tier 2 supplier.</strong></blockquote><p><strong>Why include the Development Interface Agreement in the safety plan?</strong></p><p>One reason is to avoid disputes during the planning and development of a product. Another reason is liability. If a vehicle has a safety issue after being sold to consumers, a Development Interface Agreement provides clarity about which company is best positioned to fix the system.</p><h4>Confirmation Measures</h4><p>The last part of the safety plan that we will discuss is the Confirmation Measures section. Confirmation measures check three things: that our processes comply with the functional safety standard, that their project execution is following the safety plan, and that the design really does improve safety. These measures are carried out by independent people who are not involved in the design or implementation of the product. The safety plan should describe what specific confirmation measures will be used. The plan will also discuss who is responsible for each measure in addition to how these measures will be carried out. Confirmation measures help ensure that the people who design the product and the people who review the design are independent.</p><h4>Summary</h4><p>We have gone through the major parts of a safety plan. The safety plan would be one of the first steps in developing a safe product. Designing a system under the functional safety standard requires methodical planning and execution. The safety plan serves as a guide to what will be done to achieve functional safety. The plan also defines responsibilities between the players involved in the project. This ensures that everybody knows what to do and that somebody is covering every task. As the project passes through the design, implementation, and production phases, the output will be checked against the safety plan.</p><p>With this, we have come to the end of this article. Thanks for reading this and following along. Hope you loved it! <strong>Bundle of thanks for reading it!</strong></p><p>My <a href="https://linkedin.com/in/prateek-sawhney-a0b134131/">Linkedin</a> :)</p><ul><li><a href="https://github.com/prateeksawhney97">prateeksawhney97 - Overview</a></li><li><a href="https://play.google.com/store/apps/dev?id=6602729235674498692">Android Apps by Prateek Sawhney on Google Play</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc715f2f57d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>