<?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 Krishna Raj R on Medium]]></title>
        <description><![CDATA[Stories by Krishna Raj R on Medium]]></description>
        <link>https://medium.com/@krishnarajr319?source=rss-dd27d450bcb4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lLN0sVNp0_4I8SVp</url>
            <title>Stories by Krishna Raj R on Medium</title>
            <link>https://medium.com/@krishnarajr319?source=rss-dd27d450bcb4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 23:11:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@krishnarajr319/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[Human Pose Comparison and Action Scoring using Deep Learning,OpenCV & Python]]></title>
            <link>https://medium.com/analytics-vidhya/human-pose-comparison-and-action-scoring-using-deep-learning-opencv-python-c2bdf0ddecba?source=rss-dd27d450bcb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2bdf0ddecba</guid>
            <category><![CDATA[object-tracking]]></category>
            <category><![CDATA[opencv-python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[action-recognition]]></category>
            <dc:creator><![CDATA[Krishna Raj R]]></dc:creator>
            <pubDate>Mon, 13 Apr 2020 12:50:51 GMT</pubDate>
            <atom:updated>2023-03-20T00:03:59.985Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iot4AHNjJw0pgQW6zFgfTA.png" /></figure><blockquote><em>For the code and instructions on how to run, Please Visit : </em><a href="https://github.com/kr1210/Human-Pose-Compare">https://github.com/kr1210/Human-Pose-Compare</a></blockquote><p>Pose Estimation is one of the more elegant applications of neural networks and is startlingly accurate and sometimes, seems like something right out of science fiction.</p><p>For Instance, check out Google’s Move Mirror, an in-browser application that estimates the user’s pose in real time and then displays a movie still with the actor holding the same pose.</p><p>When I glanced over it, however, I got an idea. What if the same methodology could be used to compare the same actions performed by two people? This technology could then be used to teach people over remote view! I got to work immediately and tried to reverse engineer the techniques used by Google.</p><p>I found, to my disappointment, a few Tensorflow.js tutorials and theories on the same and nothing in python. This was understandable as it was an in-browser application and so, I decided to port the code to mighty Python.A few sessions of research showed me that they were using Posenet, a fast yet accurate model, for estimating pose. Then there were a few under-the-hood operations in order to assist the model,which we’ll go into detail in a bit.</p><p>The Objective was simple: I wanted to go one step ahead and compare a whole action such as a punch or a kick with an image and tell me the extend to which it was correct.</p><p>Now let’s take a look at all the steps that were taken</p><ol><li>The Model: As I stated earlier, Google Mirror uses PoseNet, a deep learning model which specifies 17 points on the human body. <a href="https://github.com/rwightman/posenet-python">I found a good python implementation of it here.</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GbdkpKVY3Y3siheX" /></figure><p>The next challenge was defining similarity. When we think about the problem,we see that there are many uncertainties to be addressed: humans can have different heights and body shapes, they might be in different parts in the picture: one person may have been standing close to the camera, another might have been faraway. All these problems have to be solved in order to output a correct result. I decided to take all the steps followed by Google.</p><ol><li>A new Bounding box : From the model output, we get the co-ordinates of the 17 key-points on a person’s body. This information can be used to create a new bounding box which tightly covers the person in the picture.This solves the problem of people appearing in different parts of the picture.</li><li>Normalization of the points: In order to account for the size inconsistencies, we perform L2 normalization of the points in order to transform it into a unit vector. The defining property of an L2 normalized vector is that the sum of the squares will be equal to 1.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1KlPNDh4b2_wXUHy" /><figcaption>Transforming into a unit vector</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2-tIRosw2QpbjO6Q" /></figure><p>Now that we have standardized the pose vectors, it is time to choose a similarity measure. I chose cosine similarity for this particular instance, mainly because we are working with vectors.</p><h3>Cosine Similarity</h3><p>Cosine similarity of two vectors are defined as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*LZjLZkHIJJkk3DDpd75ysw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/0*0mJ_Qwd2o5bqNggr" /></figure><p>The 17 key-points are converted into a vector and plotted in high dimensional space. This vector plotting is compared to another vector plot from our benchmark image.</p><p>The direction of vectors here are an indication of the similarity of the poses. Vectors going in similar directions are similar, while those going at fairly different or opposite directions are different.</p><p>Now, given our earlier video of a man doing a punch, I simply estimated the pose for each frame and standardized the vectors and stored them in an array.I already had a pickle file saved which contained the normalized vector for the pose of a perfect punch. Now, all I had to do was compute the cosine similarity between both at each frame and take the average of all the scores.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FuV3jNS6Jhk4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DuV3jNS6Jhk4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FuV3jNS6Jhk4%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/c7043ee5412e8022f1ab5a1f6b2ed90e/href">https://medium.com/media/c7043ee5412e8022f1ab5a1f6b2ed90e/href</a></iframe><p>We can see that there is a peak where the person performing the action mimics the pose of the person in the picture. It seems I succeeded to an extent.</p><p>But the drawbacks are evident:</p><ol><li>The algorithm does not take into account the time taken to perform the activity. This is a serious drawback if this were to be used in any training software such as martial arts etc.</li><li>There is no scope of attaining a 100 percent score: Since the average is taken against one picture, there can never be a 100 percent score even if the person performed the action correctly.</li></ol><p>Due to these factors, I had to conclude that this method could only be used for qualitative analysis and maybe action recognition but not as a scoring module. The temporal information had to be taken into account somehow.</p><p>Since I did not have much data to start with, any sort of deep learning methods were taken off the table right off the bat. So I began thinking of alternative methods and other vision based approaches. A quick study into this sort of problem led me to the conclusion that some sort of optical flow based methods had to be employed in order to use the temporal information in a useful manner.</p><p>From here, the method seemed very straightforward. Instead of comparing with just one image of an action, I would now be comparing the video of an action performed by a person with the video of the action performed in a correct manner - a lookup based approach, to be blunt.</p><p>But the problems seemed to be in abundance here too:</p><ol><li>The frames had no particular order: I simply couldn’t extrapolate the earlier method since I could not know beforehand which frames from both videos had to be compared with each other.</li><li>The sequences could be of different lengths: Another problem which haunted me was that, even if I could somehow figure out which frames to compare with each other, the two videos need not be of the same duration.</li></ol><p>These problems, among others, showed me that I needed to come up with an alternative method, which would take in as input the video of a person performing an action, the name of the action and a video in the lookup in which a person is performing the same action in a correct manner, and then should produce a score.</p><p>If we think carefully, this data exhibits certain describing characteristics:</p><ol><li>There are 17 points which are tracked by their co-ordinates</li><li>The value of the co-ordinates change with time</li></ol><p>These properties tell me that I can actually treat this data as a time-series and doing so, unlocks various other methods for comparison.</p><h3>Dynamic Time Warping</h3><p>Even though it sounds like a sci-fi method of time travel, it really isn’t. It is just a method used in comparing sequences and graphs of different lengths. It matches the different troughs and crests in a graph using one to many matching and such, resulting in synced up frames on its own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*tHsAwjaA9dOBPEBH.jpeg" /></figure><p>This method seemed ideal for my use case, as I had similar graphs for each of the 17 key-points as the action was performed. I could then use DTW to compare these graphs and get 17 scores for each of the 17 key-points. An average of these 17 scores could be then taken as the total score.</p><p>I used a package called <a href="https://pypi.org/project/dtaidistance/">dtaidistance,</a> which was used to compute DTW scores between two sequences when given in the form of Numpy arrays.</p><p>In this way, I was able to use the temporal information gained from pose estimation at each frame in order to compare the actions performed by two people.</p><p>For example, in the case of punch, I constructed a lookup table which contained the sequence of each of the 17 keypoints for the action ‘punch’ in 3 views -front, left and right. It was stored in a dict in the following format:</p><pre>{&#39;punch - side&#39;: array([[[5.15185672e+01, 8.93372620......)<br> &#39;punch - front&#39;: array([[[5.15185672e+01, 8.93372620......)<br>}</pre><p>Then, the video of a man performing the punch, which we used earlier, was given along with name of the action and the orientation. These are a few visualizations for the scores obtained using this method. The points which are tracked have a green path following them:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fpnn7DY_jtnw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dpnn7DY_jtnw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fpnn7DY_jtnw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/97f615689fa7118d6f002a4a30782559/href">https://medium.com/media/97f615689fa7118d6f002a4a30782559/href</a></iframe><blockquote><em>For the code and instructions on how to run, Please Visit : </em><a href="https://github.com/kr1210/Human-Pose-Compare">https://github.com/kr1210/Human-Pose-Compare</a></blockquote><p>Improvements:</p><ol><li>Automation of recognition of action performed and orientation: In the code that I have showcased, the action and orientation have to be specified by the user. Instead, the first method I explained can be used to recognize the action performed and the orientation by using another lookup.</li><li>Using confidence scores: I have not used any confidence scores returned by Posenet. These can be used to make scoring much more efficient.</li><li>Specifying points for consideration: According to the action to be performed, specific points can be used to increase accuracy. For eg: In punching, the movement of the torso is more important than the movement of the legs.</li><li>Providing feedback: A feedback can be given to the user as to which body part’s movement and position needs to be corrected in order to boost the scores.</li></ol><p>References :</p><ol><li><a href="https://medium.com/tensorflow/move-mirror-an-ai-experiment-with-pose-estimation-in-the-browser-using-tensorflow-js-2f7b769f9b23">https://medium.com/tensorflow/move-mirror-an-ai-experiment-with-pose-estimation-in-the-browser-using-tensorflow-js-2f7b769f9b23</a></li><li><a href="https://towardsdatascience.com/dynamic-time-warping-3933f25fcdd">https://towardsdatascience.com/dynamic-time-warping-3933f25fcdd</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2bdf0ddecba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/human-pose-comparison-and-action-scoring-using-deep-learning-opencv-python-c2bdf0ddecba">Human Pose Comparison and Action Scoring using Deep Learning,OpenCV &amp; Python</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[Real-Time Image Classification On Android Using Flutter, TFlite]]></title>
            <link>https://medium.com/innovation-incubator/real-time-image-classification-on-android-using-flutter-tflite-2674f03caf0f?source=rss-dd27d450bcb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2674f03caf0f</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Krishna Raj R]]></dc:creator>
            <pubDate>Wed, 18 Sep 2019 20:09:24 GMT</pubDate>
            <atom:updated>2019-09-18T20:09:24.766Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZY6KG7c_YCw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZY6KG7c_YCw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZY6KG7c_YCw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa1105f1d4bd1350efb2071965a1697c/href">https://medium.com/media/aa1105f1d4bd1350efb2071965a1697c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nESXMWJAZ_xalDzm.jpeg" /></figure><p><strong><em>If you’d like to jump straight to the code, please visit my Github-Repo : </em></strong><a href="https://github.com/kr1210/Flutter-Real-Time-Image-Classification">https://github.com/kr1210/Flutter-Real-Time-Image-Classification</a></p><p>Making a smartphone app from scratch might seem a daunting task to most newbies and maybe even seasoned programmers.Enter Flutter.</p><p>As One of the promising, albeit untested technologies unveiled by Google for android app development, Flutter aims to make smartphone app development easier than ever. It is even rumored that flutter will soon be the go-to name in mobile app development.Creating UIs is a breeze and the developer friendly coding style makes the icing on the cake.</p><p>Working as an AI engineer ,one of the most common problems I and my team mates encounter is the matter of deployment of our models. How do you prototype your deep learning models in a quick,yet elegant way? The answer is carried around in our very pockets. Smartphones. That’s right. That overpowered piece of hardware on which you are possibly reading this article at this very moment is any developer’s dream come true. Combine the ubiquitous nature of smartphones and the versatile technology that is machine learning and you’re looking at a vast potential of innovation right there.<br>Now, I work at a place where people are often expected to roll up their sleeves and get the job done rather than wait for help. So, at one such instance, the matter of deployment loomed ahead of me and I had to choose between the daunting world of native android development and an exciting, yet uncharted new tech called Flutter. I chose the latter. At the time of writing this article, not every aspect of flutter is super stable, but it is certain that all of those problems shall disappear. In this article, I shall describe the important aspects of integrating deep learning models into an android app made with flutter. While I am no experienced android nor flutter developer, I was able to get a base version working in about a week. That’s how easy it is.</p><p>I assume the reader has a base understanding of layouts in flutter and a basic understanding of the programming language used,which is Dart. If you are unfamiliar with what I just mentioned a few beginner posts will get you on your way. While the methods and code mentioned in this project is not exactly what I would call optimized, it can serve as a starting point or a base for your own projects. So let’s dive in to it.</p><p>We will be using the <a href="https://pub.dev/packages/tflite">TFlite plugin</a> to integrate our neural network with the app. In order to use it, We first need to specify it as a dependency and also specify our model file’s presence in the assets folder. There are three steps to be followed for this:</p><ol><li>Place the model file(in .tflite format) in the assets folder along with the labels.txt file which contains the name of the classes used.</li><li>Specify the file’s presence in the assets folder so that the compiler knows to use it and also specify the usage of the plugin.</li><li>In android/app/build.gradle, add the following setting in android block.</li></ol><pre>aaptOptions {<br>        noCompress &#39;tflite&#39;<br>        noCompress &#39;lite&#39;<br>    }</pre><p>So let’s open up our pubspec.yaml file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oR_qq-H4N-J5bUuy.png" /><figcaption>pubspec.yaml</figcaption></figure><p>Here, you can see that I’ve specified the tflite: 1.0.1 as a dev_dependency. Now it is ready to be imported and used with our app. It’s that simple (Not quite). When flutter runs the packages get command, the files required to run this plugin will be downloaded without any further action from our side.<br>Now let’s open up our home.dart file, which is the page which has the ignite button labeled “start classification”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*N8hOYUjcC0N4BT9I.png" /><figcaption>Importing the tflite plugin</figcaption></figure><p>As you can see, I’ve imported the tfliteplugin on line 3 in the <em>home.dart </em>page, similar to how I would import library files in other standard programming languages.<br>The Tflite plugin comes bundled with a function called loadModel() which is used to specify the name of the model to be loaded and the labels.txt file, which contains the name of the classes used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*m_DgJMns31u-xd_E.png" /><figcaption>Loading the model</figcaption></figure><p>For representation purposes, I’ve wrapped up this process in a function of my own, which is also called loadmodel().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*9tdHWbqbiNGJtdF7.png" /><figcaption>runModelOnFrame() function</figcaption></figure><p>Now let’s move on to the <em>camera.dart</em> file, where the actual inference takes place. Here, We use the function runModelOnFrame(), which takes the frame from the camera stream and takes it as input to the model. This function requires a list of arguments such as the frame, its height, width, the number of results to be displayed and so on.<br>The output is received in the format specified by the plugin’s ReadMe file found on Flutter Pub.</p><pre>{<br>  index: 0,<br>  label: &quot;person&quot;,<br>  confidence: 0.629<br>}</pre><p>This output is received by the <em>recognitions</em> variable.<br>The output received from the model is imposed on the <em>ImageStream</em> from the camera on the <em>render.dart</em> page. In order to do this, the results obtained from the model is passed into the <em>render.dart</em> page as a list named, well, results. These results are then displayed along with the confidence percentage on the screen.</p><p>All the code and project files are available in my GitHub : <a href="https://github.com/kr1210/Flutter-Real-Time-Image-Classification">https://github.com/kr1210/Flutter-Real-Time-Image-Classification</a></p><blockquote>Last but not least, I’d like to thank my lead and mentor, <a href="https://www.linkedin.com/in/matrixb/">Bhartendu Takur</a> for recommending Flutter as a means of deployment to me.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2674f03caf0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innovation-incubator/real-time-image-classification-on-android-using-flutter-tflite-2674f03caf0f">Real-Time Image Classification On Android Using Flutter, TFlite</a> was originally published in <a href="https://medium.com/innovation-incubator">Innovation Incubator</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>