<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kartik Nanda, Engineering AI</title>
	<atom:link href="https://www.kartiknanda.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kartiknanda.com/</link>
	<description>AI algorithms, how-to guides, thoughts</description>
	<lastBuildDate>Thu, 15 Oct 2020 01:19:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.kartiknanda.com/wp-content/uploads/2020/07/cropped-site_icon-2-32x32.jpg</url>
	<title>Kartik Nanda, Engineering AI</title>
	<link>https://www.kartiknanda.com/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Using Docker To Collaborate On Code Development Across Sites</title>
		<link>https://www.kartiknanda.com/using-docker-to-collaborate-on-code-development-across-sites/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-docker-to-collaborate-on-code-development-across-sites</link>
					<comments>https://www.kartiknanda.com/using-docker-to-collaborate-on-code-development-across-sites/#respond</comments>
		
		<dc:creator><![CDATA[Kartik Nanda]]></dc:creator>
		<pubDate>Wed, 14 Oct 2020 19:21:38 +0000</pubDate>
				<category><![CDATA[Highlights]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Containerize]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://www.kartiknanda.com/?p=1264</guid>

					<description><![CDATA[<p>Google “tools to collaborate remotely” and you will get a list of the usual suspects – Trello, Slack, Zoom etc. That is all communication focused, and that’s great, but we are developers. What about the coding environment and the code &#8211; can I use Docker to collaborate with my team-mates on code development? Let me set this up – we&#8230;</p>
<p>The post <a href="https://www.kartiknanda.com/using-docker-to-collaborate-on-code-development-across-sites/">Using Docker To Collaborate On Code Development Across Sites</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Google “tools to collaborate remotely” and you will get a list of the usual suspects – Trello, Slack, Zoom etc. That is all communication focused, and that’s great, but we are developers. What about the coding environment and the code &#8211; can I use Docker to collaborate with my team-mates on code development? </p>



<p class="wp-block-paragraph">Let me set this up – we use Python, all are remote, all use different machines, different OSes. And there is no IT department, so everything is self-maintained. We use GitHub, but that is only the code. We could use Virtual Environment (<a href="https://pypi.org/project/virtualenv/">virtualenv</a> or <a href="https://docs.python.org/3/library/venv.html">venv</a>), but everyone would have to manage it independently on their setup. That can work, but changes to the environment (adding a new python package etc) can become a hassle – where is that IT department when you need it!</p>



<h2 class="wp-block-heading">Code Development using Docker?</h2>



<p class="wp-block-paragraph">On the face of it – yes. For starters it takes the OS, machine related concerns off the table. Docker provides an independent “container” and isolates the code from everything that’s not in the container. Don’t have to worry about hidden dependencies. But we still have some questions:</p>



<ul class="wp-block-list"><li>Docker seems like a solution for project release or deployment. Is it convenient to work with during development? Can multiple collaborators work on code development using Docker? How would that work? What does the setup look like?</li><li>How often do I have to build the Docker image – every time I want to run code, do I need to build a new docker image? (That would be a pain)</li><li>How heavy is the image – how much extra memory?</li><li>Execution time – is executing code from within the Docker container slower?</li><li>Is Docker easy to setup on any machine? How much extra stuff, effort is it?</li></ul>



<p class="wp-block-paragraph">We are going to try to answer these questions. First, what is Docker?</p>



<h2 class="wp-block-heading">What is Docker?</h2>



<p class="wp-block-paragraph">Docker is the “industry standard” approach for implementing containers.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Containers encapsulate an application as a single executable package of software that bundles application code together with all of the related configuration files, libraries, and dependencies required for it to run.</p><cite>&#8211; ibm.com/cloud/learn/containerization (<a href="https://www.ibm.com/cloud/learn/containerization">link</a>)</cite></blockquote>



<p class="wp-block-paragraph">Here is a great <a href="https://youtu.be/8fi7uSYlOdc" target="_blank" rel="noreferrer noopener">video</a> (by Liz Rice, GOTO 2018) that explains the concept and walks through the basics of building a container (like Docker) from scratch in Go. I like to look under the hood first!</p>



<p class="wp-block-paragraph">The above video provides a great explanation (please do watch the video). Follow that up with <a href="https://youtu.be/iqqDU2crIEQ" target="_blank" rel="noreferrer noopener">this one</a> from the Docker site that does a walk through on how to use Docker. Both show the deployment scenario – a web service released as a containerized solution. That does not address our needs.</p>



<p class="wp-block-paragraph">There is <a href="https://www.docker.com/blog/tag/python-env-series/" target="_blank" rel="noreferrer noopener">this</a> series of blog posts that does address python code development using Docker. I am going to follow this and set up a containerized python development environment. Let’s get going.</p>



<h2 class="wp-block-heading">Installing Docker</h2>



<ul class="wp-block-list"><li>The first step is to create a <a href="https://hub.docker.com/" target="_blank" rel="noreferrer noopener">Docker hub</a> account &#8211; required if we want to save and share Docker images. I will be creating Docker images on a Windows machine (or Linux running on Windows), then linking them and sharing through the hub – more on this later though.</li><li>Install Docker on the desktop (Windows 10 pro, ver. 2004). Here is the link to the relevant <a href="https://docs.docker.com/docker-for-windows/install/" target="_blank" rel="noreferrer noopener">Docker documentation</a>. (WSL has replaced Hyper-V, so, a) ignore the instruction about Hyper-V; and, b) here is a <a href="https://docs.docker.com/docker-for-windows/wsl/" target="_blank" rel="noreferrer noopener">page</a> that provides more details about Docker and WSL.) &nbsp;</li><li>Execute the downloaded file, follow the prompts. Launch Docker and follow the instructions – you will download from a git repo, build a docker image, and finally run the image. This launches the docker tutorial in a container.</li><li>The Docker window should look like (Docker Desktop on a Windows machine)</li></ul>



<div class="wp-block-image is-style-default"><figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="624" height="111" src="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image1.jpg" alt="Docker Desktop Application window" class="wp-image-1265" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image1.jpg 624w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image1-300x53.jpg 300w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image1-370x66.jpg 370w" sizes="(max-width: 624px) 100vw, 624px" /></figure></div>



<ul class="wp-block-list"><li>Hover over the docker-tutorial and click the browser button. This pulls up a docker tutorial.</li></ul>



<h2 class="wp-block-heading">Testing the Installation</h2>



<p class="wp-block-paragraph">One option is to follow through the tutorial above (and that’s a good option). A second option, especially if you want to quickly check the installation, is:</p>



<ul class="wp-block-list"><li>Open a terminal/console window</li><li>Test the installation by running the Hello-World docker image (<a href="https://docs.docker.com/get-started/">source</a>)</li></ul>



<div class="wp-block-image is-style-default"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="281" src="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image2-1024x281.jpg" alt="Testing docker installation" class="wp-image-1266" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image2-1024x281.jpg 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image2-300x82.jpg 300w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image2-768x211.jpg 768w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image2-370x102.jpg 370w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image2-760x209.jpg 760w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image2.jpg 1180w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure></div>



<ul class="wp-block-list"><li>Try:&nbsp; C:\Users\username&gt; docker ps -all</li></ul>



<p class="wp-block-paragraph">Now that Docker is setup, lets create out first Python image</p>



<h2 class="wp-block-heading">Getting Started with Docker</h2>



<p class="wp-block-paragraph">Before diving in, lets briefly look at what a Docker Image and a Container actually is. These are the key building blocks and understanding them is a must if we want to be effective in our use of Docker. A Docker Image encapsulates an application and the related configuration files, libraries, and dependencies required for it to run. To illustrate, I will create a python app image that encapsulates Python3.8 (or another version), the python package Numpy, and the application code. A Dockerfile captures these various components, which create an image. To run the application, the image is executed, as a container. A container thus is an instantiation of the image. Multiple containers can have the same image. In general, they are all independent of each other, but dependencies can be created.</p>



<p class="wp-block-paragraph">In the example above, I downloaded the “hello-world” image (created by someone else) and ran it as a container (docker run hello-world). What did docker do? Docker downloaded the image, created a container and executed the application that was specified in the image, within the container.</p>



<p class="wp-block-paragraph">Some common Docker commands:</p>



<pre class="wp-block-code"><code>docker --help  -> a big list of all the commands you can use
docker build  -> to build an image from the Dockerfile
docker build --help  -> help on the create command. use with any command
docker run  -> create container from image, run the application specified in the image
docker create  -> creates a container from image
docker start/stop  -> to start/stop a container
docker ps  -> see what is running (containers)
docker rm -> to delete container
docker rmi  -> to delete an image
docker images  -> to see all the images</code></pre>



<p class="wp-block-paragraph">Check <a href="https://www.youtube.com/watch?v=iqqDU2crIEQ">here</a> for detailed explanations and examples.</p>



<h2 class="wp-block-heading">Python using Docker</h2>



<h3 class="wp-block-heading">Python Shell in a Container</h3>



<p class="wp-block-paragraph">We saw above how to execute a docker image as a container. Let’s now create a docker image. As a first step, I want to run python in a container. A textfile (called Dockerfile by default) defines the image. The Dockerfile to run python in a container looks like (for the code head on over to the <a href="https://github.com/kartiknan/docker_testing">github repo</a>):</p>



<pre class="wp-block-code"><code># This is a Dockerfile to build and run a python shell in a container
# set base image (host OS)
FROM python:3.8
# set the working directory in the container
WORKDIR /code
# command to run on container start
CMD &#91; "python"]</code></pre>



<p class="wp-block-paragraph">The first line of code above defines the base docker image, in this case Python3.8. The next line sets the working directory within the container. Finally, the last line tells docker what command to execute when the container starts. </p>



<p class="wp-block-paragraph">Now lets build the image from the Dockerfile we created above, using the docker build command:</p>



<pre class="wp-block-code"><code>C:\Users\kar16\Desktop\Docker_testing> docker build -t python_basic:v0 .</code></pre>



<p class="wp-block-paragraph">I have given the image a name and a tag by using the <em>-t name:tag</em> above. Docker by default looks for the Dockerfile in the current directory so I did not have to specify it. After creating it, you can check the image created by using docker images command.</p>



<p class="wp-block-paragraph">Once the image is created, I can run it &#8211; which creates a container, and executes the specified command (&#8220;python&#8221;) in the container. </p>



<div class="wp-block-image is-style-default"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="310" src="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image3-1024x310.jpg" alt="Setting up Docker for code development" class="wp-image-1269" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image3-1024x310.jpg 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image3-300x91.jpg 300w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image3-768x233.jpg 768w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image3-370x112.jpg 370w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image3-760x230.jpg 760w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image3.jpg 1135w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure></div>



<p class="wp-block-paragraph">The command (see in the figure above) is <em>docker run &lt;image_name&gt;:&lt;tag&gt;</em> . I have used the <em>-it</em> option which specifies run interactively and allocate a tty (use docker run &#8211;help for details).</p>



<h3 class="wp-block-heading">Python script in a Container</h3>



<p class="wp-block-paragraph">In the previous section, we created a container running python3.8 in isolation from any packages etc installed on the machine. I can now share this image with anyone and they will run python3.8 irrespective of their machine and their current setup. </p>



<p class="wp-block-paragraph">But this is not really useful &#8211; I need a few more things. One, I need to install relevant packages, and two, our code. To do that modify the Dockerfile so it looks like:</p>



<pre class="wp-block-code"><code># set base image (host OS)
FROM python:3.8

# set the working directory in the container
WORKDIR /code

# copy the dependencies file to the working directory
COPY requirements.txt .

# install dependencies
RUN pip install -r requirements.txt

# copy the content of the local src directory to the working directory
COPY src/ .

# command to run on container start
CMD &#91; "python", "-i", "./test.py"]</code></pre>



<p class="wp-block-paragraph">I am doing a few additional things in this Dockerfile. First, copy the requirements.txt file which specifies the packages needed to run the code. Then install the packages (using pip). Lastly copy over the source code. The command to be executed in the container is also changed so it will execute the specified python script. </p>



<p class="wp-block-paragraph">The application code is trivial and for illustration only (test.py below).</p>



<pre class="wp-block-code"><code># Testing docker setup

import numpy as np
from pathlib import Path

print('the current folder is {}'.format(Path.cwd()))
data = np.arange(1, 25)
print('the average is {}'.format(np.average(data)))
</code></pre>



<p class="wp-block-paragraph">Once again, build the image, as follows, </p>



<pre class="wp-block-code"><code>C:\Users\kar16\Desktop\Docker_testing> docker build -t python_basic:v1 .</code></pre>



<p class="wp-block-paragraph">&#8230; and run the container. The output looks like:</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="219" src="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image4-1024x219.jpg" alt="code development in a Docker container" class="wp-image-1272" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image4-1024x219.jpg 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image4-300x64.jpg 300w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image4-768x164.jpg 768w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image4-370x79.jpg 370w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image4-760x163.jpg 760w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image4.jpg 1272w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure></div>



<p class="wp-block-paragraph">This runs in the container &#8211; notice the current folder is /code. This is also an interactive session, so the python shell and the container does not exit.</p>



<h3 class="wp-block-heading">Mounting a local directory into the Container</h3>



<p class="wp-block-paragraph">Lets say we need to change test.py, our application (code development, then use the docker container as the execution environment). The current containerized development cycle consists of writing/updating code, building the image, running as a container and debugging it. There is one issue with this. Every time the code changes, the image needs to be rebuilt in order to get the Python code updates into the container.</p>



<p class="wp-block-paragraph">We can however apply code changes without having to rebuild the image. We can do this simply by bind-mounting the local source directory to its path in the container. Launch the container, as follows:</p>



<pre class="wp-block-code"><code>docker run -it --mount type=bind,source="$(pwd)"/src,target=/code python_basic:v1</code></pre>



<p class="wp-block-paragraph">The <em>docker run -it python_basic:v1</em> is the same as before. The <em>&#8211;mount type=bind,source=&#8221;$(pwd)&#8221;/src,target=/code</em> mounts a local folder, specified by <em>source=</em>, to the target folder in the container, specified by <em>target=</em></p>



<p class="wp-block-paragraph">For details check out <a href="https://docs.docker.com/storage/bind-mounts/">this docker doc</a>.</p>



<p class="wp-block-paragraph">And that&#8217;s it. Now, whenever the code changes, rerun the container, and it will pick up the new code. </p>



<h2 class="wp-block-heading">Recap</h2>



<p class="wp-block-paragraph">I started this post as I started learning Docker. In the beginning I asked a few questions, and its time to revisit them. But before I do that, a quick recap. </p>



<p class="wp-block-paragraph">My Docker journey so far:</p>



<ul class="wp-block-list"><li>Installed Docker Desktop on my Windows PC, and created a hub.docker account</li><li>Understood the terms &#8211; what is a docker image, a Dockerfile, a container</li><li>Downloaded my first docker image, ran it in a container</li><li>Wrote a Dockerfile (created an image) to start a python shell in a container</li><li>Created another image to run a python app in a container</li><li>Mounted a local directory into a container for continuing code development of the python app, with execution in a Docker container. </li></ul>



<p class="wp-block-paragraph">The code I have used above, including the dockerfiles, is all available in github <a href="https://github.com/kartiknan/docker_testing">here</a>.</p>



<h3 class="wp-block-heading">Q and A</h3>



<p class="wp-block-paragraph">Back to the questions at the top of this post:</p>



<p class="wp-block-paragraph"><em>Is Docker convenient to work with during code development?</em> </p>



<p class="wp-block-paragraph">I believe the answer is yes it is. With the setup as described here, I can make changes to the application code, and rerun it in a container with a single line shell command. Its almost as easy as running it by typing <em>python app.py</em> in the shell.</p>



<p class="wp-block-paragraph"><em>How often do I have to build the Docker image – every time I want to run code, do I need to build a new docker image?</em> </p>



<p class="wp-block-paragraph">No. Map the local source code directory into the container. </p>



<p class="wp-block-paragraph"><em>How heavy is the image – how much extra memory?</em></p>



<p class="wp-block-paragraph">Python images are large. The first basic python3.8 shell image I created in this post &#8211; 882MB. The good news is that we should need to create only one image per project. And the image should not need to be re-created very often. When it comes to building an image for deploying the app, there are ways to reduce the image size by including only what is required. </p>



<p class="wp-block-paragraph"><em>Execution time – is executing code from within the Docker container slower?</em></p>



<p class="wp-block-paragraph">I still have to explore this. There is, understandably, a small overhead associated with creating the container, but I have not measured execution times.</p>



<p class="wp-block-paragraph"><em>Is Docker easy to setup on any machine? How much extra stuff, effort is it?</em></p>



<p class="wp-block-paragraph">Setting up Docker on my machine was straight forward &#8211; I had no issues. Took me a couple of days to wrap my head around the concepts, terms etc but that is personal.</p>



<h3 class="wp-block-heading">Docker or Virtual Environment?</h3>



<p class="wp-block-paragraph">While setting up and using Docker is easy, and its utility is unmatched in certain scenarios (sharing a demo, deploying an app etc). But is Docker the right solution during development? Having gone through the setup above and trying out Docker, I feel it would be remiss of me if I don&#8217;t compare with using virtual environments during development. </p>



<p class="wp-block-paragraph">Jupyter notebooks is one key reason to use virtual environments. It is an easy and convenient way to develop code. So I am going to look at virtual environments using conda. </p>



<p class="wp-block-paragraph">Create a virtual environment like this (at the Anaconda Powershell Prompt):</p>



<pre class="wp-block-code"><code>conda create -n env_test_docker python=3.8</code></pre>



<p class="wp-block-paragraph">Activate the virtual environment:</p>



<pre class="wp-block-code"><code>conda activate env_test_docker</code></pre>



<p class="wp-block-paragraph">You can see the environments by typing <em>conda env list</em> in the Anaconda shell (see below; note the current env has an &#8216;*&#8217; before the name)</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="310" src="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image5-1024x310.jpg" alt="" class="wp-image-1279" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image5-1024x310.jpg 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image5-300x91.jpg 300w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image5-768x233.jpg 768w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image5-370x112.jpg 370w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image5-760x230.jpg 760w, https://www.kartiknanda.com/wp-content/uploads/2020/10/docker_image5.jpg 1327w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure></div>



<p class="wp-block-paragraph">Once in the new environment, the next step is to install the required packages. Do it as follows:</p>



<pre class="wp-block-code"><code>pip install -r requirements.txt</code></pre>



<p class="wp-block-paragraph">The packages can be installed during the environment creation using an environment.yml file. See <a href="https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html">here </a>for more details on conda env.</p>



<p class="wp-block-paragraph">Once the packages are installed, this setup should work across platforms. There is no isolation though, and there might be issues due to underlying platform, and individual management of the virtual environment. </p>
<p>The post <a href="https://www.kartiknanda.com/using-docker-to-collaborate-on-code-development-across-sites/">Using Docker To Collaborate On Code Development Across Sites</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kartiknanda.com/using-docker-to-collaborate-on-code-development-across-sites/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Nice to meet you!</title>
		<link>https://www.kartiknanda.com/hi-how-are-you/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hi-how-are-you</link>
					<comments>https://www.kartiknanda.com/hi-how-are-you/#respond</comments>
		
		<dc:creator><![CDATA[Kartik Nanda]]></dc:creator>
		<pubDate>Tue, 28 Jul 2020 19:51:15 +0000</pubDate>
				<category><![CDATA[Meet Me]]></category>
		<guid isPermaLink="false">http://www.kartiknanda.com/?p=1096</guid>

					<description><![CDATA[<p>Hey, I&#8217;m Kartik. Nice to meet you, and thanks for visiting my page. You will find here many of the projects that I have worked on, and, am working on. For any project, I have tried to document it as I have worked on it. I have tried to capture, and link to, what I found to be the most&#8230;</p>
<p>The post <a href="https://www.kartiknanda.com/hi-how-are-you/">Nice to meet you!</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Hey, I&#8217;m Kartik. Nice to meet you, and thanks for visiting my page. </p>



<p class="wp-block-paragraph">You will find here many of the projects that I have worked on, and, am working on. For any project, I have tried to document it as I have worked on it. I have tried to capture, and link to, what I found to be the most relevant sources &#8211; for learning and knowledge, as well as code. In most cases, the code is available on my <a href="https://github.com/kartiknan">github </a>page. </p>



<p class="wp-block-paragraph">If you&#8217;d like to know more about me, click <a href="http://www.kartiknanda.com/what-do-you-do/">here</a>, or just drop me a line. I look forward to hearing from you &#8211; so, how are you?</p>
<p>The post <a href="https://www.kartiknanda.com/hi-how-are-you/">Nice to meet you!</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kartiknanda.com/hi-how-are-you/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kartik, what do you do?</title>
		<link>https://www.kartiknanda.com/what-do-you-do/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=what-do-you-do</link>
					<comments>https://www.kartiknanda.com/what-do-you-do/#respond</comments>
		
		<dc:creator><![CDATA[Kartik Nanda]]></dc:creator>
		<pubDate>Tue, 28 Jul 2020 18:02:00 +0000</pubDate>
				<category><![CDATA[Highlights]]></category>
		<category><![CDATA[Meet Me]]></category>
		<guid isPermaLink="false">http://www.kartiknanda.com/?p=1100</guid>

					<description><![CDATA[<p>“Kartik, what do you do?” &#8211; asked you. Lets see &#8211; nowadays I design AI algorithms. I have designed Integrated Circuits, solar powered irrigation pumps in India, have founded a company, have some US patents. But what do I do? The 42nd time someone asked me this, I went deeper. As an&#160;undergraduate student at the Indian Institute of Technology (IIT),&#8230;</p>
<p>The post <a href="https://www.kartiknanda.com/what-do-you-do/">Kartik, what do you do?</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">“Kartik, what do you do?” &#8211; asked you. Lets see &#8211; nowadays I design AI algorithms. I have designed Integrated Circuits, solar powered irrigation pumps in India, have founded a company, have some <a href="https://patents.justia.com/inventor/kartik-nanda">US patents</a>. But what do I do? The 42nd time someone asked me this, I went deeper.</p>



<p class="wp-block-paragraph">As an&nbsp;undergraduate student at the <a href="http://www.iitk.ac.in/">Indian Institute of Technology (IIT), Kanpur</a>, I remember this sinking feeling at the end of every semester – I don’t see myself doing that for the rest of my life! Four years and something like forty courses, and at the end of it, I still had no idea what I wanted to do – every course had been a struggle.</p>



<p class="wp-block-paragraph">So I did the only logical thing – enrolled for a masters. It wasn’t until the second semester of <a href="https://cse.nd.edu/">graduate school at Notre Dame</a> that I found a course that I just “got” – Algorithms. Of course, realization has taken many more happy years to sink in.</p>



<p class="wp-block-paragraph">That interest in algorithms took me to signal processing early in my career. I designed delta sigma ADCs (or sigma delta, if you must!), digital filters, DSPs. Since these don’t exist in air, what I was actually doing was building mixed signal ICs. I started to think of myself as an IC guy (really! <a href="https://www.researchgate.net/profile/Samares_Kar">Prof. Kar’s</a> course!!).&nbsp;</p>



<p class="wp-block-paragraph">But algorithms wasn’t done with me yet – I moved on to solar, or more specifically, generating electricity from solar. From designing ICs, to coding algorithms for building irrigation pumps that run directly from a solar PV panel. Solar, though, is more than just a product for me. It has enabled me to return to India (where I was born), to rural India – what a learning experience that has been. I am now also more conscious of the environment, and of how we live our lives.&nbsp;</p>



<p class="wp-block-paragraph">My focus nowadays is&nbsp;Artificial Intelligence (AI), specifically deep learning using neural nets. Projects include looking for anomalies in audio signals, audio keyword recognition, identifying anomalies in images taken by a drone. All of these are algorithms &#8211; AI is but another tool. A powerful tool though, that makes it possible to do things we couldn&#8217;t earlier. I believe that AI complements human intelligence, not replace it. In other words, do things that humans cannot do or find too painful (expensive, tedious) to do. </p>



<p class="wp-block-paragraph">So, what do I do? – I design algorithms and build products around them. That is me, in a nutshell. I call Austin, Texas home, am married and have two wonderful daughters. I like the outdoors &#8211; in the pre-Corona days you could find me on Lady Bird Lake at least three evenings every week. </p>



<p class="wp-block-paragraph">OK, what do <em>you </em>do? Can I help you with your next thing? Do write &#8230;</p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.kartiknanda.com/what-do-you-do/">Kartik, what do you do?</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kartiknanda.com/what-do-you-do/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Setting up the Pi is easy</title>
		<link>https://www.kartiknanda.com/raspberry-pi-setup/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=raspberry-pi-setup</link>
					<comments>https://www.kartiknanda.com/raspberry-pi-setup/#respond</comments>
		
		<dc:creator><![CDATA[Kartik Nanda]]></dc:creator>
		<pubDate>Fri, 24 Jul 2020 01:32:30 +0000</pubDate>
				<category><![CDATA[AI on Pi]]></category>
		<category><![CDATA[Highlights]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[raspberry pi]]></category>
		<guid isPermaLink="false">http://www.kartiknanda.com/?p=1075</guid>

					<description><![CDATA[<p>This is the first in a series of posts on how to run AI on the Raspberry Pi (AI on Pi). The first step &#8211; setting up the Raspberry Pi. The final goal is to use the Pi to run a deep learning application. This could be vision related – example, recognizing an event from images/video feed, using Convolutional Neural&#8230;</p>
<p>The post <a href="https://www.kartiknanda.com/raspberry-pi-setup/">Setting up the Pi is easy</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">This is the first in a series of posts on how to run AI on the Raspberry Pi (AI on Pi). The first step &#8211; setting up the Raspberry Pi. The final goal is to use the Pi to run a deep learning application. This could be vision related – example, recognizing an event from images/video feed, using Convolutional Neural Nets (CNNs). It could also be audio related, so NLP using RNNs, but that is for a later time.</p>



<h2 class="wp-block-heading">The main goals:</h2>



<ul class="wp-block-list"><li>Capture images / video using a camera (sensor) connected to the Pi</li><li>AI algo executes on the Pi</li><li>Result is communicated to “Hub” using BT, Wifi etc. Hub could be another computer, IoT Hub, or the Cloud.</li></ul>



<p class="wp-block-paragraph">Since I have never worked with the Raspberry Pi previously, let’s start at the very beginning.</p>



<h3 class="wp-block-heading">Hardware:</h3>



<ul class="wp-block-list"><li>Raspberry Pi 4, 4GB version (bought the <a href="https://www.canakit.com/raspberry-pi-4-starter-kit.html">Canakit Raspberry Pi 4 Starter Kit</a>)</li></ul>



<ul class="wp-block-list"><li>OV5647 5.0MP Camera Module (bought at <a href="https://dlscorp.com/shop/ov5647-5-0-mp-raspberry-pi-compatible-camera-modules/">dlscorp.com</a> site)<br>The OV5647 module is the older version. There is a new <a href="https://www.raspberrypi.org/products/camera-module-v2/">official camera module</a>, but I decided to go with the older version for two reasons – cost and 5MP (vs 8MP in V2) is plenty for AI applications. Important details – needs to be a CSI module, and comes with a replaceable lens mount (M12)</li></ul>



<ul class="wp-block-list"><li>Camera lens (bought different lenses from dlscorp)</li></ul>



<ul class="wp-block-list"><li>Monitor – used an old monitor I had from years ago. The Pi connects to a monitor using a micro-HDMI port. The kit includes a micro-HDMI to HDMI cable, but I needed to buy a micro-HDMI to VGA adapter for my Monitor.</li></ul>



<ul class="wp-block-list"><li>Keyboard and mouse – used an old keyboard I had laying around</li></ul>



<h3 class="wp-block-heading">Software:</h3>



<ul class="wp-block-list"><li>Used the standard NOOBS (preloaded on the micro SD card), and the full Raspbian install. Nothing fancy, yet.</li></ul>



<h2 class="wp-block-heading">Step 1: Connect the System</h2>



<div class="wp-block-image"><figure class="alignright size-medium is-resized"><img decoding="async" src="http://www.kartiknanda.com/wp-content/uploads/2020/07/raspberry_pi_setup-225x300.jpg" alt="Raspberry Pi setup with a camera facing out a window" class="wp-image-1076" width="243" height="331"/></figure></div>



<p class="wp-block-paragraph">There are many excellent walk throughs – see <a href="https://projects.raspberrypi.org/en/projects/raspberry-pi-getting-started">here</a> or <a href="https://www.youtube.com/watch?v=BpJCAafw2qE">here</a>. The basics are simple enough – connect the display, keyboard and mouse, and the power, and follow the onscreen prompts. There are a couple of things I would like to point out though. One, setup SSH and VNC access to the Pi, so you can connect to it from a remote computer and don’t need the dedicated mouse, keyboard and monitor. This will be especially useful during deployment of the application. The second thing – <a href="https://www.raspberrypi.org/documentation/raspbian/updating.md">update the software</a>. Use “sudo apt-get update” and “sudo apt-get upgrade”.</p>



<p class="wp-block-paragraph">Once the system is operational, do take the time to explore, browse the web etc. Marvel at a simple yet very complete computer.</p>



<h2 class="wp-block-heading">Step 2: Python Setup</h2>



<p class="wp-block-paragraph">There are other languages, of course, but Python is the language of choice. Python2 and Python3 come pre-installed, with a bunch of packages. The first thing is the virtual environment setup – extremely important given the stand-alone nature of the intended application. The application should not break because of an update a couple of years out. I used <a href="https://virtualenv.pypa.io/en/latest/">virtualenv</a> – <a href="https://www.youtube.com/watch?v=N5vscPTWKOk">here</a> is a good intro.</p>



<p class="wp-block-paragraph">I spent some time (a little) trying to research the “best” editor but realize that the Pi is not necessarily where I will develop the code. That can be done on a laptop or in the cloud. So, for now I am using Thonny, which came pre-installed. I have not yet written a lot of python on the Pi, will see how it goes over the next few days/weeks – might yet change my mind. </p>



<p class="wp-block-paragraph">Try out a simple program, ensure that python is up and running. In the next post, the camera setup.</p>
<p>The post <a href="https://www.kartiknanda.com/raspberry-pi-setup/">Setting up the Pi is easy</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kartiknanda.com/raspberry-pi-setup/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Edge or Cloud &#8211; Where should AI live?</title>
		<link>https://www.kartiknanda.com/edge-or-cloud-where-should-ai-live/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=edge-or-cloud-where-should-ai-live</link>
					<comments>https://www.kartiknanda.com/edge-or-cloud-where-should-ai-live/#respond</comments>
		
		<dc:creator><![CDATA[Kartik Nanda]]></dc:creator>
		<pubDate>Sat, 19 Oct 2019 18:36:48 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[Highlights]]></category>
		<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Cloud AI]]></category>
		<category><![CDATA[Edge IoT]]></category>
		<category><![CDATA[Edge or Cloud]]></category>
		<category><![CDATA[IoT]]></category>
		<guid isPermaLink="false">http://www.kartiknanda.com/?p=107</guid>

					<description><![CDATA[<p>Where should the AI live? Does it have to be in the Cloud? Or does it live in the Edge? Is it even an option (sometimes it's not)? Is there a hybrid solution, that is, bits and pieces live on the Edge, and the Cloud? This article examines various criteria that have an impact on this decision</p>
<p>The post <a href="https://www.kartiknanda.com/edge-or-cloud-where-should-ai-live/">Edge or Cloud &#8211; Where should AI live?</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">This is a question that has come up many times during AI product discussions &#8211; where will the AI live? Does it have to be in the Cloud? Or does it live in the Edge? Is it even an option (sometimes it&#8217;s not)? Is there a hybrid solution, that is, bits and pieces live on the Edge, <em>and </em>the Cloud. </p>



<p class="wp-block-paragraph">There is not much online that compares these today, partly because its still early days. There was a panel discussion on this topic at the Texas Wireless Summit (<a href="https://www.youtube.com/watch?v=yorYWRrl4Jk">link to the YouTube video</a>). The excellent panelists covered some of the aspects I talk about here.</p>



<p class="wp-block-paragraph">The table below summarizes some key considerations and suggests which is better &#8211; the Cloud or the Edge. Below we examine each, and present our rationale. There is not a mathematical proof, but rather intuitive arguments, with some examples. We consider two examples. First is the facial recognition on mobile devices &#8211; we can unlock our phone, the laptop just by looking at it. The device uses its camera to &#8220;see&#8221; us, and uses an AI model running on the device itself to recognize the face, and unlock. Why does this model sit on the Edge?</p>



<p class="wp-block-paragraph">The second example is a drone searching for forest fires. Consider two possible implementations. Option 1 &#8211; the images are streamed into the Cloud, where the AI model looks for the fire. Option 2 &#8211; the AI sits on the drone itself, and the drone then only communicates the location of the fire. </p>



<div class="wp-block-image"><figure class="aligncenter size-aldo-thumb-masonry-big"><img decoding="async" width="760" height="197" src="https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1-760x197.jpg" alt="Comparing AI deployment at the Edge Vs in the Cloud" class="wp-image-1041" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1-760x197.jpg 760w, https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1-300x78.jpg 300w, https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1-1024x265.jpg 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1-768x199.jpg 768w, https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1-1536x398.jpg 1536w, https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1-370x96.jpg 370w, https://www.kartiknanda.com/wp-content/uploads/2020/07/AI_Edge_or_Cloud_Blog_Tbl1.jpg 1668w" sizes="(max-width: 760px) 100vw, 760px" /><figcaption>Where Should AI live &#8211; Edge or Cloud?</figcaption></figure></div>



<h2 class="wp-block-heading">Accuracy</h2>



<p class="wp-block-paragraph">Accuracy is a simple one. By &#8220;accuracy&#8221; we mean the accuracy of the AI model&#8217;s output. The Cloud has more resources, and in general, that translates into higher accuracy. What are these Resources? &#8211; compute and memory, so a bigger, more complex model. But it could also be access to other data (sensor fusion, or data from other deployments), or historical data, or other information that is not available at the Edge.</p>



<p class="wp-block-paragraph">A drone with a model in the Cloud is likely better at detecting fires.</p>



<h2 class="wp-block-heading">Time</h2>



<p class="wp-block-paragraph">Time &#8211; how long before we get the output result &#8211; is slightly more complicated. For the same computation, the Edge will be faster than the Cloud. Why? &#8211; the Edge is the data generation point. If the model sits in the Cloud, the data has to be uploaded, then inferred, and the results downloaded back to the Edge. However, if the results are not going back to the Edge and instead stay in the Cloud, then time might be the same.</p>



<p class="wp-block-paragraph">For the phone unlock example, the Edge is a better place for the AI. The action &#8211; unlock the phone &#8211; is at the Edge. </p>



<h2 class="wp-block-heading">Reliability</h2>



<p class="wp-block-paragraph">Sending data to the Cloud has a &#8220;variable&#8221; time aspect as well. Communication depends on many factors, like network availability, signal strength, data routing, traffic. Some are controllable, others harder. In a worst scenario, what if the data does not get through &#8211; will it be an issue that can be recovered from? </p>



<p class="wp-block-paragraph">As an example, if the face recognition unlock on the mobile phone ran in the Cloud, it likely wouldn&#8217;t be a feature! </p>



<h2 class="wp-block-heading">Power</h2>



<p class="wp-block-paragraph">There is a simple rule &#8211; the farther the data has to travel, the more power it needs. The most power-hungry part of an IoT (Internet of Things) device is the radio (eg, see <a href="http://diposit.ub.edu/dspace/bitstream/2445/97601/1/660493.pdf">Modeling Power Consumption for IoT devices</a>). The energy consumed of course depends on the amount of data sent. As an example, assume a drone looking for a fire. Option one is to send a video stream and process it in the Cloud. Another would be for the AI model to sit on the drone, and for the drone to only send the location of the fire. From the power perspective, the later will be far better.</p>



<h2 class="wp-block-heading">Cost</h2>



<p class="wp-block-paragraph">Closely tied to power is the cost. This is not obvious, because cost can include many things. However, purely from a cost-of-data angle, streaming the video is more costly than processing it at the Edge (on the drone, in the example above). </p>



<p class="wp-block-paragraph">The broader question about cost is harder. One aspect is one-time costs Vs recurring costs. While the Edge device is more a one-time cost, the Cloud presents a recurring cost. That&#8217;s only one aspect though, and cost has to be evaluated on a product by product basis. </p>



<h2 class="wp-block-heading">Security</h2>



<p class="wp-block-paragraph">There are two ways to look at security. One is the security of the data. It is most secure, and most easily secured, if it never leaves the Edge. Once the data is on the internet, or in the Cloud, it is only as secure as the encryption/protocols. </p>



<p class="wp-block-paragraph">The second is securing the Intellectual Property (IP) &#8211; the AI model for instance. This is more secure if its in the Cloud. </p>



<h2 class="wp-block-heading">Privacy</h2>



<p class="wp-block-paragraph">While &#8220;security&#8221; looks at the problem from the Provider&#8217;s perspective (company building the product), &#8220;privacy&#8221; looks at it from the Consumer&#8217;s perspective (person or entity using the product). It is a major concern, and becoming more important every day. Imagine if every time face recognition AI unlocks my phone, my image is uploaded to the Cloud. Then another AI algorithm uses it to &#8220;read&#8221; my emotional state, and sends suggestions (ads). That is a possibility (easy) with Cloud-based AI, but not as much with Edge-based AI. </p>



<p class="wp-block-paragraph">The easiest way to keep our personal data personal is to keep it on our devices, and not send it to the Cloud. </p>



<p class="wp-block-paragraph">So there&#8217;s the short list of considerations to keep in mind while planning your AI deployment, and figuring out where it belongs &#8211; the Cloud or the Edge. It is not a comprehensive list, and there are many other considerations like time-to-market, managing deployment, cost of building the solution, technology etc that are not covered. They make more sense though if examined within the scope of the AI project. Feel free to <a href="/contact-us">reach  out</a> with thoughts or if you need help to get started on your project.</p>
<p>The post <a href="https://www.kartiknanda.com/edge-or-cloud-where-should-ai-live/">Edge or Cloud &#8211; Where should AI live?</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kartiknanda.com/edge-or-cloud-where-should-ai-live/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AI and IoT &#8211; Marriage made in the Cloud</title>
		<link>https://www.kartiknanda.com/ai-and-iot/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ai-and-iot</link>
					<comments>https://www.kartiknanda.com/ai-and-iot/#respond</comments>
		
		<dc:creator><![CDATA[Kartik Nanda]]></dc:creator>
		<pubDate>Mon, 22 Oct 2018 18:42:05 +0000</pubDate>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Distributed AI]]></category>
		<category><![CDATA[Edge IoT]]></category>
		<category><![CDATA[Internet of Things]]></category>
		<category><![CDATA[smart home]]></category>
		<category><![CDATA[Solar Monitoring]]></category>
		<category><![CDATA[Solar PhotoVoltaic]]></category>
		<guid isPermaLink="false">http://www.kartiknanda.com/?p=70</guid>

					<description><![CDATA[<p>Whether you realize this or not, we are so connected to the “Cloud”. From my home thermostat, and doorbell, to now the microwave – everything connects to the internet. It&#8217;s not limited to the home either. From as big as the electricity grid to entire factory floors, to as small as your wrist health-monitor – everything is (or will be)&#8230;</p>
<p>The post <a href="https://www.kartiknanda.com/ai-and-iot/">AI and IoT &#8211; Marriage made in the Cloud</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Whether you realize this or not, we are so connected to the “Cloud”. From my home thermostat, and doorbell, to now the microwave – everything connects to the internet. It&#8217;s not limited to the home either. From as big as the electricity grid to entire factory floors, to as small as your wrist health-monitor – everything is (or will be) connected.<br></p>



<p class="wp-block-paragraph">Two things make this all possible – the Internet-of-Things (IoT) and Artificial Intelligence (AI). IoT is the physical interface, the senses. The internet senses the World through the IoT devices. In simpler terms, they collect the data – a camera that takes pictures or a microphone that listens. Or it could be simpler sensors like a thermometer (measuring temperature).<br></p>



<p class="wp-block-paragraph">But merely collecting all this data is not useful. (The quantity of this data is <a href="https://www.forbes.com/sites/bernardmarr/2018/05/21/how-much-data-do-we-create-every-day-the-mind-blowing-stats-everyone-should-read/#43db8a7060ba">huge</a> and increasing.) Something has to interpret and convert this data into actionable <em>information</em>. Something, that can extract meaningful information from this data. That is where Artificial Intelligence (AI) steps in.</p>



<p class="wp-block-paragraph">Today the AI lives in the cloud (for the most part). IoT collects and sends data to the Cloud, where the AI interprets it, and decides the outcome. Let&#8217;s see how this works with examples.</p>



<h2 class="wp-block-heading">AI and IoT – a marriage made in the Cloud</h2>



<p class="wp-block-paragraph">In the context of IoT, the goal of AI is:</p>



<ul class="wp-block-list"><li>to learn a model from the data, and,</li><li>use the model to interpret new data and provide an actionable outcome (a decision).</li></ul>



<p class="wp-block-paragraph">We’ll consider two examples – a voice assistant, like Alexa or Siri, and a smart front door. The Voice Assistant understands human language. For the smart front door, the goal is that the door should recognize me and unlock itself, without me having to use a key.&nbsp;</p>



<h3 class="wp-block-heading">Example: The Voice Assisant</h3>



<p class="wp-block-paragraph">The Voice Assistant (VA) responds to spoken commands. It uses a microphone (the IoT sensor) to listen. The AI makes sense of the sounds &#8211; the words, sentences and context. It then provides the information or acts on the command. (For example, playing specific music or provide driving directions).<br></p>



<div class="wp-block-image"><figure class="alignright size-medium"><img decoding="async" width="300" height="187" src="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1-300x187.jpg" alt="Key steps in developing and using an AI solution" class="wp-image-1248" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1-300x187.jpg 300w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1-1024x639.jpg 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1-768x479.jpg 768w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1-1536x958.jpg 1536w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1-370x231.jpg 370w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1-760x474.jpg 760w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig1.jpg 1672w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption>AI and IoT &#8211; the green boxes are IoT sensors</figcaption></figure></div>



<p class="wp-block-paragraph">Figure shows how this works. The IoT gathers the data (1) – in the case of the Voice Assistant, the data is sounds. This data is then sent to the Cloud (2). Here the data trains the AI (3) and build a model. The model is then deployed (4). <br></p>



<p class="wp-block-paragraph">The model for the VA is complicated. It needs to understand the entire language, spoken with many different accents. Once trained though, the same model applies to all the VAs in the network. </p>



<p class="wp-block-paragraph">For the Voice Assistant, the model (AI) learns and is deployed in the cloud itself. <br>The AI receives and interprets all spoken words in the Cloud (Cloud-AI). Why keep it in the Cloud? Mostly because it is a large model. It is also being constantly updated, and keeping it in the Cloud means only one model needs to be updated. The main issue is the lack of privacy. Anything I say, the VA is listening to and sending to the Cloud where it may be interpreted.<br></p>



<h3 class="wp-block-heading">Example: The Smart Front Door</h3>



<p class="wp-block-paragraph">The goal with the smart Front Door is it recognizes me and responds by unlocking the door for me, and only me. It needs to sense my presence, and let’s say it uses a camera (the IoT sensor). AI provides the intelligence. It learns what I look like and then uses that model to recognize me and open the door.</p>



<p class="wp-block-paragraph">The Front Door system design may follow the same approach as the VA. The camera (IoT) gathers the data, which is sent to the Cloud. There the AI learns to recognize me. But here things become different. The AI has to recognize my face for my door, and my neighbor&#8217;s face for their door. That means the AI trains differently for different doors.</p>



<p class="has-text-align-center has-very-light-gray-background-color has-background wp-block-paragraph">This is a critical difference &#8211; in the VA case, the same AI (one trained model) could serve all IoT devices in the network. But in the Front Door example, every door has a unique model.</p>



<p class="wp-block-paragraph">So for the Front Door, it might make sense to instead deploy the AI in the IoT device itself (IoT-Edge), rather than the Cloud. The Front door only needs to decide Me-Vs-NotMe. So while the model may train in the Cloud (esp. the Not-Me part), it is deployed at the IoT-Edge.<br></p>



<p class="wp-block-paragraph">There are other good reasons for the different approaches (Cloud AI Vs Edge AI). Two of the main ones are privacy, and the size of the model. Large, typically complicated models can not fit on the resource-limited IoT devices. But, I also do not want a digital representation of my face stored on the cloud.</p>



<h2 class="wp-block-heading">Heterogenous IoT Networks</h2>



<p class="wp-block-paragraph">We looked at two examples above &#8211; the VA and front door &#8211; both using single IoT devices. In general though, IoT networks consist of many devices. They are also not always homogenous, that is, not all the attached systems are identical. They may have some common features, but some unique ones as well. Think of a factory floor or even the car &#8211; both have many different types of sensors (IoT sense devices). <br></p>



<p class="wp-block-paragraph">This complicates the AI. It is no longer possible to train the AI on one IoT device, and map the model to all the IoT devices in the network.<br></p>



<p class="wp-block-paragraph">To illustrate this, imagine if my front door now has a fingerprint sensor in addition to the camera. The AI for the camera cannot map to the finger print sensor. Yet the two have to work together on the same problem, namely to recognize me and unlock the door.</p>



<div class="wp-block-image"><figure class="alignleft size-aldo-thumb-med"><img decoding="async" width="370" height="208" src="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig2-370x208.png" alt="IoT network devices are not always identical. They may have common and unique features" class="wp-image-1252" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig2-370x208.png 370w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig2-270x152.png 270w" sizes="(max-width: 370px) 100vw, 370px" /></figure></div>



<p class="wp-block-paragraph">The figure shows a general scenario &#8211; it depicts two different IoT sensors. They both have some common features, and some unique ones. One solution is to learn a superset of all possible features in the cloud. The result is a large, complicated model. This needs far more resources in the IoT edge devices, or compromises on privacy by keeping the AI in the Cloud (figure below, left).</p>



<h2 class="wp-block-heading">A Distributed AI Model (Edge-AI)</h2>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="410" src="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4-1024x410.png" alt="AI and the Internet of Things: Cloud-AI Vs Distributed AI" class="wp-image-1254" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4-1024x410.png 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4-300x120.png 300w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4-768x308.png 768w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4-1536x616.png 1536w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4-370x148.png 370w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4-760x305.png 760w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig4.png 1881w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>AI in the Cloud Vs Distributed AI</figcaption></figure></div>



<p class="wp-block-paragraph">Another solution is a Distributed AI model. This implements the AI on the network (above figure, right) &#8211; which includes the Cloud and the different IoT devices. Parts of the solution &#8211; the common features &#8211; are mapped to the Cloud. The unique ones are modeled and learnt locally on the IoT sensor devices. <br></p>



<p class="wp-block-paragraph">This provides both benefits &#8211; privacy and resource management. Since the model is local to the IoT edge device, private data is not sent or stored in the cloud. This also utilizes the available resources better. The IoT devices store only local models, and not the entire systems&#8217; model. The result &#8211; a smaller footprint at each IoT device. Much of the AI now resides on the network devices. This reduces the computations and data requirements in the cloud. <br></p>



<p class="wp-block-paragraph">This is a Distributed AI solution (or Edge-AI). As IoT networks become more prevalent, we will start to see more AI move to the Edge. Lets illustrate with an example next.</p>



<h2 class="wp-block-heading">Example &#8211; Solar Monitoring with Distributed AI</h2>



<p class="wp-block-paragraph">The past few years have seen a tremendous growth in rooftop solar plants. Many residences today generate their own electricity from the Sun. Here&#8217;s a common question that comes up all too often from owners:<br></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>&#8220;I have installed a rooftop solar plant for electricity. How do I know if the energy output from my plant is actually correct, as designed?&#8221;<br></p><cite>Solar Customer</cite></blockquote>



<p class="wp-block-paragraph">Data there is plenty of &#8211; solar plants provide daily energy output data. The problem is this energy output number changes from day to day, based on many factors like the weather. What is lacking (and what the owner is looking for) is information. Is the output <em>correct</em>?</p>



<h3 class="wp-block-heading">AI and Solar Monitoring&nbsp;<br></h3>



<p class="has-text-align-center has-very-light-gray-background-color has-background wp-block-paragraph">The goal with AI, is to learn a model of the Plant, and to monitor it by comparing actual output against the predicted output.<br></p>



<p class="wp-block-paragraph">One solution is to model the plant in the Cloud (the Cloud-AI solution). The first step is to take all the data into the cloud. The second step is to learn a model of the plant &#8211; certain plant specific details such as the shade profile. The third step is to predict the output under the given environmental conditions. The final step is comparing the actual output from the plant and the predicted output. The result is actionable information &#8211; is the plant output good or not.</p>



<p class="wp-block-paragraph">This solution works, but has two issues. The first is privacy &#8211; all the data goes to the Cloud. The second is scalability. Imagine learning the models for hundreds of thousands of small residential solar plants in the Cloud. A better solution: if the models could be learnt locally in the IoT device themselves.<br></p>



<div class="wp-block-image"><figure class="aligncenter size-aldo-thumb-masonry-big"><img decoding="async" width="760" height="334" src="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5-760x334.png" alt="Using Distributed AI (Edge-AI) for Solar Monitoring" class="wp-image-1255" srcset="https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5-760x334.png 760w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5-300x132.png 300w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5-1024x450.png 1024w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5-768x337.png 768w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5-1536x675.png 1536w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5-370x163.png 370w, https://www.kartiknanda.com/wp-content/uploads/2020/08/Edge_AI_Blog_Fig5.png 1987w" sizes="(max-width: 760px) 100vw, 760px" /><figcaption>Solar Monitoring &#8211; The Distributed AI approach</figcaption></figure></div>



<p class="wp-block-paragraph">Edge-AI solves both of these issues. The AI solution maps on to the entire network (see figure). Certain elements that are common to all the plants &#8211; the weather for example &#8211; are modeled in the Cloud. The Plant specific modeling however, is local. <br></p>



<p class="wp-block-paragraph">The result is better on many fronts. One, the distributed model uses resources more optimally by processing data locally. Data privacy is much better since all plant modeling is local. The network scales easily. Adding a new plant is easy since every plant learns its own model, and only its own model.&nbsp;</p>



<h2 class="wp-block-heading">Closing Thoughts</h2>



<p class="wp-block-paragraph">Products and solutions based on a network of IoT sensors are set to become prevalent. Some applications include the electricity smart-Grid, a smart-home, individualized health care. AI will be an integral part of any such product. And while today Cloud-based solutions dominate the AI landscape, such AI-IoT network products will need new distributed topologies. <br></p>



<p class="wp-block-paragraph">Edge-AI is a distributed AI topology. It maps the AI on the entire network, not just in the Cloud. This provides two distinct advantages over AI in the Cloud. The first is privacy &#8211; with models that are learnt locally. Second is the lean implementation, an optimal use of the available resources. <br></p>



<p class="wp-block-paragraph">Distributed AI will drive the next wave of Intelligent Products.</p>
<p>The post <a href="https://www.kartiknanda.com/ai-and-iot/">AI and IoT &#8211; Marriage made in the Cloud</a> appeared first on <a href="https://www.kartiknanda.com">Kartik Nanda, Engineering AI</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kartiknanda.com/ai-and-iot/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
