<?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 Abdul Ahad on Medium]]></title>
        <description><![CDATA[Stories by Abdul Ahad on Medium]]></description>
        <link>https://medium.com/@abdul.ahad.m?source=rss-2802206f553b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nfPIzS5A8erWSYR1alUCxg.jpeg</url>
            <title>Stories by Abdul Ahad on Medium</title>
            <link>https://medium.com/@abdul.ahad.m?source=rss-2802206f553b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 09:44:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdul.ahad.m/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[Kalman Filters: An Introduction to One of the Most Powerful Tools in Robotics]]></title>
            <link>https://medium.com/@abdul.ahad.m/kalman-filters-an-introduction-to-one-of-the-most-powerful-tools-in-robotics-10a6454af2f9?source=rss-2802206f553b------2</link>
            <guid isPermaLink="false">https://medium.com/p/10a6454af2f9</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[kalman-filter]]></category>
            <category><![CDATA[robotics]]></category>
            <dc:creator><![CDATA[Abdul Ahad]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 17:11:26 GMT</pubDate>
            <atom:updated>2023-02-19T17:11:26.804Z</atom:updated>
            <content:encoded><![CDATA[<p>Kalman Filter is one of the first “advanced” algorithms that beginners come across when learning SLAM or robotics. Despite its intimidating appearance, with its complex matrices and algebraic jargon, it is actually a simple and intuitive algorithm that can become a powerful tool in your robotics skillset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*uchJzlZpiQDsKU6I" /><figcaption>© <a href="https://logicalerrors.wordpress.com/2019/02/03/kalman-filter/">https://logicalerrors.wordpress.com/2019/02/03/kalman-filter/</a></figcaption></figure><h3>Intuition</h3><p>So what exactly is a Kalman Filter? Simply put, it is an estimation algorithm that uses a two-step process to estimate a certain quantity based on data that we already have. To understand the algorithm better, let’s go through an example.</p><p>Imagine we have to estimate the height of a falling object. We can use the familiar equations of motion to “predict” the height, but due to various “factors,” the actual height might differ from the predicted one. However, if we are able to observe the falling object, we can use these observations to “correct” or update our predictions, getting us a more accurate estimate.</p><p>This is the essence of a Kalman Filter: a combination of two steps. First, the prediction step, where we use the physics of the system to get an initial estimate for the quantity we are estimating, and second, the update step, where we take data from our observations to augment our predictions.</p><p>This same intuition extends to various applications such as object tracking, Orientation correction, filtering noisy sensor data, and a gazillion other applications of the Kalman filter.</p><p>Let’s delve into the mathematical details of each step.</p><h3><strong>Prediction Step</strong></h3><p>In the prediction step, we use the equations of motion to estimate the next state of the system. The prediction step can be expressed mathematically as follows:</p><pre>x_k = F_k * x_k-1 + B_k * u_k + w_k<br>P_k = F_k * P * F_k^T + Q_k</pre><p>where x_k is the state estimate at the time step k, F_k is the state transition matrix, x_k-1 is the previous state estimate, B_k is the control input matrix, u_k is the control input vector, and w_k is the process noise at the time step k-1.</p><p>Don&#39;t be frightened by the ‘State transition’ or the ‘Control Input’ matrix.</p><p>The state transition matrix simply gives the relationship between the current state and the future state of the system, i.e it models the physics of the system. For example, when tracking the position and velocity of a moving object, the state transition matrix tell us how the position and velocity change with time.</p><p>The control input matrix tells us how the inputs to the system affect its state.</p><p>The state covariance matrix P_k represents the covariance (i.e. statistical dependence) between the different components of the estimated state. It is a way to model the uncertainty in the state estimate Accurate modeling of the state covariance matrix is critical to the performance of the Kalman filter, as errors in the covariance matrix can lead to biased or incorrect state estimates.</p><blockquote>For more info on covariance : <a href="https://youtu.be/KDw3hC2YNFc">https://youtu.be/KDw3hC2YNFc</a>”</blockquote><h3>Update Step</h3><p>In the update step, we consider the measurements we have made of the system to correct our prediction. The update step can be expressed mathematically as follows:</p><pre>S_k = H_k * P_k * H_k^T + R_k<br><br>K_k = P_k-1 * H_k^T *S_k^-1</pre><p>where S_kis the innovation covariance, K_k is the Kalman gain, P_k-1 is the state covariance matrix, H_k is the Measurement matrix, and R_k is the measurement noise covariance matrix.</p><p>The Kalman gain K_k determines how much weight to give to the measurement and how much to the prediction.</p><p>The measurement matrix or Observation matrix is a way to map your state space into the measurement or observation space. For example, if we are trying to estimate the position of a vehicle using GPS measurements, the measurement matrix would map the state of the vehicle (which might include both position and velocity) to the GPS measurements. This mapping might involve taking into account the geometry of the GPS satellites and the time delay in receiving the signals.</p><pre>I = z_k - (H_k * x_k)<br><br>x_k = x_k + K_k * I<br><br>P_k = (I - K_k * H_k) * P_k-1</pre><p>where z_k is the measurement vector, i.e the output from your sensors.</p><p>With these two steps, we can iteratively update our estimate of the state of the system, taking into account both our predictions and the measurements we have made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*wF248chxQfyBCK_6.png" /><figcaption>An example of a Kalman filter used to estimate the height of a falling object</figcaption></figure><p>Kalman Filters are able to model real-world uncertainties into the system using a Gaussian noise model and utilize the Kalman gain factor to account for this noise in the update step. This makes them a powerful tool in robotics and estimation problems.</p><p>In conclusion, don’t let complex mathematical expressions scare you away from Kalman Filters. Once you get the intuition, it can be a valuable addition to your skill set. So go ahead, dive into the world of Kalman Filters, and unlock its full potential!</p><h3>References :</h3><ol><li><a href="https://www.cs.cmu.edu/~motionplanning/papers/sbp_papers/kalman/kleeman_understanding_kalman.pdf">https://www.cs.cmu.edu/~motionplanning/papers/sbp_papers/kalman/kleeman_understanding_kalman.pdf</a></li><li><a href="https://github.com/abdulahad01/mobileRobotics">https://github.com/abdulahad01/mobileRobotics</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10a6454af2f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with Image classification using FastAI: A Beginner’s guide]]></title>
            <link>https://medium.com/@abdul.ahad.m/getting-started-with-image-classification-using-fastai-a-beginners-guide-6a3c30c27e1f?source=rss-2802206f553b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a3c30c27e1f</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[fastai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Abdul Ahad]]></dc:creator>
            <pubDate>Wed, 25 Jan 2023 17:21:17 GMT</pubDate>
            <atom:updated>2023-01-25T17:23:05.764Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Are you tired of sifting through endless lines of code to create a simple image classifier? Look no further! The fastai library offers an easy and efficient solution for building image classifiers with minimal code. From data collection and cleaning to training, validation, and testing, the fastai library’s helpful API’s make the entire process a breeze. In this blog post, we’ll dive into the world of image classification using fastai and show you just how easy and straightforward it can be. We will train a simple classifier to classify traffic signals. So, buckle up and get ready to learn how to create your own image classifier in no time!</p><h3>Download and Import necessary packages</h3><p>Before we begin, let’s make sure we have the latest version of fastai installed, as well as the duckduckgo package, which we’ll use to easily download images for training our classifier. Updating or installing these packages is simple, just run the following command in your terminal and you’ll be all set to start building your image classifier!</p><pre>!pip install -Uqq fastai duckduckgo_search</pre><p>To get started, we’ll need to import a few necessary packages. First, we’ll import the ddg_images() function from the duckduckgo package, which we&#39;ll use to download our images for training. We&#39;ll also need the matplotlib library for visualizing our images, and the fastdownload package for quickly downloading and preparing our datasets. Additionally, we&#39;ll import the fastai.vision and fastai.data modules, which contain a wealth of useful computer vision and data-related APIs that will greatly simplify our development process. Here&#39;s the code to import these packages:</p><pre>import os<br>import time<br>from duckduckgo_search import ddg_images<br>import matplotlib.pyplot as plt<br><br>from fastdownload import download_url<br>from fastcore.all import *<br>from fastai.vision.all import *<br>from fastai.data.all import *</pre><h3>Creating our dataset</h3><p>Let&#39;s create a function search_images() that searches duckduckgo and returns a list of image URL&#39;s. This function will make it easy for us to search for and download the images we need for training our classifier.</p><pre># Function that downloads images using ddg_images api<br>def search_images(term, max_images=30):<br>    print(f&quot;Searching for &#39;{term}&#39;&quot;)<br>    # return type &lt;class &#39;fastcore.foundation.L&#39;&gt;     <br>    return L(ddg_images(term, max_results=max_images)).itemgot(&#39;image&#39;)</pre><p>With our search_images() function in place, we can now easily download the images we need for training our classifier. The Fastai library provides a convenient download_url() function that makes it simple to download an image from a given URL. Here&#39;s an example of how you might use the download_url() function to download an image and visualize it using matplotlib</p><pre># Download and visualise an Image<br>urls = search_images(&quot;red traffic light&quot;)<br>urls[0]<br>download_url(https://medium.com/urls[0],%20&#39;red_light.jpg&#39;)<br>img = plt.imread(&#39;red_light.jpg&#39;)<br>plt.imshow(img)</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*BF3ekYn9gsg1nR6xvaMTeA.png" /></figure><p>With the images downloaded, we can now create our dataset. Let’s define a function that will take the names of the required categories for our traffic light classifier and create the necessary directories. The function will then download the data for each category, with a specified time delay between each download step to avoid overloading the servers.</p><pre>root = Path(&#39;data&#39;)<br>def make_dataset(category):<br>    print(f&quot;Downloading {category} images&quot;)<br>    dest = root/category <br>    dest.mkdir(parents=True, exist_ok=True)<br>    urls = search_images(category)<br>    <br>    download_images(dest,urls=urls)<br>    time.sleep(10)  <br>    urls = search_images(category+&#39; different shapes&#39;)<br>    download_images(dest,urls=urls)<br>    time.sleep(10)<br>    urls = search_images(category+&quot; on a dark night&quot;)<br>    download_images(dest,urls=urls)<br>    time.sleep(10)</pre><pre>categories = (&#39;red_traffic_light&#39;, &#39;yellow_traffic_light&#39;, &#39;green_traffic_light&#39;)<br>for category in categories:<br>    make_dataset(category)</pre><h3>Data Cleaning</h3><p>After creating our dataset, it’s important to ensure that all the images are properly downloaded. There may be some images that were not properly downloaded and could confuse our model during training. Thankfully, fastai provides a handy verify_images() function that can be used to filter out any invalid images from our dataset.</p><pre>path=&#39;/kaggle/working/data/&#39;<br>failed = verify_images(get_image_files(path))<br>for files in failed:<br>    os.remove(files)<br>len(failed)</pre><h3>Training the computer vision model</h3><p>To get our data ready for training, we’ll use the DataBlock and DataLoaders API’s provided by fastai. First, we’ll define a DataBlock object, which in this case takes in image data and category labels as input. It also splits the data into training and validation sets and resizes the images to a uniform shape. Next, we’ll pass in the path to our dataset and use the dataloaders() method to create our DataLoaders object, which we can then use to train our model. Then we pass the path to our dataset.</p><pre># Creating a data loader object<br>DB = DataBlock(blocks = [ImageBlock, CategoryBlock],<br>              get_items = get_image_files,<br>              get_y = parent_label,<br>              splitter = RandomSplitter(valid_pct=0.2, seed = 42),<br>              item_tfms=[Resize(192, method=&#39;squish&#39;)])<br><br>dls = DB.dataloaders(path, bs=32)<br>dls.show_batch(max_n=6)</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*SzD4xEK3GrMDNQ4927Latg.png" /></figure><p>As you may have noticed, some of the images within the dataset may be wrongly labeled. It’s important to remove these images as they can confuse our model during training. However, for the sake of brevity, I won’t be discussing this task in this article.</p><p>Once we have our DataLoaders object, we can use it to train a model. One way to do this is by using the vision_learner() function provided by fastai’s vision library. This function creates a Learner object that can be used to train a model on image data. The vision_learner() function takes several arguments:</p><ul><li><em>dls:</em> This is the DataLoaders object that contains your training and validation datasets.</li><li><em>arch:</em> This is the architecture of the model you are using. In this case, it is the ResNet-18 architecture.</li><li><em>metrics:</em> This is the evaluation metric that you want to use to measure the performance of your model. In this case, the metric used is ‘accuracy’.</li></ul><p>The resnet18 architecture that we are using has been pre-trained on the ImageNet dataset. This means that the model has already learned to recognize many common image features, which can make training on our traffic light dataset faster and more effective. However, the learning rate that was used to train the model on ImageNet may not be optimal for our dataset. To find a suitable learning rate for our model, we can use the lr_find() method provided by the Learner object. This method will perform a learning rate sweep, training the model on a small subset of the data at various learning rates and plotting the results.</p><pre>learn = vision_learner(dls, resnet18, metrics=accuracy)<br>learn.lr_find()</pre><figure><img alt="png" src="https://cdn-images-1.medium.com/proxy/1*JiNA1nLCgpSzgA_adDoZtg.png" /></figure><p>Once we have found a suitable learning rate, we can use the fine_tune() method to train the model on our dataset. The fine_tune() method takes several arguments:</p><ul><li><em>epochs:</em> This is the number of times the model will iterate over the entire dataset during training.</li><li><em>lr: </em>This is the learning rate that will be used during training.</li></ul><pre>learn.fine_tune(3,1.7e-2)</pre><p>epoch train_loss valid_loss accuracy time 0 1.767307 5.993516 0.469388 00:14 epoch train_loss valid_loss accuracy time 0 1.003815 4.203748 0.632653 00:14 1 1.099732 3.330343 0.673469 00:15 2 0.827126 1.924323 0.673469 00:15</p><p>With just 3 epochs, our model is able to reach an accuracy of about 67 percent. While this is a good starting point, there are many ways we could potentially improve the performance of our model. Some possible techniques include:</p><ul><li><strong>Training for more epochs:</strong> By training for more epochs, the model will have more opportunities to update its weights and learn from the data, which could lead to improved performance.</li><li><strong>Cleaning the data:</strong> By removing any wrongly labeled images or any other noisy data, the model will have more reliable data to learn from, which could lead to improved performance.</li><li><strong>Choosing a different architecture:</strong> Different architectures may have different strengths and weaknesses, and some may be better suited to our dataset than others.</li><li><strong>Data augmentation:</strong> By applying data augmentation techniques like random flipping, rotation, and zooming, we can make the model more robust and generalize better to unseen data.</li><li><strong>Regularization:</strong> By using techniques like dropout, weight decay, or early stopping, we can reduce overfitting and improve the generalization of the model. I encourage you to explore these different techniques and come up with your own methods for improving the performance of your model. The best way to learn is by experimenting and trying different things out for yourself.</li></ul><h3>Using the model</h3><p>Now that we have trained our model, we can use it to make predictions on new data. One way to do this is by using the predict() method provided by the Learner object. The predict() method takes an image or a batch of images as input and returns the predicted class or classes. Let&#39;s see how well it classifies our red_traffic_light image that we downloaded earlier.</p><pre>learn.predict(&#39;red_light.jpg&#39;)</pre><pre>(&#39;red_traffic_light&#39;,<br> TensorBase(1),<br> TensorBase([1.5997e-12, 1.0000e+00, 1.9508e-06]))</pre><p>As you can see, the predict() method successfully classified the image as red_traffic_light, which is the correct class. This is a good indication that our model has learned to recognize the characteristics of red traffic lights and can make accurate predictions on new images.</p><h3>Conclusion</h3><p>Overall, this simple example shows how easy it is to create an image classifier using the fastai library, and how powerful it can be even with a small amount of data and a small number of training epochs. It’s a great starting point for further exploring and experimenting with more complex models and more advanced techniques.</p><p>I’m glad you found this tutorial helpful. If you liked it, please consider leaving feedback and suggestions on how it can be improved.</p><p><em>Abdul Ahad</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a3c30c27e1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>