<?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 Ramji Balasubramanian on Medium]]></title>
        <description><![CDATA[Stories by Ramji Balasubramanian on Medium]]></description>
        <link>https://medium.com/@ramji-b?source=rss-3882a13bf64b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*B66o5olWNjVIdI4ES5drPw.jpeg</url>
            <title>Stories by Ramji Balasubramanian on Medium</title>
            <link>https://medium.com/@ramji-b?source=rss-3882a13bf64b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 22:05:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramji-b/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[AI for Indian Farmers: Transforming Traditional Farmers into Technology-Driven Farmers]]></title>
            <link>https://medium.com/fasalapp/ai-for-indian-farmers-transforming-traditional-farmers-into-technology-driven-farmers-60bac6f4a367?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/60bac6f4a367</guid>
            <category><![CDATA[precision-agriculture]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[digital-transfomation]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Fri, 31 Dec 2021 07:58:10 GMT</pubDate>
            <atom:updated>2021-12-31T07:58:10.015Z</atom:updated>
            <content:encoded><![CDATA[<p>As per the <a href="https://www.fao.org/india/fao-in-india/india-at-a-glance/en/">Food and Agricultural Organisation(FAO) of the United Nation report in 2016</a>,- Agriculture accounted for 23% of GDP and employed 59% of the country’s total workforce. However, India still has many growing concerns. As the Indian economy has diversified and grown, agriculture&#39;s contribution to GDP has steadily declined from 1951 to 2011. While achieving food sufficiency in production, India still accounts for a quarter of the world’s hungry people and is home to over 190 million undernourished people. The incidence of poverty is now pegged at nearly 30 percent. As per the Global Nutrition Report (2016), India ranks 114th out of 132 countries on under-5 stunting and 120th out of 130 countries on under-5 wasting, and 170th out of 185 countries on prevalence of anaemia. Anaemia continues to affect 50 percent of women including pregnant women and 60 percent of children in the country.</p><p>While agriculture in India has achieved grain self-sufficiency but the production is resource-intensive, cereal centric, and regionally biased. The resource-intensive ways of Indian agriculture have raised serious sustainability issues too and would definitely need a realignment and rethinking of policies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*jbsRrWCpoZirpbet" /></figure><blockquote><em>India has enough food; does it have too many people working in agriculture? The pressure on land is an outcome of policy, which condemns most people to marginal farming. India needs a </em><strong><em>different set of solutions for agriculture and for those working the land</em></strong><em>.</em></blockquote><p>Being an Engineer, when I read this report of FAO it made me think that one main reason for the intensive resource usage could be the way of farming. Most of the farmers in India are typically following a traditional approach or what they have been taught by their forefathers. But as climate change is happening it is becoming very hard for farmers to follow the traditional way of farming.</p><p>On the other hand, as the cost of cloud, sensors and computational power has come down drastically in recent years, Artificial Intelligence(AI) has come in to solve these dynamically changing problems with <strong>data-driven solutions in a cheaper and efficient way with precise accuracy.</strong></p><h3>Technology-Driven Farmers</h3><p>The pace of technological advances has redefined farming over the years and has affected the agriculture industry in more ways than one. In recent years, Indian farmers are being guided using different techniques like the Internet of Things, AI, etc., to plan the usage of resources, chemical sprays, etc., which in turn optimizes the resource usage. The intelligent way of predictions using these AI-driven technologies is gradually transforming Indian Farmers to use crop-specific precise decision making in their field.</p><p><strong><em>Some major applications of the AI-driven technologies in agriculture are:</em></strong></p><ul><li><em>Microclimate Forecasting </em>— India has different climate conditions due to its vast size and marked variations in terrain. Microclimate variables like temperature, humidity, precipitation are sensitive to land surface properties and land-atmosphere connections making microclimate forecasting more difficult. Getting the accurate microclimate around the crop canopy allows farmers to potentially minimize disease and pest incidence, effectively manage crop growth, optimise resources and plan optimal harvest time. Based on past days of data, different time-series model are being proposed in recent researches for better prediction of microclimate parameters like temperature, humidity, rainfall, etc. They outperform local weather forecasts available to farmers globally, either by the meteorological department or universities or some weather app, as they provide weather forecasts for larger areas. We at Fasal have also developed our own AI based microclimate forecast models the details of which could be found in our previously published article on <a href="https://medium.com/fasalapp/why-fasal-built-its-own-ai-based-weather-forecast-system-fasal-%CE%BCclimate-28f2eeae80ae">AI based microclimate forecast</a> and <a href="https://medium.com/fasal-engineering/exploring-doppler-weather-radar-images-to-generate-rainfall-alerts-9ba07e6263d0">doppler radar based local rainfall prediction</a>.</li><li><em>Irrigation Management</em> — As per the Ministry of Water Resources report, water use efficiency (WUE) in Agricultural sector is only 38% in comparison to developed countries with a WUE of 50–60%. Low WUE or overwatering not only wastes water but also damages roots and causes the plant to slowly starve to death. AI can help in developing precision irrigation model allowing the application of water and nutrients to the plant at the right time and place in small measured doses in order to provide it with optimal growing conditions. For more details please refer to our <a href="https://medium.com/fasalapp/are-you-irrigating-your-vineyard-right-f08be0665b29">article</a> on Fasal’s technology on irrigation management of vineyards based on real-time data to maintain suitable soil moisture levels at different crop stages.</li><li><a href="https://medium.com/fasalapp/grape-powdery-mildew-risk-and-mitigation-b6efb50c1e5d"><em>Disease/Pest Monitoring</em></a> —Changes in climate are having a significant impact on agricultural pest/disease occurence. There is a serious risk of crop economic losses, as well as a challenge to human food security. Timing is crucial when it comes to protecting crops form pest/diseases and knowing what to expect before it infects their fields. Prevention is most often the best treatment option. The crop-specific diseases are closely related to microclimate changes and the use of modelling prediction tools could help in their early detection. In one of our previous <a href="https://medium.com/fasalapp/grape-powdery-mildew-risk-and-mitigation-b6efb50c1e5d">articles</a>, we explain how Fasal has developed dynamic models for Powdery Mildew by tracking pathogen growth and their development, and infection level in the crop and continuously notifying the farmer through the app. Fasal has now &gt;50 different pest/disease models that help our farmers to take up preventive sprays at the right time, thereby, reducing the damage to the crop as well as reducing the unnecessary traditional way of repetitive sprays.</li><li><em>Remote Sensing using Satellite Imagery </em>— Images taken from satellites provide a means to assess crop conditions without physically touching them. These images can be used to identify nutrient deficiencies, diseases, water deficiency or water logging, weed infestations, insect damage, and plant populations. Addiitonally, these images can be used as base maps in variable rate applications of fertilizers and pesticides allowing farmers to treat only affected areas of a field. Problems within a field may be identified remotely before they can be visually identified. More details on how satellite imagery is being used for crop health assesment could be found <a href="https://medium.com/fasalapp/crop-health-assessment-using-satellite-imagery-2dcc57f76f33">here</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*HzF6zjnFeAsSWh23" /><figcaption>Fasal’s Device from the field</figcaption></figure><p>“I believe if a car can be driven without a driver why not an Indian farmer can change their gear to tech-driven farmers and eventually make ourselves as hunger-free country.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60bac6f4a367" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fasalapp/ai-for-indian-farmers-transforming-traditional-farmers-into-technology-driven-farmers-60bac6f4a367">AI for Indian Farmers: Transforming Traditional Farmers into Technology-Driven Farmers</a> was originally published in <a href="https://medium.com/fasalapp">Fasal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Regularization]]></title>
            <link>https://ramji-b.medium.com/regularization-e7b7d5104eb1?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7b7d5104eb1</guid>
            <category><![CDATA[regularization]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Sun, 07 Mar 2021 13:48:14 GMT</pubDate>
            <atom:updated>2021-03-07T14:10:55.943Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“Many strategies used in machine learning are explicitly designed to reduce the test error, possibly at the expense of increased training error. These strategies are collectively known as regularization.” — Goodfellow et al.</blockquote><p>In Neural Networks, obtaining a generalized model by choosing the right set of parameters(Weights and Biases) is a key factor, to lessen the effect of overfitting. How can we obtain such parameters?. The answer is <strong>regularization</strong>. Regularization can be splinted into two buckets.</p><ul><li><em>Implicit Regularization Methods</em>: Data augmentation and early stopping</li><li><em>Explicit Regularization Methods</em>: Dropout</li></ul><p>There are various types of regularization techniques, such as L1 regularization, L2 regularization (commonly called “weight decay”), and Elastic Net, that are used by updating the loss function itself, adding an additional parameter to constrain the capacity of the model.</p><h3>Why do we need Regularization?</h3><p>Regularization helps us control our model capacity, ensuring that our models are better at making (correct) classifications on data points that they were not trained on, which we call the ability to generalize. If we don’t apply regularization, our classifiers can easily become too complex and overfit to our training data, in which case we lose the ability to generalize to our testing data (and data points outside the testing set as well, such as new images in the wild).</p><p>However, too much regularization can be a bad thing. We can run the risk of underfitting, in which case our model performs poorly on the training data and is not able to model the relationship between the input data and output class labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*8zQWv2mPFkS0eN40pJH4wQ.png" /><figcaption><strong>blue line:</strong> overfit, <strong>orange line: </strong>Underfit</figcaption></figure><p>The goal of regularization is to obtain these types of “green functions” that fit our training data nicely, but avoid overfitting to our training data (blue) or failing to model the underlying relationship (orange).</p><h3>Loss and Weight Update to include Regularization</h3><p>The loss over the entire training set can be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*oxbbX-fxVpSNQd9bZI9U7g.png" /></figure><p>Now, let’s say that we have obtained a weight matrix W such that every data point in our training set is classified correctly, which means that our loss L = 0. Awesome, we’re getting 100% accuracy — but let me ask you a question about this weight matrix — is it unique? Or, in other words, are there better choices of W that will improve our model’s ability to generalize and reduce overfitting?</p><p>If there is such a W, how do we know? And how can we incorporate this type of penalty into our loss function? The answer is to define a regularization penalty, a function that operates on our weight matrix. The regularization penalty is commonly written as a function, R(W).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/145/1*RdruCBbsoW2E4oA5K6bGZA.png" /><figcaption>L2 Regularization</figcaption></figure><p>To mitigate the effect various dimensions have on our output classifications, we apply regularization, thereby seeking W values that take into account all of the dimensions rather than the few with large values. In practice you may find that regularization hurts your training accuracy slightly, but actually increases your testing accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*uJptb0IY3mbWOnsYLLm_0A.png" /></figure><p>The second term is new — this is our regularization penalty. The \lambda variable is a hyperparameter that controls the amount or strength of the regularization we are applying. In practice, both the learning rate \alpha and the regularization term \lambda are the hyperparameters that you’ll spend the most time tuning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*gFRSp_z-rE0saFt1fvOesA.png" /><figcaption>weight updating during backpropagation</figcaption></figure><p>Here we are adding a negative linear term to our gradients (i.e., gradient descent), penalizing large weights, with the end goal of making it easier for our model to generalize.</p><p><strong>Reference:</strong></p><p>Deep Learning for Computer Vision with Python by Adrian Rosebrock (Starter Bundle)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7b7d5104eb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Batch Normalization and its Advantages]]></title>
            <link>https://ramji-b.medium.com/batch-normalization-and-its-advantages-a1dc52af83d0?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1dc52af83d0</guid>
            <category><![CDATA[batch-normalization]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[basics]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Sat, 06 Mar 2021 14:18:13 GMT</pubDate>
            <atom:updated>2021-03-06T14:18:13.142Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I was reading about NFNets, a state-of-the-art algorithm in image classification without Normalization by Deepmind. Understanding the functionality of Batch-Normalization in Deep Neural Networks and it effects was one the key element to understand NFNets Algorithm. Just thought of sharing my understanding of Batch-Normalization.</p><p>Training Deep Neural Network with n number of layers is challenging as they are sensitive to few parameters like initial random weights, learning rate, etc., One possible reason for this is the distribution of the inputs to layers deep in the network may change after each mini-batch when backpropagates. This change in distribution of inputs to layers in deep neural networks is referred as “internal covariance shift”.</p><h3>What is Batch Normalization?</h3><p>Batch normalization is a technique for training very deep neural networks that standardizes the inputs to a layer for each mini-batch. This has the effect of stabilizing the learning process and dramatically reducing the number of training epochs required to train deep networks.</p><blockquote>Algorithm</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*hevKa1HncdbaffoIgdh2FA.png" /><figcaption>image from paper</figcaption></figure><p>The BN transform can be added to a network to manipulate any activation. In the notation y = BNγ,β(x), we indicate that the parameters γ and β are to be learned, but it should be noted that the BN transform does not independently process the activation in each training example. Rather, BNγ,β(x) depends both on the training example and the other examples in the mini-batch. The scaled and shifted values y are passed to other network layers. The normalized activations xb are internal to our transformation, but their presence is crucial. The distributions of values of any xb has the expected value of 0 and the variance of 1, as long as the elements of each mini-batch are sampled from the same distribution, and if we neglect epsilon. Each normalized activation xb (k) can be viewed as an input to a sub-network composed of the linear transform y (k) = γ (k)xb (k) + β (k) , followed by the other processing done by the original network. These sub-network inputs all have fixed means and variances, and although the joint distribution of these normalized xb (k) can change over the course of training, we expect that the introduction of normalized inputs accelerates the training of the sub-network and, consequently, the network as a whole.</p><h3>Accelerating Batch Normalization Networks</h3><p>Simply adding Batch Normalization to a network does not take full advantage of our method. To do so, we applied the following modifications:</p><ul><li><strong><em>Increase learning rate:</em></strong> In a batch-normalized model, they have been able to achieve a training speedup from higher learning rates, with no ill side effects</li><li><strong><em>Remove Dropout: </em></strong>Google research team found that removing Dropout from BN-Inception allows the network to achieve higher validation accuracy. We conjecture that Batch Normalization provides similar regularization benefits as Dropout, since the activations observed for a training example are affected by the random selection of examples in the same mini-batch.</li><li><strong><em>Shuffle training examples more thoroughly</em></strong>: Google research team enabled within-shard shuffling of the training data, which prevents the same examples from always appearing in a mini-batch together. This led to about 1% improvement in the validation accuracy, which is consistent with the view of Batch Normalization as a regularizer: the randomization inherent in our method should be most beneficial when it affects an example differently each time it is seen.</li><li><strong>Reduce the L2 weight regularization:</strong> While in Inception an L2 loss on the model parameters controls overfitting, in modified BN-Inception the weight of this loss is reduced by a factor of 5. they found that this improves the accuracy on the held-out validation data.</li><li><strong><em>Accelerate the learning rate decay</em></strong>. In training Inception, learning rate was decayed exponentially. Because our network trains faster than Inception, we lower the learning rate 6 times faster.</li><li><strong><em>Remove Local Response Normalization</em></strong> While Inception and other networks (Srivastava et al., 2014) benefit from it, we found that with Batch Normalization it is not necessary. Reduce the photometric distortions. Because batch normalized networks train faster and observe each training example fewer times, we let the trainer focus on more “real” images by distorting them less.</li></ul><p>The whole article is a compilation of important information from paper. I hope this helps to understand batch normalization better and faster.</p><p><strong>Reference</strong></p><p><a href="http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43442.pdf">http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43442.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1dc52af83d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stochastic Gradient Descent (SGD)]]></title>
            <link>https://medium.com/analytics-vidhya/stochastic-gradient-descent-sgd-881d7a0ea137?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/881d7a0ea137</guid>
            <category><![CDATA[stochastic-gradient]]></category>
            <category><![CDATA[gradient-descent-python]]></category>
            <category><![CDATA[gradient-descent]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Mon, 01 Feb 2021 02:48:13 GMT</pubDate>
            <atom:updated>2021-02-01T15:55:34.695Z</atom:updated>
            <content:encoded><![CDATA[<p>Gradient Descent, a first order optimization used to learn the weights of classifier. However, this implementation of gradient descent will be computationally slow to reach the global minima. If you want to read and understand about gradient descent read my previous article on “<a href="https://medium.com/analytics-vidhya/understanding-gradient-descent-106ad1142ff4">Understanding Gradient Descent</a>”.</p><p><strong>Stochastic Gradient Descent(SGD)</strong> is a simple modification to the standard gradient descent where the weight matrix W is updated for a smaller batch of dataset instead of updating at the end of every epoch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*lETgf8vtqTvtMrcR.png" /></figure><h3>Mini-batch SGD</h3><p>Reviewing the gradient descent algorithm, it should be obvious that the method will run very slowly on large datasets. The reason for this slowness is because each iteration of gradient descent requires us to compute a prediction for each training point in our training data before we are allowed to update our weight matrix. For image datasets such as ImageNet were we have over 1.2 million training images, this computation can take a long time. It also turns out that computing predictions for every training point before taking a step along our weight matrix is computationally wasteful and does little to help our model coverage. Instead, what we should do is batch our updates.</p><pre>#Pseudocode<br>while True:<br>   batch = next_training_batch(data, 256)#256 batch-size<br>   Wgradient = evaluate_gradient(loss, batch, W)<br>   W += -alpha * Wgradient</pre><p>The only difference between gradient descent and SGD is next batch training. As we can observe, if we have 512 data points the weight matrix (W) will gets updated for every 256 samples (256 batch-size). The batch size will always be greater than 1. To start, batch sizes &gt; 1 help reduce variance in the parameter update, leading to a more stable convergence.</p><h3>Implementation</h3><pre>import the necessary packages<br>from sklearn.model_selection import train_test_split<br>from sklearn.metrics import classification_report<br>from sklearn.datasets import make_blobs<br>import matplotlib.pyplot as plt<br>import numpy as np<br>import argparse</pre><pre>def sigmoid_activation(x):</pre><pre>     # compute the sigmoid activation value for a given input<br>     return 1.0 / (1 + np.exp(-x))</pre><pre>def sigmoid_deriv(x):<br>     # compute the derivative of the sigmoid function ASSUMING<br>     # that the input `x` has already been passed through <br>     # the sigmoid activation function<br>      return x * (1 - x)</pre><pre>def predict(X, W):<br>    # take the dot product between our features and weight matrix<br>    preds = sigmoid_activation(X.dot(W))<br>    # apply a step function to threshold the outputs to binary<br>    # class labels<br>    preds[preds &lt;= 0.5] = 0<br>    preds[preds &gt; 0] = 1<br>    # return the predictions<br>    return preds</pre><pre>def next_batch(X, y, batchSize):<br>    # loop over our dataset `X` in mini-batches, yielding a tuple of<br>    # the current batched data and labels<br>    for i in np.arange(0, X.shape[0], batchSize):<br>        yield (X[i:i + batchSize], y[i:i + batchSize])</pre><pre># construct the argument parse and parse the arguments<br>ap = argparse.ArgumentParser()<br>ap.add_argument(&quot;-e&quot;, &quot;--epochs&quot;, type=float, default=100,<br>help=&quot;# of epochs&quot;)<br>ap.add_argument(&quot;-a&quot;, &quot;--alpha&quot;, type=float, default=0.01,<br>help=&quot;learning rate&quot;)<br>ap.add_argument(&quot;-b&quot;, &quot;--batch-size&quot;, type=int, default=32,<br>help=&quot;size of SGD mini-batches&quot;)<br>args = vars(ap.parse_args())</pre><pre># generate a 2-class classification problem with 1,000 data points,<br># where each data point is a 2D feature vector<br>(X, y) = make_blobs(n_samples=1000, n_features=2, centers=2,   cluster_std=1.5, random_state=1)<br>y = y.reshape((y.shape[0], 1))</pre><pre># insert a column of 1&#39;s as the last entry in the feature<br># matrix -- this little trick allows us to treat the bias<br># as a trainable parameter within the weight matrix<br>X = np.c_[X, np.ones((X.shape[0]))]<br># partition the data into training and testing splits using 50% of<br># the data for training and the remaining 50% for testing<br>(trainX, testX, trainY, testY) = train_test_split(X, y,<br>test_size=0.5, random_state=42)</pre><pre># initialize our weight matrix and list of losses<br>print(&quot;[INFO] training...&quot;)<br>W = np.random.randn(X.shape[1], 1)<br>losses = []</pre><pre># loop over the desired number of epochs<br>for epoch in np.arange(0, args[&quot;epochs&quot;]):<br>   # initialize the total loss for the epoch<br>   epochLoss = []<br>   # loop over our data in batches<br>   for (batchX, batchY) in next_batch(trainX, <br>                       trainY,   args[&quot;batch_size&quot;]):<br>       # take the dot product between our current batch of features<br>       # and the weight matrix, then pass this value through our<br>       # activation function <br>       preds = sigmoid_activation(batchX.dot(W))<br>       # now that we have our predictions, we need to determine th<br>       # `error`, which is the difference between our predictions<br>       # and the true values<br>       error = preds - batchY<br>       epochLoss.append(np.sum(error ** 2))<br>       # the gradient descent update is the dot product between our<br>       # (1) current batch and (2) the error of the sigmoid<br>       # derivative of our predictions</pre><pre>       # update our loss history by taking the average loss <br>       # across all<br>       # batches <br>       loss = np.average(epochLoss)  <br>       losses.append(loss)<br>       # check to see if an update should be displayed<br>       if epoch == 0 or (epoch + 1) % 5 == 0:<br>         print(&quot;[INFO] epoch={}, loss={:.7f}&quot;.format(int(<br>                                        epoch + 1),   loss))</pre><pre># evaluate our mode<br>print(&quot;[INFO] evaluating...&quot;)<br>preds = predict(testX, W)<br>print(classification_report(testY, preds))</pre><pre># plot the (testing) classification data<br>plt.style.use(&quot;ggplot&quot;)<br>plt.figure()<br>plt.title(&quot;Data&quot;)<br>plt.scatter(testX[:, 0], testX[:, 1], marker=&quot;o&quot;, c=testY[:, 0], s=30)<br># construct a figure that plots the loss over time<br>plt.style.use(&quot;ggplot&quot;)<br>plt.figure()<br>plt.plot(np.arange(0, args[&quot;epochs&quot;]), losses)<br>plt.title(&quot;Training Loss&quot;)<br>plt.xlabel(&quot;Epoch #&quot;)<br>plt.ylabel(&quot;Loss&quot;)<br>plt.show()</pre><p>Happy Learning!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=881d7a0ea137" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/stochastic-gradient-descent-sgd-881d7a0ea137">Stochastic Gradient Descent (SGD)</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Region — Based Convolutional Neural Network (RCNN)]]></title>
            <link>https://medium.com/analytics-vidhya/region-based-convolutional-neural-network-rcnn-b68ada0db871?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b68ada0db871</guid>
            <category><![CDATA[r-cnn]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[object-detection]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Wed, 27 Jan 2021 03:06:12 GMT</pubDate>
            <atom:updated>2024-02-01T11:54:25.029Z</atom:updated>
            <content:encoded><![CDATA[<h3>Region — Based Convolutional Neural Network (RCNN)</h3><p><a href="https://www.analyticsvidhya.com/blog/2018/11/implementation-faster-r-cnn-python-object-detection/?utm_source=medium&amp;utm_medium=medium&amp;utm_campaign=backlinking">R-CNN </a>is a region based Object Detection Algorithm developed by Girshick et al., from UC Berkeley in 2014. Before jumping into the algorithm lets try to understand what object detection actually means and how it differs from image classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4fd3wSm1rGeJI7aN.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*NYHpsWZ8s-E1fthY.jpg" /></figure><h3><strong>What is Object Detection?</strong></h3><p>Take the example for the above given image, and think about image classification. We will be able to classify whether the given image is dog/cat from first example, where as in second example we cant unless we detect dog and cat individually. In real world, we always have multiple objects in single image. This is were the importance of object detection comes.</p><p><strong>Image Classification</strong>: Predict the type or class of an object in an image.</p><ul><li><em>Input</em>: An image with a single object, such as a photograph.</li><li><em>Output</em>: A class label (e.g. one or more integers that are mapped to class labels).</li></ul><p><strong>Object Detection</strong>: Locate the presence of objects with a bounding box and types or classes of the located objects in an image.</p><ul><li><em>Input</em>: An image with one or more objects, such as a photograph.</li><li><em>Output</em>: One or more bounding boxes (e.g. defined by a point, width, and height), and a class label for each bounding box.</li></ul><h3><strong>R-CNN Algorithm</strong></h3><p>To understand R-CNN we need to have some prior knowledge on how Convolutional Neural Network works and what is Mean Average Precision (mAP) metric to measure the performance.</p><blockquote><strong>Link:</strong></blockquote><blockquote>CNN — <a href="https://adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/">https://adeshpande3.github.io/A-Beginner%27s-Guide-To-Understanding-Convolutional-Neural-Networks/</a></blockquote><blockquote>mAP — <a href="https://datanics.blogspot.com/2020/11/understanding-mean-average-precision.html?m=1">https://datanics.blogspot.com/2020/11/understanding-mean-average-precision.html?m=1</a></blockquote><p>R-CNN(<a href="https://arxiv.org/pdf/1311.2524v5.pdf">paper</a>) one of the first large and successful application of convolutional neural networks to the problem of object localization, detection, and segmentation. The approach was demonstrated on benchmark datasets, achieving then state-of-the-art results on the VOC-2012 dataset and the 200-class ILSVRC-2013 object detection dataset.</p><blockquote><strong>Architecture:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/0*5n3hUSd2IzY0bPo9.png" /></figure><p>Region based CNN consists of three modules — Region Proposal, Feature Extractor and Classifier.</p><p><strong>Region Proposal :</strong> When an input image is given region proposal tries to detect different regions (~2000) in different sizes and aspect ratios. In other words, it draws multiple bounding boxes in input image as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*6vIkiYSm1KspAB_6JUCflQ.png" /><figcaption>Region Proposal Result</figcaption></figure><p><strong>Feature Extractor:</strong> Each proposed region will be trained by a CNN network and the last layer (4096 features) will be extracted as features so the final output from Feature extractor will be <strong>Number of proposed regions x 4096</strong></p><p><strong>Classifier: </strong>Once the features are extracted we need to classify the objects inside each regions. To do this a linear SVM model is trained for classification, Specifically one <a href="https://www.analyticsvidhya.com/blog/2017/09/understaing-support-vector-machine-example-code/">SVM model</a> for each class.</p><h3><strong>Cons of R-CNN:</strong></h3><ul><li>It takes a huge amount of time to train the network as you would have to classify 2000 region proposals per image.</li><li>It cannot be implemented real time as it takes around 47 seconds for each test image.</li><li>The selective search algorithm is a fixed algorithm. Therefore, no learning is happening at that stage. This could lead to the generation of bad candidate region proposals.</li></ul><p>Thanks for reading!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b68ada0db871" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/region-based-convolutional-neural-network-rcnn-b68ada0db871">Region — Based Convolutional Neural Network (RCNN)</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Car Sales Prediction — Using Basic Matrix Operations]]></title>
            <link>https://medium.com/analytics-vidhya/car-sales-prediction-using-basic-matrix-operations-60ca8ede3bfa?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/60ca8ede3bfa</guid>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[predictions]]></category>
            <category><![CDATA[basics]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Thu, 21 Jan 2021 03:16:49 GMT</pubDate>
            <atom:updated>2021-01-21T15:46:49.150Z</atom:updated>
            <content:encoded><![CDATA[<h3>Car Sales Prediction — Using Basic Matrix Operations</h3><p>We have been studying matrix operations like Ax = b from schooling, but have we ever realized how its simplified linear regression (y=mx+c) problem. Yes, Today we are going to use matrix operations to find slope(m) and intercept(c) for predicting the<strong> car resales value</strong>.</p><p>Before getting into problem let us try to recap Ax=b, with an example as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*p5dRnvAzAiREop1f" /></figure><p>Where A is matrix of size m x n, linearly combined with x (n x 1) to obtain the target variable b (n x 1)</p><p><strong>How to relate this to Linear regression Problem?</strong></p><p>In our Car sales data, we have two columns one is Power_perf_factor and Resale Value, where we need to predict the resale value(y) with respect to input feature power factor(x).</p><blockquote>resale value = slope * power factor + intercept</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*g0aWM07phCzFDde6v3_Taw.png" /></figure><p>to represent this in matrix format, we need to form a matrix A with input feature (power factor) as one column and one column with ones for adding bias, B matrix will be our resale value and x will be our slope and intercept variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*7eKOmUOTwotDye_rHlLHYg.png" /></figure><p>For single feature we might think matrix operation is not much necessary but think if you have billions of rows and billions of features to predict the car resale value, then representing the equation (y = mx + c) in matrix format makes our life easier for prediction.</p><h3>Python Implementation</h3><pre>#importing necessary libraries</pre><pre># pandas -- &gt; dataframe operations<br># matplot --&gt; visualizations<br># numpy --&gt; Matrix operations</pre><pre>import pandas as pd<br>import matplotlib.pyplot as plt<br>import numpy as np</pre><pre>#reading the data set<br>data=pd.read_csv(&#39;Car_sales.csv&#39;)</pre><pre>#storing input feature in variable x<br>x = np.array(data[&#39;Power_perf_factor&#39;].values)</pre><pre>#formating the input feature as matrix A as shown in above figure<br>mat_A = np.transpose(np.vstack((x,np.ones(len(x)))))</pre><pre>#calculating slope and intercept (x = B/A)<br>output = np.matmul(np.linalg.pinv(mat_A),np.expand_dims(data[&#39;Resale_value&#39;].values,1))</pre><pre>#calculating ydash value based on slope and intercept(y=mx+c)<br>ydash = output[0,:]*x + output[1,:]</pre><pre>#plotting the original y value and predicted y value<br>plt.figure(figsize=(20,5))plt.plot(y, label = &#39;True Label&#39;)<br>plt.plot(ydash, label = &#39;Predicted&#39;)</pre><pre><br>#naming y axis<br>plt.ylabel(&#39;Resale Value&#39;)</pre><pre>#to show legend <br>plt.legend()<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gLAmPsv6IWQWTBLhFYYxAg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60ca8ede3bfa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/car-sales-prediction-using-basic-matrix-operations-60ca8ede3bfa">Car Sales Prediction — Using Basic Matrix Operations</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Gradient Descent]]></title>
            <link>https://medium.com/analytics-vidhya/understanding-gradient-descent-106ad1142ff4?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/106ad1142ff4</guid>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[gradient-descent]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Mon, 04 Jan 2021 16:09:00 GMT</pubDate>
            <atom:updated>2021-01-04T16:43:23.291Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/972/0*qLD9GxG0hl3-VyKw.png" /></figure><blockquote>If you are dropped in some part of Himalayas around 8 AM, How will we think to get to the safe place before sunset ? — Gradient Descent is the actual solution behind your thought process. Yes, we need to find the direction in which we have to move based on our initial assumptions such that we will reach the safe place on or before time.</blockquote><p>In my previous articles, I have explained about <a href="https://medium.com/analytics-vidhya/parameterized-learning-91f701f9cabb">Parameterized learning</a> and basic <a href="https://medium.com/analytics-vidhya/loss-functions-multiclass-svm-loss-and-cross-entropy-loss-9190c68f13e0">loss function</a> techniques. In case if you have not read, Do read those for better understanding of Gradient Descent.</p><p>In Deep Learning based problems, optimization algorithms plays an important role in achieving higher accuracy by updating the randomly initialized parameters based on the loss occurred in training process. How can we relate this to our Himalayas example?</p><p>Humans can think in multiple direction before taking a step down during hike to the safe place, whereas when you train a machine you have to try all the possibilities before taking a direction to move downhill and find the loss based on the initial assumptions and update during the second trial, such that machine is trained to reach the safe house.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*niZ8Iw5pSa1Fmrjs-Eq6_g.png" /></figure><p>In the above graph, we can see two minimal points, which looks similar but actually not. So the right parameters are necessary to reach the actual/ true minimal point(Global minima)</p><h3><strong>Steps followed to evaluate gradient</strong></h3><ol><li><strong>loss</strong>: A function used to compute the loss over our current parameters W and input data.</li><li><strong>data</strong>: Our training data where each training sample is represented by an image</li><li><strong>W: </strong>Our actual weight matrix that we are optimizing over. Our goal is to apply gradient descent to find a W that yields minimal loss.</li></ol><blockquote>The Gradient Descent Algorithm will help to compute the gradient(direction) <strong>W </strong>across all dimension using the formula</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*VTlQGTwTIH-wEGjfXYlLbA.png" /></figure><h3><strong>Practical Implementation</strong></h3><pre># import the necessary packages<br>from sklearn.model_selection import train_test_split<br>from sklearn.metrics import classification_report<br>from sklearn.datasets import make_blobs<br>import matplotlib.pyplot as plt<br>import numpy as np<br>import argparse</pre><pre>def sigmoid_activation(x):<br>  # compute the sigmoid activation value for a given input<br>  return 1.0 / (1 + np.exp(-x))</pre><pre>def sigmoid_deriv(x):<br>  # compute the derivative of the sigmoid function ASSUMING<br>  # that the input `x` has already been passed through the sigmoid<br>  # activation function<br>  return x * (1 — x)</pre><pre>def predict(X, W):<br>  # take the dot product between our features and weight matrix<br>  preds = sigmoid_activation(X.dot(W))</pre><pre>  # apply a step function to threshold the outputs to binary<br>  # class labels<br>  preds[preds &lt;= 0.5] = 0<br>  preds[preds &gt; 0] = 1</pre><pre>  # return the predictions<br>  return preds</pre><pre># construct the argument parse and parse the arguments<br>ap = argparse.ArgumentParser()<br>ap.add_argument(“-e”, “ — epochs”, type=float, default=100,<br> help=”# of epochs”)<br>ap.add_argument(“-a”, “ — alpha”, type=float, default=0.01,<br> help=”learning rate”)<br>args = vars(ap.parse_args())</pre><pre># generate a 2-class classification problem with 1,000 data points,<br># where each data point is a 2D feature vector<br>(X, y) = make_blobs(n_samples=1000, n_features=2, centers=2,<br> cluster_std=1.5, random_state=1)<br>y = y.reshape((y.shape[0], 1))</pre><pre># insert a column of 1’s as the last entry in the feature<br># matrix — this little trick allows us to treat the bias<br># as a trainable parameter within the weight matrix<br>X = np.c_[X, np.ones((X.shape[0]))]</pre><pre># partition the data into training and testing splits using 50% of<br># the data for training and the remaining 50% for testing<br>(trainX, testX, trainY, testY) = train_test_split(X, y,<br> test_size=0.5, random_state=42)</pre><pre># initialize our weight matrix and list of losses<br>print(“[INFO] training…”)<br>W = np.random.randn(X.shape[1], 1)<br>losses = []</pre><pre># loop over the desired number of epochs<br>for epoch in np.arange(0, args[“epochs”]):<br>  # take the dot product between our features `X` and the weight<br>  # matrix `W`, then pass this value through our sigmoid activation<br>  # function, thereby giving us our predictions on the dataset<br>  preds = sigmoid_activation(trainX.dot(W))</pre><pre>  # now that we have our predictions, we need to determine the<br>  # `error`, which is the difference between our predictions and<br>  # the true values<br>  error = preds — trainY<br>  loss = np.sum(error ** 2)<br>  losses.append(loss)</pre><pre>  # the gradient descent update is the dot product between our<br>  # (1) features and (2) the error of the sigmoid derivative of<br>  # our predictions<br>  d = error * sigmoid_deriv(preds)<br>  gradient = trainX.T.dot(d)</pre><pre>  # in the update stage, all we need to do is “nudge” the weight<br>  # matrix in the negative direction of the gradient (hence the<br>  # term “gradient descent” by taking a small step towards a set<br>  # of “more optimal” parameters<br>  W += -args[“alpha”] * gradient</pre><pre>  # check to see if an update should be displayed<br>  if epoch == 0 or (epoch + 1) % 5 == 0:<br>    print(“[INFO] epoch={}, loss={:.7f}”.format(int(epoch + 1),<br>    loss))</pre><pre># evaluate our model<br>print(“[INFO] evaluating…”)<br>preds = predict(testX, W)<br>print(classification_report(testY, preds))</pre><pre># plot the (testing) classification data<br>plt.style.use(“ggplot”)<br>plt.figure()<br>plt.title(“Data”)<br>plt.scatter(testX[:, 0], testX[:, 1], marker=”o”, c=testY[:, 0], s=30)</pre><pre># construct a figure that plots the loss over time<br>plt.style.use(“ggplot”)<br>plt.figure()<br>plt.plot(np.arange(0, args[“epochs”]), losses)<br>plt.title(“Training Loss”)<br>plt.xlabel(“Epoch #”)<br>plt.ylabel(“Loss”)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dqxI8R0tnphjTTLOm1vixQ.png" /></figure><p><strong>References:</strong></p><p>Deep Learning for Computer Vision with Python by Adrian Rosebrock (Starter Bundle)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=106ad1142ff4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/understanding-gradient-descent-106ad1142ff4">Understanding Gradient Descent</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How FASTTag Works?]]></title>
            <link>https://medium.com/analytics-vidhya/how-fasttag-works-61637da68150?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/61637da68150</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[fun]]></category>
            <category><![CDATA[opencv]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Mon, 28 Dec 2020 16:23:52 GMT</pubDate>
            <atom:updated>2021-01-10T04:53:58.097Z</atom:updated>
            <content:encoded><![CDATA[<h3>How FASTTag Works (Computer Vision in backend)?</h3><p>On 27 December,2020, I was travelling to my native town for my vacation. During the travel we crossed 4 toll plazas and wondered how FASTag works. And as a coincidence in todays news Indian Government has mandated the use of FASTag from January 1 for all vehicles to pass through toll plazas. Now, Nitin Gadkari, Union minister for road transport, highways and MSMEs has confirmed that the FASTags would be mandatory for paying at toll plazas and enable contactless as well as electronic payments for toll payments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5cSvDR1WAUmu_K05h5dwAw.jpeg" /></figure><h3>What is FASTag?</h3><p>A FASTag is a sticker that is attached to the windshield of your car, from the inside and has an imprinted Radio-frequency Identification (RFID) barcode which is linked with the registration details of your vehicle. As you drive though any toll plaza on any national highway in India, FASTag readers will read the code and will deduct the amount required to pass the barrier. All this without you having to stop, interact with a human being at a toll plaza and having to pay cash.</p><h3>How to extract FASTTag stickers from Windshield?</h3><p>To enable contactless and digital payment, first step will be to extract the FASTTag stickers from windshield. The challenges in identifying the stickers will differ to each car. In one car it might be on right side, in another car there is a possibility for multiple stickers in windshield as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFGWc4dx1ClzTKJp6dRwsA.jpeg" /><figcaption>multiple stickers all in one side</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5FAofvFrGNbCfUyNc2U6g.jpeg" /><figcaption>sticker available in center</figcaption></figure><h3>Code Snippet</h3><pre>import cv2<br>import imutils<br>import os<br>import matplotlib.pyplot as plt<br>import numpy as np<br>from skimage.measure import compare_ssim</pre><pre>original = cv2.cvtColor(cv2.imread(&#39;img1.png&#39;),cv2.COLOR_BGR2GRAY)<br>original = cv2.resize(original,(120,20))<br>plt.imshow(original,&#39;gray&#39;)</pre><pre>#visualizing the available images<br>plt.figure(figsize=(50,50))<br>for idx,image in enumerate(images):<br>    #read the image <br>    img = cv2.imread(&#39;images/&#39;+image)<br>    #opencv will be reading a image as BGR(Blue,Gree and Red) Channel<br>    #following code will convert BGR--&gt; RGB format<br>    img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)<br>    <br>    #adding known noise to the image<br>    gray = cv2.GaussianBlur(img,(5,5),0)<br>    <br>    #canny edge detection<br>    edged = cv2.Canny(gray,10,130)<br>    <br>    orig = img.copy()<br>    <br>    #find all the contours and grab all the detected contours<br>    cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)<br>    cnts = imutils.grab_contours(cnts)<br>    <br>    <br>    #sort the contour based on are and take only top 10<br>    cnts = sorted(cnts, key= cv2.contourArea, reverse=True)[:10]<br>    <br>    #show image size as 50x50 pixels<br>    plt.figure(figsize=(50,50))<br>    <br>    #loop over the contours<br>    for c in cnts:<br>        #find the arc length for each detected contour<br>        peri = cv2.arcLength(c,True)<br>        <br>        #approximate the contours <br>        apprx = cv2.approxPolyDP(c, 0.02*peri, True)<br>        <br>        #convert the approximate contours as rectangle<br>        x,y,w,h = cv2.boundingRect(apprx)<br>        <br>        #crop the detected stickers image<br>        image = img[y+7:y+h//3,x+(w)//4:x+w-(w)//4,:]<br>        <br>        #convert cropped image to grayscale<br>        image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)<br>        <br>        #threshold the cropped image for better detection of  fasttag<br>        gray = cv2.threshold(image, 20, 150,<br>                    cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]<br>        <br>        #erode the detected tags<br>        kernel = np.ones((3,3),np.uint8)<br>        erosion = cv2.erode(255-gray,kernel,iterations = 1)<br>        erosion = cv2.resize(255-erosion,(120,20))<br>        <br>        #compare all the detected stickers and compare with original fasttag <br>        #draw rectange over the fasttag tags<br>        if compare_ssim(erosion,original)&gt;0.4:<br>            cv2.rectangle(orig,(x,y),(x+w,y+h),(255,0,0),5)<br>            cv2.putText(orig,str(area),(x,y),<br>                       cv2.FONT_HERSHEY_SIMPLEX,<br>                       1,(0,255,0),2)<br>    plt.imshow(orig)<br>    plt.axis(&#39;off&#39;)<br>    plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*_evjL2_OMaBBxDnIcHF7yg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*STk-bQWFLA3sBvwmU3rRjw.png" /></figure><p>The algorithm created worked fine and detected the fasttag stickers and bounded with red box.</p><h3>References</h3><p><a href="https://www.news18.com/news/auto/faq-what-is-fastag-where-to-get-one-and-what-is-the-price-all-you-need-to-know-explained-3220436.html">https://www.news18.com/news/auto/faq-what-is-fastag-where-to-get-one-and-what-is-the-price-all-you-need-to-know-explained-3220436.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61637da68150" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/how-fasttag-works-61637da68150">How FASTTag Works?</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Eye Tracking using OpenCV]]></title>
            <link>https://medium.com/analytics-vidhya/eye-tracking-using-opencv-2f40cc09183c?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f40cc09183c</guid>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[eyes]]></category>
            <category><![CDATA[facedetection]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Sat, 26 Dec 2020 18:20:55 GMT</pubDate>
            <atom:updated>2020-12-27T12:35:32.394Z</atom:updated>
            <content:encoded><![CDATA[<p>During my early 2000&#39;s my father used to drive me to my home town for vacation. which will take approximately 8 hours from were I live. During our journey my primary role is to sit beside him and wake him up whenever his eyes getting closed. What if I am not near him? Isn’t it scary? Yeah it was. After reading this case study from OpenCV where we can use a small camera to keep tracking your eyes, felt happy and imagined about helpful it will be to avoid lots of accidents on highways.</p><h3>Steps to track your eye</h3><ol><li>Detect your face</li><li>Crop the face region and detect eyes in face region</li><li>Keep tracking the eye region</li></ol><h3>Code Snippet</h3><p>If you are trying in your own video the the scale factor and min Neighbors are the we need to tune to get the better result.</p><pre># import the necessary packages<br>import cv2</pre><pre>class EyeTracker:<br>   def __init__(self, faceCascadePath, eyeCascadePath):<br>       # load the face and eye detector<br>       self.faceCascade = cv2.CascadeClassifier(faceCascadePath)<br>       self.eyeCascade = cv2.CascadeClassifier(eyeCascadePath)</pre><pre>  def track(self, image):<br>       # detect faces in the image and initialize the list of<br>       # rectangles containing the faces and eyes<br>       faceRects = self.faceCascade.detectMultiScale(image,<br>         scaleFactor = 1.1, minNeighbors = 5, minSize = (30,30),<br>         flags = cv2.CASCADE_SCALE_IMAGE)<br>       rects = []</pre><pre>       # loop over the face bounding boxes<br>       for (fX, fY, fW, fH) in faceRects:<br>          # extract the face ROI and update the list of<br>          # bounding boxes<br>          faceROI = image[fY:fY + fH, fX:fX + fW]<br>          rects.append((fX, fY, fX + fW, fY + fH))<br> <br>          # detect eyes in the face ROI<br>          eyeRects = self.eyeCascade.detectMultiScale(faceROI,<br>          scaleFactor = 1.1, minNeighbors = 10, minSize = (20, 20),<br>          flags = cv2.CASCADE_SCALE_IMAGE)</pre><pre>          # loop over the eye bounding boxes<br>          for (eX, eY, eW, eH) in eyeRects:<br>          # update the list of boounding boxes<br>          rects.append(<br>             (fX + eX, fY + eY, fX + eX + eW, fY + eY + eH))</pre><pre>       # return the rectangles representing bounding<br>       # boxes around the faces and eyes<br>       return rects</pre><p>So now we have create a class which will detect faces and eyes from a video. But if we are sending video of different sizes the parameter needs to be changed often. To overcome this we can do a preprocessing on the input image, such that the eye tracker class will be called after converting to a certain format.</p><pre># USAGE<br># python eyetracking.py — face cascades/haarcascade_frontalface_default.xml — eye cascades/haarcascade_eye.xml — video video/adrian_eyes.mov<br># python eyetracking.py — face cascades/haarcascade_frontalface_default.xml — eye cascades/haarcascade_eye.xml</pre><pre># import the necessary packages<br>from pyimagesearch.eyetracker import EyeTracker<br>from pyimagesearch import imutils<br>import argparse<br>import cv2</pre><pre># construct the argument parse and parse the arguments<br>ap = argparse.ArgumentParser()<br>ap.add_argument(“-f”, “ — face”, required = True,<br> help = “path to where the face cascade resides”)<br>ap.add_argument(“-e”, “ — eye”, required = True,<br> help = “path to where the eye cascade resides”)<br>ap.add_argument(“-v”, “ — video”,<br> help = “path to the (optional) video file”)<br>args = vars(ap.parse_args())</pre><pre># construct the eye tracker<br>et = EyeTracker(args[“face”], args[“eye”])</pre><pre># if a video path was not supplied, grab the reference<br># to the gray<br>if not args.get(“video”, False):<br>   camera = cv2.VideoCapture(0)</pre><pre># otherwise, load the video<br>else:<br>   camera = cv2.VideoCapture(args[“video”])</pre><pre># keep looping<br>while True:<br>   # grab the current frame<br>   (grabbed, frame) = camera.read()</pre><pre>   # if we are viewing a video and we did not grab a<br>   # frame, then we have reached the end of the video<br>   if args.get(“video”) and not grabbed:<br>      break</pre><pre>   # resize the frame and convert it to grayscale<br>   frame = imutils.resize(frame, width = 300)<br>   gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)</pre><pre>   # detect faces and eyes in the image<br>   rects = et.track(gray)</pre><pre>   # loop over the face bounding boxes and draw them<br>   for rect in rects:<br>      cv2.rectangle(frame, (rect[0], rect[1]), (rect[2], rect[3]),    (0, 255, 0), 2)</pre><pre>   # show the tracked eyes and face<br>   cv2.imshow(“Tracking”, frame)</pre><pre>   # if the ‘q’ key is pressed, stop the loop<br>   if cv2.waitKey(1) &amp; 0xFF == ord(“q”):<br>     break</pre><pre># cleanup the camera and close any open windows<br>camera.release()<br>cv2.destroyAllWindows(</pre><p><strong>Reference:</strong></p><p>OpenCV- Basics Bundle by Adrian</p><p>link to code: <a href="https://github.com/RamjiB/Eye-Tracking">https://github.com/RamjiB/Eye-Tracking</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f40cc09183c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/eye-tracking-using-opencv-2f40cc09183c">Eye Tracking using OpenCV</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loss Functions — Multiclass SVM Loss and Cross Entropy Loss]]></title>
            <link>https://medium.com/analytics-vidhya/loss-functions-multiclass-svm-loss-and-cross-entropy-loss-9190c68f13e0?source=rss-3882a13bf64b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9190c68f13e0</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[loss]]></category>
            <category><![CDATA[basics]]></category>
            <dc:creator><![CDATA[Ramji Balasubramanian]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 17:01:57 GMT</pubDate>
            <atom:updated>2020-12-24T16:59:46.388Z</atom:updated>
            <content:encoded><![CDATA[<h3>Loss Functions — Multiclass SVM Loss and Cross Entropy Loss</h3><p>Why Loss function is more important in Machine Learning Applications? In my last article we discussed about <a href="https://medium.com/analytics-vidhya/parameterized-learning-91f701f9cabb">parameterized learning</a>, such types of learnings will take some data as input and class labels. Actually, a function will be learnt to map the input to predicted class labels by defining few parameters like weights and biases.</p><p>First will see how a loss curve will look a like and understand a bit before getting into SVM and Cross Entropy loss functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*OAVukRFC2JbkpKfm0QzNzA.png" /><figcaption>Loss curve</figcaption></figure><p>Above graph, is a loss curve for two different models trained on CIFAR-10 dataset. And what we can observe from these two lines on graph?</p><ol><li>Model 1 (Red Line)— As the model trains longer the loss drops</li><li>Model 2 (Blue Line) — Loss starts decreasing initially but after 10 epochs, it stops decreasing.</li></ol><p>The better classifier model will have lower loss. (But not always “Overfitting” is another concept, which we can discuss later).</p><blockquote>I have been speaking above loss some may understand some may not, but for those who haven&#39;t come across this term. Loss is a score calculated based on your true class labels and predicted class labels. Say you have trained a model to classify dog and cat image and model will predict your input image with a probability of 0.97 as cat and 0.03 as cat, the difference between your true label and predicted probability is nothing but a loss.</blockquote><p>Basically the model will be trained based on your loss and update/optimize the parameters (Weights and biases) to predict the data better.</p><h3>Multi Class SVM Loss</h3><p>Multi-class SVM Loss (as the name suggests) is inspired by (Linear) Support Vector Machines (SVMs), which uses a scoring function f to map our data points to numerical scores for each class labels.</p><p>Lets try to understand Multiclass SVM with an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3uAS8z_S7RFCHS-ukzCKg.png" /></figure><p>In this example, you have three images Dog, Cat and Panda and each image is classified out of three classes and we have three values for each image.</p><blockquote>Formula: Loss = max(0,predicted-original+1)</blockquote><p>For first image, True label is dog, and its predicted with the value of 4.26 as dog, 1.33 as cat and -1.01 as Panda.</p><pre>image_1 = max(0, 1.33–4.26 + 1) + max(0, -1.01–4.26 + 1)</pre><p>Similarly calculate the loss for all the images and add the calculated value for all input images. The average of loss values is nothing but a SVM loss (hinge Loss)</p><pre>image_2 =max(0, 3.76 — (-1.20) + 1) + max(0, -3.81 — (-1.20) + 1)</pre><pre>image_3 =max(0, -2.37 — (-2.27) + 1) + max(0, 1.03 — (-2.27) + 1)</pre><pre>loss = (image_1 + image_2 + image_3) / 3.0</pre><h3>Cross- Entropy Loss</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*zYFd4rf14DGusIDHYHkLQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJ3vl37Szagq5Ntwn2oTvg.png" /></figure><p>Our goal here is to classify our input image(Panda) as Dog, Cat or Panda. This involves three steps.</p><p>Step 1 — We will get the scoring value for each of the three classes as we got in Multiclass SVM based on the used function.</p><p>Step 2 — Exponentiate the result of Scoring function to obtain unnormalized Probabilities</p><p>Step 3 — Calculate the sum of Unnormalized Probabilities and divide each value by sum to obtain Normalized Probabilities (Softmax Layer)</p><p>Step 4 — From step 3 we actually got which class the input image belongs, but to assess how good our value is we need to apply negative natural logarithm on normalized probability.</p><p>We can then repeat this process for all images in our training set, take the average, and obtain the overall cross-entropy loss for the training set. This process allows us to quantify how good or bad a set of parameters are performing on our training set.</p><p>This will give a clarity on how multiclass and cross entropy losses are calculated with a practical example. I hope this helps.</p><p>Keep Reading!!!</p><h3>Reference:</h3><p>Deep Learning for Computer Vision with Python by Adrian Rosebrock (Starter Bundle)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9190c68f13e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/loss-functions-multiclass-svm-loss-and-cross-entropy-loss-9190c68f13e0">Loss Functions — Multiclass SVM Loss and Cross Entropy Loss</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>