<?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 Deepak Puttarangaswamy on Medium]]></title>
        <description><![CDATA[Stories by Deepak Puttarangaswamy on Medium]]></description>
        <link>https://medium.com/@pdster?source=rss-200e09933d4c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nEnVhwyGmkjCGpBLHZVR2A.png</url>
            <title>Stories by Deepak Puttarangaswamy on Medium</title>
            <link>https://medium.com/@pdster?source=rss-200e09933d4c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:21:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pdster/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[Image classification with client-side neural network using TensorFlow.js]]></title>
            <link>https://medium.com/agara-labs/image-classification-with-the-client-side-neural-network-using-tensorflow-js-8f94d3dc7c5c?source=rss-200e09933d4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f94d3dc7c5c</guid>
            <category><![CDATA[mobilenet]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tensorflowjs]]></category>
            <category><![CDATA[imagenet]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Deepak Puttarangaswamy]]></dc:creator>
            <pubDate>Tue, 09 Apr 2019 15:47:26 GMT</pubDate>
            <atom:updated>2019-04-20T09:20:58.030Z</atom:updated>
            <content:encoded><![CDATA[<h3>Image Classification with client-side neural network using TensorFlow.js</h3><p>With client-side neural network, we can train and build models on the browser which will use user data locally. This provides high availability and easy interaction for the end user.</p><p>In this article, you will be reading about how to setup Keras’ pre-trained MobileNet model trained over ImageNet to classify images on client-side using TensorFlow.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ga8durZd_JnV80X-1jMrpA.png" /><figcaption>Final application</figcaption></figure><h3>What is TensorFlow.js?</h3><p>TensorFlow.js is a library for developing and training ML models in JavaScript, and deploying in the browser or on Node.js.</p><p>TensorFlow.js provides better API and documentation than some of the other libraries to build and train complex models from scratch.</p><p>Some of the other comparable libraries: <br>1. ml5.js: It aims to make machine learning approachable for a broad audience of artists, creative coders, and students. The library provides access to machine learning algorithms and models in the browser, building on top of TensorFlow.js with no other external dependencies. You can get started with Machine Learning but not worry about any low-level details like Tensors or Optimizers.</p><p>2. <a href="https://github.com/BrainJS/brain.js">BrainJS</a>: It is a library of Neural Networks written in JavaScript. This is a continuation of the <a href="https://github.com/harthur/brain">harthur/brain</a> repository (which is not maintained anymore)</p><p>Click <a href="https://www.tensorflow.org/js">here</a> to know more about TensorFlow.js.</p><h3><strong>Why client-side neural network?</strong></h3><p>As web technology advances, it opens door to many platforms for unique web experiences and applications.</p><p><em>Keep user data local — </em>With the client-side neural network, we can have small sized models run locally. The user data stays at the client-side and does not have to be sent across the internet to run through a model and get responses.</p><p><em>No dependencies</em> — Highly usable and accessible to the end user. Anyone can use it, this requires no additional installations or prerequisites. It can simply be accessed from the web browser via the URL address where frontend application is hosted.</p><p><em>Interactive and easy to use</em> — In general, web-based applications are highly interactive and easy to use. It is easy for users to get started and engage with the application.</p><p><em>The Caveats</em> — Having models run in the browser, it is best suited for tasks like transfer learning, fine-tuning pre-trained models and for inference.</p><blockquote>Transfer learning is the improvement of learning in a new task through the transfer of knowledge from a related task that has already been learned.<br><a href="https://storage.googleapis.com/tfjs-examples/webcam-transfer-learning/dist/index.html">Here</a> is a demo of transfer learning, you will use webcam as a controller to play pac-man using images trained in your browser. Here, a pre-trained image classifying model is further trained on images in the browser to define the directions and controls of a joystick.</blockquote><p>Loading and running massive sized models into our web application might cause some performance issues. TensorFlow suggests using a model that is of 30 MB in size or less in the browser.</p><p>Check out some cool demos from TensorFlow.js <a href="https://www.tensorflow.org/js/demos/">here</a>.</p><h3><strong>Let&#39;s get started</strong></h3><p>We will be building a web application to choose an image and submit it to our model, the app will give us back the top five highest predictions for the image from the imageNet classes.</p><p>I have created the frontend application for this example with <a href="https://reactjs.org/">React</a>, <a href="https://redux.js.org/">Redux</a>, and <a href="https://getbootstrap.com/">Bootstrap</a>. Feel free to pick your choice.</p><p><a href="https://github.com/deepakpster/imageClassification">Here</a> is the GitHub repo of the codebase.</p><p>Let&#39;s take a <a href="https://keras.io/applications/#mobilenet">MobileNet</a> model that is already built and trained with Keras and make use of it in the browser with TensorFlow.js.</p><p>First, we need to install the TensorFlow.js model converter tool. From a Python environment where Keras is already installed, run pip install tensorflowjs from the terminal.</p><p>Next, open Jupyter notebook. Run jupyter notebook from the terminal.</p><p>We are in the Jupyter notebook now. Lets import Keras and TensorFlow.js library. We will create a MobileNet model and then convert the model and save it in a directory. Below is the code from the notebook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*czGiBt3EYXs3-zPFOgYBnQ.png" /></figure><p>If everything goes well, then you should be able to see the converted model files in the mentioned output directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*eNAWNF6mTPvgunVILc0y8A.png" /></figure><p><strong><em>Loading the model</em></strong></p><p>Now, let&#39;s load the model as and when our frontend application loads on the browser. I will be saving the model in browser’s indexed DB, this way we can load the model only once and cache it for the next subsequent load/refresh of application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*-ssNlipfmyiLDu30rVUf3g.png" /></figure><p>I am using Web server for Chrome to host the model on my localhost with port number 8887.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*1DUALlDj3-_Ca-bENQAorw.png" /></figure><p><strong><em>Select an image</em></strong></p><p>Let&#39;s provide an Input element to browse and select an image from the local disk. On selecting the image, we will create the object URL for the selected image and render the image as a preview. We then, make a call to predictImage action by passing img element as an argument.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*-QF_1gzG_IVclKulJV2fcw.png" /><figcaption>Input element to choose an image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*Z0rjqPaCITxSRDFtUwChpg.png" /><figcaption>Image element to preview the selected image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*ZDfzZcydVRj3OQIcTw2J5Q.png" /><figcaption>On choosing a photo, call model to predict the label for the selected image</figcaption></figure><p><strong><em>Pre-processing the image</em></strong></p><p>Alright, now when we choose an input image from our application, we need to transform the selected image to a rank-4 <a href="https://www.tensorflow.org/js/guide/tensors_operations">tensor</a> object of floats with height and width dimension 224 x 224. It&#39;s expected, as our mobilenet model is pre-trained with ImageNet images with dimension 224 x 224.</p><p>To do this, we create a tensor object from the image by calling the TensorFlow.js function <a href="https://js.tensorflow.org/api/0.15.3/#fromPixels">tf.fromPixels()</a> and passing our image element to it. We then resize the image to 224 x 224, cast the tensor’s type to float32 and expand the tensor’s dimensions to be of rank-4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*lemxkab0RB8THg-kVlCHUQ.png" /><figcaption>Transforming an image to a tensor object</figcaption></figure><p>MobileNet wants the image data to be further pre-processed in a specific way. In other libraries like, Keras, pre-processing functions for specific models are included in the API. Although in TensorFlow.js does not have these pre-processing function included, we will build a pre-processing function as follows:</p><p>The images that MobileNet was originally trained on were preprocessed so that the RGB values were scaled down from a scale of 0 to 255 to a scale of -1 to 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*d13MOP-G4G4Tdck3GGFuCw.png" /></figure><p>We do this by first creating a scalar value of 127.5 which is exactly one half of 255. We then subtract this scalar from the original tensor and divide that result by the scalar. This way, we will have all the values in tensor on a scale of -1 to 1.</p><blockquote>([0, 255] - 127.5) / 127.5 = [-127.5, 127.5] / 127.5 = [-1, 1]<br>check out <a href="https://www.tensorflow.org/xla/broadcasting">Broadcasting</a> to understand this better.</blockquote><p><strong><em>Getting a prediction</em></strong></p><p>When the user selects an image, we make a call to action method to transform the image into a tensor object. Now, we can pass the transformed tensor to the model to get a prediction by calling predict() on the model and passing tensor to it. predict() returns a tensor of the output predictions for the given input. We then call data() on the predictions tensor, which asynchronously loads the values from the tensor and returns a Promise .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*UrTyBUttENOSPXTT35vLvQ.png" /></figure><p>So, predictions array is going to be made of 1000 elements, each of which corresponds to the prediction probability of individual ImageNet class. Each index in the array maps to the specific ImageNet class.</p><p>We will get the top five highest predictions out from the predictions and store it in top5 variable. We will iterate through the predictions array and create object item with prediction probability and imageNet className properties. We will then sort the list of objects in descending order of prediction probability and obtain the first five from the sorted list using the slice() function.</p><p>We will then store the prediction state and display it on the UI as a list. We will highlight the predictions with different background colors based on the probability score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*qYHDiVfcSRshVloNd3ZHVg.png" /></figure><h3><strong>Demo</strong></h3><p>We’ve completed building our application. You will be able to see the prediction as you select an image. Notice, how fast our MobileNet is generating these results.</p><p>The trained MobileNet model used in this example is about 17 MB in size. MobileNets have a reduced number of parameters — 4.2 million, faster in performance and are useful for mobile applications. They are small and low latency convolutional network.</p><p>Even though MobileNet has reduced size, reduced parameters and performs faster, it is less accurate than other state-of-the-art networks as discussed in <a href="https://arxiv.org/pdf/1704.04861.pdf">this</a> paper. But there is only a slight reduction in accuracy when compared to other networks.</p><p>So hopefully, this article has illustrated the practicality of using MobileNet to classify images on the client side using TensorFlow.js. Let me know in the comments if you have something to share.</p><h3>Some results</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5pCzsGFl_AmJovilnxllSQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*58ynqcKTCVDT52ysLsmhFg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGFe_94wZfpET4hk92uTCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPJV8d7GFBd5K-StAVKLqQ.png" /></figure><p><em>References and useful links:<br></em>TensorFlow.js official site <a href="https://js.tensorflow.org/api/latest/">https://js.tensorflow.org/</a><br>Keras <a href="https://keras.io/">https://keras.io/</a><br><a href="https://gogul09.github.io/software/mobile-net-tensorflow-js">https://gogul09.github.io/software/mobile-net-tensorflow-js</a><br>Deeplizard <a href="http://deeplizard.com/learn/playlist/PLZbbT5o_s2xr83l8w44N_g3pygvajLrJ-">http://deeplizard.com/learn/playlist/PLZbbT5o_s2xr83l8w44N_g3pygvajLrJ-</a><br>Standford’s CS231n: Convolutional Neural Networks for Visual Recognition <a href="http://cs231n.stanford.edu/">http://cs231n.stanford.edu/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f94d3dc7c5c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/agara-labs/image-classification-with-the-client-side-neural-network-using-tensorflow-js-8f94d3dc7c5c">Image classification with client-side neural network using TensorFlow.js</a> was originally published in <a href="https://medium.com/agara-labs">Agara</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Web Browsers Work ?]]></title>
            <link>https://medium.com/@pdster/how-web-browsers-work-6385b9374375?source=rss-200e09933d4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6385b9374375</guid>
            <category><![CDATA[ui-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Deepak Puttarangaswamy]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 05:12:49 GMT</pubDate>
            <atom:updated>2018-12-11T06:30:59.845Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<h3>How Web Browsers Work ?</h3><p><strong>What is a browser ?</strong></p><p>A web browser also referred as browser is a software application used to access information on world wide web. The main functionality of a browser is to retrieve web resources from the server and display it on the web browser window. The web resource is usually an HTML document, but may also be a PDF, image, audio, videos or some other type of content. The location of the resource is specified by using a URI (Uniform Resource Identifier).</p><p>A browser contains a well structured components which performs a series of task to display web resources on the browser window.</p><p><strong>The browser’s high level structure</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aDQUwsijfEQa6vkhY91N3w.png" /><figcaption>High level structure of a browser</figcaption></figure><p>The main components of a web browser are:</p><ol><li><strong>User Interface (UI): </strong>It is the layout of elements available for user to interact in the browser window except for the web page itself. The elements for interaction includes address bar, refresh, back, forward, bookmark options and etc.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CF-f8LS0SHQ0AoPondx5_A.png" /><figcaption>User Interface of Chrome Browser</figcaption></figure><p><strong>2. Browser Engine: </strong>It is the bridge between the UI and the Rendering Engine. Based on inputs from the UI, it queries HTML document and other resources of a web page into an interactive visual representation on the browser window by manipulating the rendering engine.</p><p><strong>3. Rendering Engine: </strong>It is the component responsible for displaying the requested content on the browser window. For example, if an HTML page is requested, then it is responsible for parsing HTML document and the CSS and display the parsed and formatted content on the screen.</p><p>By default, it can display HTML , XML documents and images. It can display other formats of data by using browser plugins and extensions.</p><p>There are different rendering engines for different browsers. For example, Internet Explorer uses Gecko, Safari uses WebKit, Chrome and Opera (version 15 onwards) uses Blink, an extended implementation of WebKit.</p><p>WebKit is an open source rendering engine which started as an engine for the Linux platform and was modified by Apple to support Mac and Windows. See <a href="http://webkit.org/">webkit.org</a> for more details.</p><blockquote>It is important to note that browsers such as Chrome run multiple instances of the rendering engine: one for each tab. Each tab runs in a separate process.</blockquote><p><strong>The Main Flow</strong></p><p>The rendering engine gets the content of the requested document from the Networking component in chunks of 8kb.</p><p>Once the chunks are received, following will be the basic flow of rendering engine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjO-UTshQRnJcSSuRTPm1w.png" /><figcaption>The main flow</figcaption></figure><p>So here, in this flow, we can see how a HTML document that was fetched over the network is parsed and rendered into a visually appealing view on the screen. The flow contains primarily four stages:</p><p><strong>1.Parsing HTML to construct the DOM tree: </strong>The rendering engine will start parsing the HTML document and convert elements to Document Object Models (DOM) nodes in a tree called the “content tree”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EFDTBOragDmxK0Cmfd6Ctg.png" /><figcaption>HTML Document</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqYyWkPdrgjvH28ANZJdig.png" /><figcaption>Content Tree</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*5sWr48VZhDBmGpxl_HLehQ.png" /><figcaption>Collection of HTML elements</figcaption></figure><p><strong>2. Render tree construction: </strong>The engine will parse the style data, both in external CSS files and in style elements. Styling information together with visual instructions in the HTML will be used to create another tree called the “render tree”.<br>The render tree contains rectangles with visual attributes like colour and dimensions. The rectangles are in the right order to be displayed on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xes6yQ2bteVtMuefEF6Isg.png" /><figcaption>Render Tree</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tVP6dX386ak4Wb5NYmBzGw.png" /><figcaption>Inline Style for body element</figcaption></figure><p><strong>3. Layout of the render tree: </strong>After the construction of the render tree it goes through a “layout” process. The output of the layout process is a “box model,” which precisely captures the exact position and size of each element within the viewport: all of the relative measurements are converted to absolute pixels on the screen.</p><p>In the below screenshot, you can see the “box model” (margin, border, padding, width and height) information computed for body element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G2NigKo1hRy7aKEiEui64A.png" /><figcaption>Computed style and box model details</figcaption></figure><p><strong>4. Painting the render tree: </strong>The render tree will be traversed and each node will be painted using the UI backend layer. This process is also referred to as “rasterising”. <br>This is the stage, where the computed layout information for each node in the render tree is converted to actual pixels on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*81u-icbRGNSTJTsKGKgPYw.png" /><figcaption>Painted View</figcaption></figure><p>It’s important to understand that this is a gradual process. For better user experience, the rendering engine will try to display contents on the screen as soon as possible. It will not wait until all HTML is parsed before starting to build and layout the render tree. Parts of the content will be parsed and displayed, while the process continues with the rest of the contents that keeps coming from the network.</p><p><strong>Main Flow Examples</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Ycv7K7swz5tBt7Ag168AA.png" /><figcaption>WebKit Main Flow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqWz54Ztg-GvIzscYyZUFQ.png" /><figcaption>Mozilla’s Gecko Rendering Engine Main Flow</figcaption></figure><blockquote>Repaint occurs when changes are made to the element’s appearance but do not affect its layout. For example, like changing the background colour, opacity, visibility of an element.</blockquote><blockquote>Reflow occurs when changes are made to the element that changes a part of the layout or the entire page. Reflow causes the subsequent reflow of all the child and parent elements as well as any elements following it in the Render/Frame tree.</blockquote><p><strong>4. Networking: </strong>It is the component that handles all kind of network communication on the browser. It uses a set of common networking protocols like HTTP, HTTPS, FTP and etc while fetching the requested resources through URLs.</p><p><strong>5. UI Backend: </strong>It is used to draw basic widgets like combobox, alert, pop-up windows, frames etc. This backend exposes a generic interface that is not platform specific. Underneath it uses operating system user interface methods.</p><p><strong>6. JavaScript Interpreter: </strong>It is a component used to parse and execute the JavaScript code embedded in a web page.</p><p>There are different types of JS engines used by different browsers to analyse, parse and execute, by generating the most optimised JS code in the shortest time. A few are,<br>- Chrome uses V8 Engine<br>- Mozilla uses SpiderMonkey<br>- IE and Edge uses Chakra<br>- Safari uses JavaScriptCore</p><p><strong>7. Data Storage: </strong>This is a persistence layer. The browser may need to save all sorts of data locally, such as cookies. Browsers also support storage mechanisms such as localStorage, IndexedDB, WebSQL and FileSystem.</p><p>Please feel free to leave any feedbacks or questions in the comments.</p><p>References: <a href="https://www.html5rocks.com/en/tutorials/internals/howbrowserswork/">https://www.html5rocks.com/en/tutorials/internals/howbrowserswork/</a><br><a href="http://www.stubbornella.org/content/2009/03/27/reflows-repaints-css-performance-making-your-javascript-slow/">http://www.stubbornella.org/content/2009/03/27/reflows-repaints-css-performance-making-your-javascript-slow/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6385b9374375" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>