<?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 Adesh Gautam on Medium]]></title>
        <description><![CDATA[Stories by Adesh Gautam on Medium]]></description>
        <link>https://medium.com/@adeshg7?source=rss-d90d6240dcbc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bVElvqieMa3KT08_uLr8hw.jpeg</url>
            <title>Stories by Adesh Gautam on Medium</title>
            <link>https://medium.com/@adeshg7?source=rss-d90d6240dcbc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 18:36:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adeshg7/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[A visit to Google Gurgaon Office]]></title>
            <link>https://adeshg7.medium.com/a-visit-to-google-gurgaon-office-4e65a56db4b8?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e65a56db4b8</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[office]]></category>
            <category><![CDATA[gurgaon]]></category>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[internships]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Mon, 05 Jun 2023 09:11:13 GMT</pubDate>
            <atom:updated>2023-06-05T09:11:13.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BbGJtYoTiTxa1UV6DCp5mA.jpeg" /><figcaption>Google Gurgaon Office</figcaption></figure><p><strong>The month is June 2018</strong></p><p>Sharing this just for the fun I had back 5 years ago. I wrote this article a long time back but didn’t publish, finally doing it.</p><p>An email pops up.</p><p>“We are happy to confirm your attendance at the Google Gurgaon office”.</p><p>This made me so much excited and I was already daydreaming about the possible next set of events.</p><p>It was a “Tech Intern Connect” event where interns from 100+ different organizations and 50+ campuses were gathered to share knowledge and experience.</p><p>I was waiting for the day.</p><p>On June 29 2018 evening, I took the train and reached by the next morning. The event was going to start at 8:30AM but I was there 10 mins early 😛.</p><p>First, “Badging and Refreshment”.</p><p>There was a warm welcome in which the Google interns at the reception were distributing badges and greeting with big smiles.</p><p>Upon entering the room where the rest of the interns from Hyderabad, Mumbai and Bangalore were connected live on Hangouts, we received the Google schwag including badges, stickers etc.</p><p>Then there was an activity called “Ice Breaker” which was basically a Bingo game with more fun. We had to fill the names of the interns on the Bingo sheet. There was a rush for asking each other’s names and fill the names as fast as possible as the winner was getting extra schwag.</p><p>After that, there was a tech talk about “DNA of a product”. It gave intuitive explanations of what a good product is, what needs to be focused upon for a good product etc. An example was given of the recently launched beta “Neighbourly”, an app for crowdsourcing local questions.</p><p>After that there was an interesting panel discussion with 5 Googlers who are a part of Google ranging from 1 month to 10–15 years. They shared their experiences, talked about their past and answered a lot of questions asked by us.</p><p>Then there was a networking lunch. The time where all the student interns, Google interns, Google engineers and members of TOPs interacted with each other. We shared each other’s experiences, talked about college life, future goals and exchanged contacts. This was really fun.</p><p>We ate lunch sitting in groups and then the most exciting part was there. The “Google Theatre Club”. Some Googlers and interns paired up and performed Improv comedy — a form of live theatre. We gave them many different situations and characters which won’t even match up and they performed on them. We didn’t stop laughing at their acts.</p><p>At last, it was time for the closing of the event and we were again given chance to ask questions or doubts. The head of TOPs told how to remain engaged with Google, be aware of future Google opportunities and utilize the tons of resources provided by Google.</p><p>The event was over at 3:30 PM.</p><p>It was one of the best days of my life. I got to meet so many interesting people and hope will be connected further.</p><p>And, that was it. A fun, interesting, educational visit to Google Gurgaon Office.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/pixels.adesh/?hl=en"><strong>Instagram</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a><strong> </strong><a href="https://github.com/adesgautam"><strong>Github</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e65a56db4b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your own Search Engine using OpenAI’s CLIP and FastAPI — Part 1]]></title>
            <link>https://adeshg7.medium.com/build-your-own-search-engine-using-openais-clip-and-fastapi-part-1-89995aefbcdd?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/89995aefbcdd</guid>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[search]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[clip]]></category>
            <category><![CDATA[projects]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Fri, 18 Jun 2021 15:48:38 GMT</pubDate>
            <atom:updated>2021-06-18T15:48:38.859Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build your own Search Engine using OpenAI’s CLIP and FastAPI</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w-jaO7igIP4nd-jt" /><figcaption>Photo by <a href="https://unsplash.com/@synkevych?utm_source=medium&amp;utm_medium=referral">Roman Synkevych</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Okay, so this search engine will not be a full-fledged one but you’ll get a hand wtih all the capabilities of the OpenAI’s CLIP model and how to use it to your own use cases.</blockquote><h3><strong>What is CLIP ?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0FSyr5m6LVRtHr9wHJ-KZA.png" /><figcaption>CLIP architecture</figcaption></figure><p>Suppose you want to tag your images to a set of particular words, what you’ll do?</p><p>You’ll probably build a classifier that can do this pretty easily right? But what if you want to tag them to a sequence of words or even a sequence of sentences. It is hard to utilize a classifier for this purpose.</p><p>Now here CLIP comes into play, it is trained on a pair of a sequence of words and an image. So, it knows whatever it is seeing can be formulated into a sequence of words. It won’t generate those words rather it can tell that this particular image is closely related to these particular set of words.</p><p>So you provide your images to the model and a set of sentences to it and it will tell that this image is closely related to these sentences with this similarity.</p><p>If you want a full-blown read of CLIP’s working head over to this <a href="https://openai.com/blog/clip/">official article</a>.</p><p>The official code implementation of can be found <a href="https://github.com/openai/CLIP">here</a>.</p><h3>How to use CLIP to build your Search Engine?</h3><blockquote>The code for this article can be found <a href="https://github.com/adesgautam/clip-search">here</a>.</blockquote><p>We’ll do two things here, first</p><h4><strong>Image Search</strong></h4><ol><li>We’ll go through the images in a particular directory and generate embeddings for them and store it in a DB.</li><li>Then for a text query, we’ll generate new embeddings and then calculate the similarity between the embeddings stored in DB with the query.</li><li>Using this similarity we can know, with which image the query resembles more.</li><li>Now we can sort the results and display them.</li></ol><p>Here you can see we are creating embeddings of all the images and storing in DB.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fcb36e16b4f590d405ee714e15d4fa7/href">https://medium.com/media/2fcb36e16b4f590d405ee714e15d4fa7/href</a></iframe><p>Once it is done, you can calculate text and image similarity using this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/425b5861bba120f41b4d09188305124a/href">https://medium.com/media/425b5861bba120f41b4d09188305124a/href</a></iframe><p>Now you can use this similarity metric to sort the images and display them.</p><p>The second thing we’ll build is</p><h4>Reverse Image Search</h4><p>For this the idea is the same.</p><ol><li>We already have image embeddings stored, we’ll create new ones for the query image.</li><li>Then we can calculate similarity, sort and display them.</li></ol><h3>FastAPI as backend</h3><p>I wanted to use Flask but we have FastAPI widely getting popular so why not use it then.</p><p>FastAPI is a high-performance asynchronous web framework. It is around 10X faster than Flask. So it makes sense to use it for super-fast APIs.</p><p>You can refer to the <a href="https://fastapi.tiangolo.com/">official docs here</a> for more details.</p><h3>Libraries</h3><p>We have used the following libraries in the code:</p><ol><li>FastAPI</li><li>Sqlite3(I know it’s not ideal but just for experimentation stuff)</li><li>CLIP model based on PyTorch framework.</li></ol><h3>Expanding the Engine</h3><p>To expand the engine you’ll have to index more and more images into the DB and generate embeddings. As theDB will grow the similarity calculation will be slow. So, for that a full fledged database could be useful. I’ll cover more of these things in my next post.</p><p>I’ll be adding more features to this project soon and release a new article soon. Please feel free to PR to the Github repo and contribute to the project.</p><p>The code repo is available <a href="https://github.com/adesgautam/clip-search">here</a>.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>Connect me here:</p><p><a href="https://github.com/adesgautam"><strong>Github</strong></a><strong> </strong><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/pixels.adesh/"><strong>Instagram</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89995aefbcdd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Colorizing black and white images on Android using Tflite]]></title>
            <link>https://adeshg7.medium.com/colorizing-black-and-white-images-on-android-using-tflite-a2064bee7049?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2064bee7049</guid>
            <category><![CDATA[tflite]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[tensorflow-lite]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Thu, 19 Nov 2020 07:55:23 GMT</pubDate>
            <atom:updated>2020-11-19T08:42:06.229Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V-yLXOza6xpGP0Bb" /><figcaption>Photo by <a href="https://unsplash.com/@marvelous?utm_source=medium&amp;utm_medium=referral">Marvin Meyer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>In this story we’ll see how you can deploy your tensorflow model on an Android device using Tflite. Ok, but why do you want to run your models on Android ? For fun ? or testing you model on REAL data ?<br>Well, for me it’s both.</blockquote><p>Training a model on laptop using python is a no brainer. Gather data and boom ! Using Pytorch or Tensorflow you can train it pretty easily. But what about putting your model on an Android device.</p><p>You have to understand the limitations of putting you model on phone. First you don’t have numpy there so less flexibility. You can’t just read an image and reshape it and do different operations in 5–6 lines and do inference. You have to do it the Android way. It’s a different experience for an ML engineer.</p><p>The code is available on my <a href="https://github.com/adesgautam/colornet-tflite">Github repo</a>.</p><h3>The Android Way</h3><p>I have a basic workflow for the app:</p><ol><li>Create a Imageview on the app.</li><li>Add a button and add an onclicklistener to it.</li><li>Write stuff in the onclicklistener to load an image from gallery or camera to the imageview on clicking it.</li><li>Further in the onclicklistener, add code to load tflite model, get the Image from imageview into a bitmap object and apply preprocessing using tensorflow’s already provided functions or using your own.</li><li>Feed the bitmap to the model, get the output and do post processing if required. Now feed this output as bitmap into the imageview.</li></ol><h3>Things to keep a note of</h3><p>This is the simplest workflow to do inference on an image.</p><p>But, we have some differences in the workflow for our app. First, we have 2 model inputs, for a mobilenet and a custom model. So, we have to preprocess the image differently for each model input. Second, for the custom model we are feeding the output from the mobilenet and a separate input, so basically there are two inputs for the custom model. It will generate a colorized image as output.</p><p>You can refer to the below image for the model architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*j1VY-nloZTCliOliJF-osA.png" /><figcaption>Colornet Model Architecture</figcaption></figure><p>Also, the custom model input takes a LAB color format and the mobilenet takes RGB format. But this depends on your model.</p><p>Also, you have the following things on Android which can be new at first but they are just the required things to do inference on Android:</p><ol><li>Tflite Interpreter</li><li>MappedByteBuffer</li><li>GpuDelegate</li></ol><p>Hope this woud help you in deploying your models on Android device.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://github.com/adesgautam"><strong>Github</strong></a><strong> </strong><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/pixels.adesh/"><strong>Instagram</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2064bee7049" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Django + PostgreSQL on EC2 using Apache2 from scratch]]></title>
            <link>https://adeshg7.medium.com/deploy-django-postgresql-on-ec2-using-apache2-from-scratch-42dc8e6682c1?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/42dc8e6682c1</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Fri, 10 Jul 2020 12:49:47 GMT</pubDate>
            <atom:updated>2020-07-10T12:49:47.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0e21IIZs2PNvHhcc" /><figcaption>Photo by <a href="https://unsplash.com/@alvarordesign?utm_source=medium&amp;utm_medium=referral">Alvaro Reyes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>It’s fun to build apps as personal projects, but what if you want it to deploy it and showcase it to others? And not only that it should be able to handle multiple requests simultaneously. Well, in this article we’ll do this. Create Django apps, use PostgreSQL as a database and use Apache2 for handling multiple requests and some tips for logging and debugging errors.</blockquote><h3>Setup EC2 instance</h3><p>Launch a new Instance on AWS EC2 using the following configs:</p><ol><li>OS: <strong><em>Ubuntu 18.04 LTS</em></strong></li><li>Any instance type, we’ll choose <strong><em>t2.medium</em></strong></li><li>Add Storage <strong><em>20GB</em></strong>, it’ll be sufficient for now</li><li>In Security group, add rule with Type: <strong><em>HTTP</em></strong>, Port Range: <strong><em>80</em></strong>, Source: <strong><em>Custom</em></strong> and <strong><em>0.0.0.0/0, ::/0</em></strong></li></ol><p>Launch the instance and <strong><em>SSH</em></strong> into it.</p><h3>Setup PostgreSQL</h3><ol><li>Install PostgreSQL:</li></ol><pre>sudo apt-get update</pre><pre>sudo apt-get install python-dev libpq-dev postgresql postgresql-contrib</pre><p>2. Now, let’s setup PostgreSQL,</p><pre>sudo su — postgres</pre><pre>psql</pre><pre>CREATE DATABASE djangodemodb;</pre><pre>CREATE USER adesh WITH PASSWORD ‘mysecretpass’;</pre><pre>GRANT ALL PRIVILEGES ON DATABASE djangodemodb TO adesh;</pre><pre>\q</pre><pre>exit</pre><p>Using these commands sequentially, you’ll create a database named ‘<strong>djangodemodb</strong>’ and a new user ‘<strong>adesh</strong>’ with ‘<strong>mysercretpass</strong>’ as password. You also need to grant privileges to ‘<strong>adesh</strong>’ user for ‘<strong>djangodemodb</strong>’ database. Finally, you exit out of the <strong>psql</strong> shell using <strong><em>\q</em></strong>.</p><h3>Setup Django</h3><p>First we’ll set up the virtual environment for Django so that it’s easily deployable on EC2.</p><ol><li>Create a directory djangodemo and create a virtualenv using python3:</li></ol><pre>mkdir djangodemo <br>cd djangodemo <br>virtualenv -p python3 djangodemo</pre><p>2. Install <strong><em>Django 2.2</em></strong>. We’ll work on this as it’s the <strong><em>LTS</em></strong> version.</p><pre>source djangodemo/bin/activate <br>pip install django==2.2</pre><p>3. Then create a Django project:</p><pre>python -m django startproject djangodemo_UI</pre><p>4. Test if the Django server is running, it will be at <strong><em>127.0.0.01:8000</em></strong></p><pre>python manage.py makemigrations &amp;&amp; python manage.py migrate</pre><pre>python manage.py runserver</pre><p>5. In the <strong><em>settings.py</em></strong> file change the following:</p><pre>ALLOWED_HOSTS = [‘*’]</pre><pre>Change DATABASES to this:</pre><pre>DATABASES = {</pre><pre>‘default’: {</pre><pre>‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’,</pre><pre>‘NAME’: ‘djangodemodb’,</pre><pre>‘USER’: ‘adesh’,</pre><pre>‘PASSWORD’: ‘mysecretpass’,</pre><pre>‘HOST’: ‘localhost’,</pre><pre>‘PORT’: ‘’,</pre><pre>}</pre><pre>}</pre><p>6. Install <strong><em>psycopg2</em></strong> to help Django interact with PostgreSQL.</p><pre>pip install psycopg2</pre><p>If you get an error, try</p><pre>pip install psycopg2-binary</pre><p>7. Create <strong>superuser</strong> for the admin dashboard, it will ask for username and password:</p><pre>python manage.py createsuperuser</pre><h3>Setup Apache2</h3><ol><li>Install Apache2:</li></ol><pre>sudo apt-get update</pre><pre>sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3</pre><p>2. Change the configs of <strong><em>000-default.conf</em></strong>:</p><pre>vim /etc/apache2/sites-available/000-default.conf</pre><p>File location: <strong><em>/etc/apache2/sites-available/000-default.conf</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c24104bae967cfd3a46e08429c11a948/href">https://medium.com/media/c24104bae967cfd3a46e08429c11a948/href</a></iframe><p>Change the following in the above config:</p><blockquote>Change <strong>path/to/your/djangodemo_UI</strong> to your root djangodemo directory</blockquote><blockquote>Change <strong>path/to/your/djangodemo_UI/wsgi/folder</strong> to your path containing the wsgi.py file in <strong>djangodemo_UI/djangodemo_UI</strong></blockquote><blockquote>Change <strong>path/to/your/djangodemo/virtualenv</strong> to your path to the djangodemo virtual environment we created</blockquote><p>3. Enable MPM workers to handle multiple requests in <strong><em>apache2.conf</em></strong>:</p><pre>vim /etc/apache2/apache2.conf</pre><p>File location: <strong><em>/etc/apache2/apache2.conf</em></strong></p><p>Add the following lines at the end of the file. These need to be changed as per your Django app memory consumption and traffic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbe6dfd9cc87d2d2d40ae8c7ada282b6/href">https://medium.com/media/dbe6dfd9cc87d2d2d40ae8c7ada282b6/href</a></iframe><p>4. Change the permissions for ‘djangodemo_UI’ directory using:</p><pre>sudo chown :www-data djangodemo_UI</pre><p>5. Now, restart the Apache2 server:</p><pre>sudo service apache2 restart</pre><p>Now go to the <strong><em>IPv4/Public URL</em></strong> of your EC2 instance and you’ll see you Django app running.</p><h3>Logging and Debugging</h3><p>It is very difficult to debug errors on Apache2. For that we’ll configure Django to log errors separately. Add the following to <strong><em>settings.py</em></strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/caf90eb0fdf51005f8270614ad91b922/href">https://medium.com/media/caf90eb0fdf51005f8270614ad91b922/href</a></iframe><p>Check this file for potential errors, or you can check the Apache2 logs using:</p><pre>tail -n 100 /var/log/apache2/error.log</pre><p>Also, use <strong><em>DEBUG=False</em></strong> in <strong><em>settings.py</em></strong> in production. This could also help in finding errors in the logs.</p><h3>Notes</h3><ol><li>Check the Security Group rules. Allow port <strong>80</strong> for <strong>HTTP</strong></li><li>Use correct paths in <strong><em>000-default.conf </em></strong>file</li><li>Check if correct dependencies are installed in the virtual environment.</li><li>Check for the correct PostgreSQL configuration.</li><li>Check for correct ‘<strong><em>static</em></strong>’ and ‘<strong><em>media</em></strong>’ directories.</li></ol><p>You can find the Github repo <a href="https://github.com/adesgautam/django-apache2"><strong><em>here</em></strong></a></p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://github.com/adesgautam"><strong>Github</strong></a><strong> </strong><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/pixels.adesh/"><strong>Instagram</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42dc8e6682c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vuejs + Golang = A rare combination]]></title>
            <link>https://adeshg7.medium.com/vuejs-golang-a-rare-combination-53538b6fb918?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/53538b6fb918</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[single-page-applications]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 16:44:41 GMT</pubDate>
            <atom:updated>2019-07-23T16:44:41.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SJ43Bk4fxc44mgVR" /><figcaption>Photo by <a href="https://unsplash.com/@rxspawn?utm_source=medium&amp;utm_medium=referral">Florian Olivo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Back in 2018, I wrote an article “Django + Angular 4 = A powerful web application” which has over 15k reads. Out of curiosity, I tried Angular 4 and Django. Continuing the series, here is a new article helping you to build amazing apps using - “Vuejs” and “Golang”.</blockquote><p>I know, these two aren’t popular to be used along with each other. But, let’s try…</p><h3>Background</h3><p>Okay so first, let’s talk about the features these technologies provide.</p><h4>Golang</h4><ol><li>Binaries — The binaries are generated with all the dependencies built-in. Thus, you need not to install the runtimes to run the application.</li><li>Static typing — The compiler takes care of the code when you are writing it and not only compile it. The type conversions and compatibility etc are taken care of.</li><li>Concurrency — The best feature of Golang is that it has first-class support of concurrency built itself in the language.</li><li>Standard library — The standard library is powerful enough that you mostly won’t need 3rd party libraries.</li></ol><h4>Vuejs</h4><ol><li>Size — After gzipping it weighs only 18kB as compared to the minified jQuery which sizes to 29kB after gzipping.</li><li>Readability — The code and syntax of Vuejs is very clear and simple.</li><li>Documentation — It has thorough documentation which makes it fast and easy to learn.</li><li>Reactivity — The data binding between HTML and Javascript is very fluid.</li><li>Vue CLI 3 — It offers a lot of features that makes developers life easy. Just try it and you’ll love it.</li></ol><p><strong>Golang</strong> and <strong>Vuejs</strong> both are fast during runtime. Thus, making them work with each other provide a fast single page application.</p><p>Ok, let’s start.</p><h3>Setting up directories</h3><p>First, set up your directories like below. “LICENSE” and “README.md” for Git.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*vtaJKeFNo6dKujZYsEi6hw.png" /></figure><p>Now, in backend directory create a file server.go</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*-Kc01BeHC7_k3AzYblaVxA.png" /></figure><p>For frontend, type the following in the terminal to create a new app Calculator,</p><pre>                      vue create calculator</pre><p>It will ask you to choose a preset. Choose the default one (babel, eslint).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*tbr9X84OEsJCrWgEOJSHvA.png" /></figure><p>Now this will be the folder structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*IUbOGEl5b4ozSYWQmuDM_w.png" /></figure><p>The skeleton is ready!</p><p>Now, let’s see what we are going to build. It’s not a fancy app but will help you get started to build complex apps.</p><p>We are going to build a calculator in which you will enter two numbers, they will be grabbed by Vue frontend and sent to the Golang server using a <strong>POST</strong> request. The server will compute addition, multiplication, subtraction and division and send back the results using a <strong>POST</strong> request. The frontend will then render the results.</p><h3>Build the backend</h3><p>Golang is fast and the reason for it is the compiler, which doesn’t let you declare variables unless you use them. If you declare something or import any package you will <strong>have</strong> to use it. It is very strict about it. And also whatever you are going to do you have to tell the compiler beforehand like: if you want to grab the <strong>POST</strong> data, you have to declare the structure of the <strong>JSON</strong> data beforehand. This is a little tricky but worth the speed.</p><p>Coming to the code.</p><p>So, we’ll use the encoding/json and net/http packages. Then, we’ll declare the structures for the JSON data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*bBx8qYZkWpg8R92e8gT_5g.png" /><figcaption>packages and the JSON data structures</figcaption></figure><p>Now, we’ll write a simple function to do the calculations. Here, we need to specify the return type explicitly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*AR0TlByqhirRpm8s7R5FUA.png" /><figcaption>process function</figcaption></figure><p>We need to write a function which will be called when we have to process the <strong>JSON</strong> data coming to the backend using <strong>POST</strong> request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*JaFzDlfYH0LwTwLTOIs2Iw.png" /></figure><p>On line 33, we are declaring a JSON decoder to decode the incoming JSON data from therequest&#39;s body.</p><p>numsData and numsResData are the declared structures.</p><p>The incoming data is stored in numsData and is decoded on line 38.</p><p>Then we set up the ResponseWriter’s headers and then send the <strong>JSON</strong> response on line 47 and check for errors.</p><p>At last, the main function. Here we can define the <strong>HTTP</strong> routing. For every <strong>URL</strong> the respective function can be defined like on line 53. The backend server will run on PORT 8090.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*ug8QMqiNpF9QefRl9uuNuQ.png" /></figure><p>The complete code is below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/187c7990080c9415ca5b2408a1957140/href">https://medium.com/media/187c7990080c9415ca5b2408a1957140/href</a></iframe><h3>Now let’s build the frontend</h3><p>First cd into the frontend directory and install the dependencies using the below command.</p><pre>   npm install --save bootstrap-vue bootstrap axios vee-validate</pre><p>We’ll use axios for handling POST requests, vee-validate for validating the input form data and, bootstrap-vue for pretty interfaces.</p><p>In src/Calculator.vue we have to write the frontend part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*13qy_tphvGcHiOM1wR3KIg.png" /></figure><p>From line 17 to 25, we are defining the input boxes and labels to get the data.v-model is used to get the data in Vue.</p><p>The lines 30–35 define the UI for displaying the calculations and on line 43 a button, which will trigger the postreq() function which we will be defining next.</p><p>In the script tag, we write the <strong>javascript</strong>. First, we’ll import the requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*2oy5ZoqYZVh0bF_iml9onw.png" /><figcaption>writing scripts tag</figcaption></figure><p>Lines 54–59 are the necessary stuff, importing axios and vee-validate.</p><p>Then, we’ll define the variables which we’ll use on lines 64–69. The data variable stores all the variables for the Calculator component.</p><p>In methods, all the functions are defined. We created postreq() function from where we are sending the <strong>POST</strong> request with <strong>JSON</strong> data to the url:<a href="http://localhost:8090/calc.">http://localhost:8090/calc</a> . Remember the calc function we created in server.go file? We are sending the <strong>JSON</strong> data there. After the data is sent, the response from the backend is stored in the result variable, from which we set the add, mul, sub and div variables which are binded to the <strong>HTML</strong> using {{ add }} etc. to show the result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5298394b34872a6870076a2d4ae69d23/href">https://medium.com/media/5298394b34872a6870076a2d4ae69d23/href</a></iframe><p>Pretty simple huh? Yes, it is!</p><p>And that’s all we need to do. Just remember the points.</p><ul><li>Write the server logic in Golang which will run on a separate <strong>PORT</strong>.</li><li>Build structures to hold the <strong>JSON</strong> data. You just can’t store them right away in a variable.</li><li>The Vuejs frontend will communicate to the server using API calls using <strong>GET</strong> or <strong>POST</strong> requests.</li></ul><h3>Run the App</h3><p>The backend server can be run using</p><pre>                        go run server.go</pre><p>It will run on <strong>PORT</strong> 8090.</p><p>The frontend can be run using</p><pre>                          npm run serve</pre><p><strong>Congratulations</strong> <strong>!!!</strong> Your app is ready.</p><p>The whole code is available on the <a href="https://github.com/adesgautam/Calculator">Github repo</a>.</p><p>Also, checkout an app <strong>Rocket Engine Designer,</strong> I built using Vuejs and Golang <a href="https://github.com/adesgautam/Proton">here</a>.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://github.com/adesgautam"><strong>Github</strong></a><strong> </strong><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/adeshgautam/"><strong>Instagram</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53538b6fb918" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Processing using Matlab/Octave — Part 2]]></title>
            <link>https://medium.com/swlh/image-processing-using-matlab-octave-part-2-218627067a5d?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/218627067a5d</guid>
            <category><![CDATA[color-model]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[rgb]]></category>
            <category><![CDATA[matlab]]></category>
            <category><![CDATA[filtering]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 06:01:01 GMT</pubDate>
            <atom:updated>2019-04-12T06:01:01.839Z</atom:updated>
            <content:encoded><![CDATA[<h3>Image Processing using Matlab/Octave — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aDlvs48C-i0ZHPpVOaxbGw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/LOnPLLM4rpQ?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Steve Johnson</a> on <a href="https://unsplash.com/search/photos/art?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>In the previous part we saw what is Image Processing, how it works and some basics of Matlab/Octave. In this part we’ll see color model, some additional functions in Matlab/Octave and how to do basic image enhancement.</blockquote><h3>What is Color Model ?</h3><p>Color model is a mathematical way to represent colors as combination of three or four numbers in a tuple.</p><p>Let’s see some of the color models.</p><p><strong>RGB (Red Green Blue)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*IimAwauEvO3FvWHx-JzsbQ.png" /><figcaption>RGB Color Model</figcaption></figure><p>It is an additive color model in which you can see that the mixture of all primary colors Red, Green and Blue gives white and also you can see Cyan, Magenta and Yellow.</p><p><strong>CMY (Cyan Magenta Yellow)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*kH2InX11jz79iwU5tthNLg.png" /><figcaption>CMY Color Model</figcaption></figure><p>Here mixing all the three of them gives black. This model is widely used in printing but as this black is not pure black so K(Key) is added to complete it as CMYK, where K stands for black.</p><p>Another color model <strong>HSV(Hue Saturation Value)</strong> is also used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*JopIoR0pvjGB7sw19LAHQw.png" /><figcaption><a href="http://gagauznews.md/22463/dualizm-fundamentalnoe-svojstvo-nashego-mira-ili-razvodka.html">Source</a></figcaption></figure><p>Here, you can see that the deeper in the cone towards bottom, the darker is the color(value), on the edges of the cone the color is the brightest (Saturation) and about the circumference you can see different colors (Hue).</p><h3>Additional functions in Matlab/Octave</h3><p>First, we’ll see how to read/write images in Matlab and display them.</p><p><strong>Reading</strong>:</p><pre>                  img = imread(“lena.png”);</pre><p><strong>Writing</strong>:</p><pre>                  imwrite(img, “Lena.png”);</pre><p><strong>Displaying</strong>:</p><pre>                         imshow(img); </pre><p><strong>Image Conversion</strong></p><p>For converting between images there are built-in functions in Matlab, such as:</p><p><strong>RGB → Gray:</strong></p><pre>                  gray_image = rgb2gray(rgb_image);</pre><p><strong>RGB →Binary:</strong></p><pre>                     binary = im2bw(rgb_image);</pre><p><strong>RGB → HSV:</strong></p><pre>                   hsv_image = rgb2hsv(rgb_image);</pre><h3>Image Enhancement</h3><p>The motive of enhancement is to process an image so that the result is more suitable than the original image for a specific application. Image enhancement approaches fall into two broad categories: Spatial domain and Frequency domain.</p><p>In spatial domain the image manipulation is done directly on the pixels of an image. It can be denoted as:</p><pre>                    G(x, y) = T[F(x, y)]</pre><p>where, (x, y) are the coordinates of the pixels, F is the input image, G is the enhanced image and T is an operator on F.</p><p>Now let’s see these operators:</p><ol><li><strong>Image Negative</strong></li></ol><p>The negative of an image is just the subtraction of pixel values from 255 for a gray image. It is of the form:</p><pre>                           N = (L - 1) - I</pre><p>where, L-1 = 255, for gray image and I is the image pixels.</p><p>Now let’s implement this in Matlab:</p><pre>clear all; % clear all variables<br>close all; % close all figures<br>clc;       % clear command window</pre><pre>% import image package<br>pkg load image;</pre><pre>% read image<br>img = imread(“lena.png”);</pre><pre>% convert image into gray and then from uint8 to double<br>grayscale_img = rgb2gray(img);</pre><pre>% show grayscale image<br>figure<br>imshow(grayscale_img);<br>title(“grayscale image”);<br>imwrite(grayscale_img, “original.jpg”);</pre><pre># calculate negative of the image<br>output = 255 — grayscale_img;</pre><pre>% show output image<br>figure<br>imshow(uint8(output));<br>title(“output image”);<br>imwrite(uint8(output), “negative_tansformation.jpg”);</pre><p>The first 3 lines clears the variables in memory, closes all opened windows and clears the terminal.</p><p>Then, we import the image package. If you don’t know how to do this, go <a href="https://octave.sourceforge.io/image/index.html">here</a> and download the package and follow this <a href="https://octave.org/doc/v4.2.1/Installing-and-Removing-Packages.html">tutorial</a>.</p><p>Now image is read and converted to grayscale. After that a new window is created, image is displayed with title “grayscale image” and written as “original.jpg”.</p><p><em>“output”</em> is the negative of the input image and the same displaying and writing is done.</p><p><strong>2. Log Transformation:</strong></p><p>It is done using the following operations:</p><pre>                           s = c log(1+r)</pre><p>where c is a constant.</p><p>It expands the values of dark pixels(near 0) and compresses the higher level values(near 255) i.e., it compresses <a href="https://en.wikipedia.org/wiki/Dynamic_range">dynamic range</a> of an image and the image looks washed out.</p><p>Code:</p><pre>c = 45;<br>output = c * log(1 + grayscale_img);</pre><p><strong>3. Power Law Transformation</strong></p><p>It is also called as Gamma correction. It has the basic form:</p><pre>                             s = c * r^𝛄</pre><p>where c and 𝛄 are constants and r is the input image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*OhrBbrmQU0ilR0iHac9jjg.png" /></figure><p>This is a plot of s versus 𝛄, where 𝛄 &lt; 1 results in dark values and 𝛄 &gt;1 results in bright values.</p><p>Code:</p><pre>r = double(img)/255;<br>c = 1;<br>gamma = 0.6;<br>s = c * (r) .^ gamma;</pre><p><strong>4. Contrast Stretching</strong></p><p>Contrast is a measure of the “range” of an image; i.e. how spread its intensities are.</p><pre>            Contrast = ( Imax — Imin ) / ( Imax + Imin )</pre><p>It maps minimum intensity in the image to the minimum value in the range (0–100) and maximum intensity in the image to the maximum values (200–255). Contrast stretching is all about increasing the difference between the maximum intensity value in an image and the minimum one. All the rest of the intensity values are spread out between this range.</p><p>Code:</p><p>It can be done in just one line of code using <em>imadjust</em>.</p><pre>cs = imadjust(gray_img, stretchlim(gray_img),[]);</pre><p>or doing it using the formula:</p><pre>a      = min(img(:));            %minimum pixel of image X<br>b      = max(img(:));            %maximum pixel of image X <br>cs_img = (img - a) .* (255 / (b - a));</pre><p>Next, we’ll see image filtering using MATLAB/Octave.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://github.com/adesgautam"><strong>Github</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a><strong> </strong><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/adeshgautam/"><strong>Instagram</strong></a></p><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqDjlKFwScoQYQ62DWEdig.png" /></a></figure><h4>This story is published in <a href="https://medium.com/swlh">The Startup</a>, Medium’s largest entrepreneurship publication followed by +442,678 people.</h4><h4>Subscribe to receive <a href="https://growthsupply.com/the-startup-newsletter/">our top stories here</a>.</h4><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouK9XR4xuNWtCes-TIUNAw.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=218627067a5d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/image-processing-using-matlab-octave-part-2-218627067a5d">Image Processing using Matlab/Octave — Part 2</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build an AI to play F1-race]]></title>
            <link>https://medium.com/swlh/build-an-ai-to-play-f1-race-64f078a3fce2?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/64f078a3fce2</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Tue, 05 Mar 2019 07:51:11 GMT</pubDate>
            <atom:updated>2019-03-05T07:51:11.282Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpYwjwbfCiHuomcZ4a73Tg.png" /><figcaption>The F1-race classic</figcaption></figure><blockquote>Really ? an AI to play F1 race game ? Well kind of. This story is more over as a helper guide rather than a tutorial to build the whole system.</blockquote><p>I started it out as a project as an experiment and built some groundwork which you can further improve by contributing.</p><p><a href="https://github.com/adesgautam/AI-race"><strong>Link to the Github repo</strong></a></p><h3><strong>The F1-race game</strong></h3><p>So, lets first talk about the game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*OnC4rPq2R6CVvPzls7BCIg.png" /><figcaption>F1-race gameplay</figcaption></figure><p>The F1-race game was published by <strong>Nintendo</strong>(NES) in 1984.</p><p>The gameplay involves a racing car which can be run on 3 tracks sorted by the difficulty levels 1, 2 and 3.</p><p>The objective is to complete the track within the time frame of 40 seconds. The tracks have some sharp turns and there are some more cars that makes the game a bit interesting.</p><p>There are 4 controls: FORWARD, BACKWARD, LEFT and RIGHT. Combination of two controls like FORWARD-LEFT, FORWARD-RIGHT are also allowed.</p><h3>The Plan</h3><p>We’ll convert the problem into a supervised learning task(<strong>Images -&gt; Labels</strong>).</p><p>The pipeline we’ll build is as such:</p><ol><li>Collect data(game frames and keyboard presses) using emulators.</li><li>Prepare data(crop images and prepare labels).</li><li>Train the <strong>CNN model</strong>.</li><li>Test the predictions.</li><li>Make the model to play the game on emulator.</li></ol><h3><strong>1. Collect Data</strong></h3><p>I’ll use the <strong>OpenEmu</strong> emulator for running the F1-race game on Mac. if you are on another OS you can use <a href="http://www.nintendoemulator.com/nes/4099">this website</a> to run the game in the browser. We’ll use <a href="https://github.com/adesgautam/AI-race/blob/master/grabScreen.py">this script</a> for grabbing game screenshots and simultaneously the keyboard presses.</p><p>Be careful in setting the window area of the game to grab screenshots.</p><p>All of the images will be saved in the <strong>pics1</strong> directory and a <strong>CSV</strong> file will be created with the image path and the keys pressed.</p><p>Try to collect more and more data as possible. I tried with just 10k images.</p><h3>2. Prepare Data</h3><p>Refer to the <a href="https://github.com/adesgautam/AI-race/blob/master/prepare_data.py">script here</a>.</p><p>Here, the images will be cropped for getting only the relevant portion of the images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*LG9dfaokCMSgx7O2Z9l5aA.png" /><figcaption>cropped image</figcaption></figure><p>After that they’ll be resized into 64x64 or 32x32 or your choice of size. Remember that the size of image will reflect upon the computation power used to train the model.</p><p>The labels will be converted into <strong>one-hot encoding</strong>.</p><h3>Training the model</h3><p>Now, we’ll train a <strong>CNN model</strong> on the data we prepared.</p><p><a href="https://github.com/adesgautam/AI-race/blob/master/models.py">This file</a> contains 4 CNN models to experiment with.</p><p>And this script trains the model and plots the <strong>loss</strong> and <strong>accuracy</strong> graph.</p><p>I trained on <strong>10k images</strong> using the <strong>CNN Model2</strong> in the <strong>models.py</strong> file and got <strong>81%</strong> accuracy on testing data with <strong>RGB</strong> images of size <strong>32x32</strong>.</p><h3>Playing the game</h3><p>To play the game refer to <a href="https://github.com/adesgautam/AI-race/blob/master/play.py">this script</a>.</p><p>Remember that <strong>OpenEmu</strong> doesn’t allow direct keyboard inputs from the script to the window. Therefore, we’ll use the browser emulator <a href="http://www.nintendoemulator.com/nes/4099">here</a>.</p><p>Be careful in placing the browser window in appropriate positions for taking screenshots.</p><p>Despite the accuracy I got of about <strong>81%,</strong> the gameplay of the model was not good. It requires a lot of improvement.</p><p>But, I tried to set up a <strong>pipeline</strong> for building the system and also, this can be used for other games where the game problem can be converted into a <strong>supervised learning task</strong>.</p><p>Feel free to fork the <a href="https://github.com/adesgautam/AI-race"><strong>repo</strong></a> and contribute to the project.</p><p>After any further improvements in the model, I’ll present to you the next part of this story.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://github.com/adesgautam"><strong>Github</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a><strong> </strong><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/adeshgautam/"><strong>Instagram</strong></a></p><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqDjlKFwScoQYQ62DWEdig.png" /></a></figure><h4>This story is published in <a href="https://medium.com/swlh">The Startup</a>, Medium’s largest entrepreneurship publication followed by +431,678 people.</h4><h4>Subscribe to receive <a href="https://growthsupply.com/the-startup-newsletter/">our top stories here</a>.</h4><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouK9XR4xuNWtCes-TIUNAw.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64f078a3fce2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/build-an-ai-to-play-f1-race-64f078a3fce2">Build an AI to play F1-race</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django + Angular 4 = A powerful web application]]></title>
            <link>https://medium.com/swlh/django-angular-4-a-powerful-web-application-60b6fb39ef34?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b6fb39ef34</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 12:51:48 GMT</pubDate>
            <atom:updated>2018-10-17T13:19:03.071Z</atom:updated>
            <content:encoded><![CDATA[<h3>Django + Angular = A powerful web application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HMSlMmFggjckpURl" /></figure><blockquote>You know how to use Django to make web apps and also, you know how to build beautiful frontends using Angular but you were probably wondering how to integrate them with each other to build a single web app that has benefits of both?</blockquote><p>This was the thing that was going in my head when I was learning <strong>Django</strong> and <strong>Angular 4</strong>. I wanted both of them in the same application so that I would be having the power of python and goodness of Angular and without learning node.js separately to make a full-fledged Web App. And, I think, you reading this story also have the same motive.</p><h3>Let’s Start</h3><p>A little background first.</p><p>Django is an all in one pack having various features and functionalities. It is:</p><ol><li>Fast — It is designed for developers such as to be as fast as possible, helping to make it cost-effective and efficient.</li><li>Lots of features — Many extras like user authentication, content administration, RSS feeds etc.</li><li>Secure — A lot of security features to prevent attacks like SQL injection and cross-site scripting.</li><li>Scalable — It can bear heavy traffic demand making it a good fit for busy websites.</li></ol><p>Along with all this, it has python, I mean do I have to tell how much good is that? 😉</p><p>But then why we are trying to use Angular along with that?</p><p>Because, it is Cross-Platform, fast, helps us to make beautiful UI and the list goes on. For more read<a href="https://angular.io/features"> here</a>.</p><p>And, also the Django template system sucks! Angular could help build a scalable, clean and a single page web application.</p><p>Enough of the talks. Let’s build one ourselves.</p><h3>Setting up Directories</h3><ol><li>Create a directory for our application.</li></ol><pre>                     mkdir my-app &amp;&amp; cd my-app</pre><p>2. Create two separate folders for our backend(Django) and the frontend(Angular 4)</p><pre>                   mkdir backend &amp;&amp; mkdir frontend</pre><h3>Setting up Django</h3><ol><li>First, download <a href="https://github.com/heroku/heroku-django-template">this</a> repo as zip file and copy it to the backend directory. This zip file has the template which is ready for <strong>Heroku</strong> deployment. So, deploying on Heroku is hassle free now.</li><li>Unzip and rename the folder to your choice of the app name.</li><li>In the folder there is another folder, also change its name to your choice, let’s suppose it as “my-app”</li><li>Rename all the instances of “my-app” (without quotes) with your app name in the following files:</li></ol><p>a. Procfile</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*EetI5uzEGboWRxWOoBy7XA.png" /><figcaption>Procfile</figcaption></figure><p>b. manage.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*ZPktwDXcCkxDY5De-xBQGg.png" /><figcaption>manage.py</figcaption></figure><p>c. my-app/wsgi.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*g97HvzK1b7SQQnq1x8zr3Q.png" /><figcaption>wsgi.py</figcaption></figure><p>d. my-app/settings.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*2edMVk8xrPfjIYRLGyCKOg.png" /><figcaption>settings.py</figcaption></figure><p>4. Now create a new app in Django</p><pre>                 python3 manage.py startapp new_app</pre><p>5. A “new_app” named project will be created in the current directory.</p><p>6. We’ll be using the <strong>DRF (Django REST Framework) </strong>for setting up the APIs in our Django app to connect with Angular. Read more about DRF <a href="http://www.django-rest-framework.org/">here</a>.</p><p>Create a new file “serializers.py” (without quotes) in the “new_app” folder. To correctly use the DRF head on <a href="https://www.django-rest-framework.org/tutorial/quickstart/">here</a>.</p><p>You could change the serializers.py according to the models you have defined in the “models.py” file. We’ll make a dummy model.</p><p>The models.py file should look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f4d8146d425dc7a3a0d91a3f0acf454/href">https://medium.com/media/3f4d8146d425dc7a3a0d91a3f0acf454/href</a></iframe><p>The “serializers.py” file should look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50aad136c31fd48d8eae7d0fe3e12e05/href">https://medium.com/media/50aad136c31fd48d8eae7d0fe3e12e05/href</a></iframe><p>Also, don’t forget to update the <strong>settings.py</strong> file by adding the <strong>“new_app”</strong> and <strong>“rest_framework”</strong> and some more necessary changes (See lines 31–41 below).</p><p>Update the file as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*F-WQylwKF1j7bt_a7zXIBQ.png" /><figcaption>settings.py</figcaption></figure><p>The <strong>settings.py</strong> file needs to be updated to use the templates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*FNGbXfWf9wRDB1-d3VpKIg.png" /><figcaption>settings.py</figcaption></figure><p>Now, create a new folder “templates” and a file <strong>“home.html”</strong>. Copy the below contents to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e89f6d52288b81bec17815ecd15db489/href">https://medium.com/media/e89f6d52288b81bec17815ecd15db489/href</a></iframe><p>So, this is an important thing that you need to remember. The <strong>“home.html”</strong> will use the CSS and Javascript files that Angular will generate every time you will change the Angular app, named:</p><p>a. styles.css</p><p>b. runtime.js</p><p>c. polyfills.js</p><p>d. main.js</p><p>A point to remember here is that in order to work with Angular, on the Django part we’ll create a home URL as defined below on line 9 and the other URLs will be the REST API which the Angular part will use to connect to Django.</p><p>Remember that, the Angular part(frontend) will talk to the Django(backend) using these REST APIs defined in the “urls.py” file.</p><p>Now, change the <strong>“urls.py”</strong> file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffc870416dcbc31e5e03975597ac3504/href">https://medium.com/media/ffc870416dcbc31e5e03975597ac3504/href</a></iframe><p>Change the <strong>“views.py”</strong> as follows. The DRF is being used to handle GET request. Here, we are just returning all the data stored in the database as a JSON response.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01289bd73dcfa083ec2bfa7619780121/href">https://medium.com/media/01289bd73dcfa083ec2bfa7619780121/href</a></iframe><p>You’ll also need to update the “requirements.py” file by adding DRF to it, only required when deploying to Heroku.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*ke395akt65fNfZMHBnRkVA.png" /><figcaption>requirements.py</figcaption></figure><p>Now, this is the bare bones Django setup you’ll need.</p><p>This is pretty simple, right? Just set up the Django project and add DRF.</p><h3>Setting up Angular 4</h3><p>Now, let’s do the Angular part.</p><ol><li>Go to the frontend directory, and start a new Angular 4 app.</li></ol><pre>                         ng new my-app</pre><p>2. Now, this is the bare bone Angular app, but, we need to use Django as the backend.</p><p>So, the idea is that <strong>DRF</strong> will help us to make APIs(we have defined those URLs earlier in the “urls.py” file) which the Angular app will utilize using <strong>HTTP</strong> requests. We are replacing Node.js here with Django.</p><p>MEAN(Mongo, Express.js, Angular, Node.js) stack is now MAD(Mongo, Angular, Django) stack. But, in this app, we are just using the SQLite database, just for simplicity.</p><p>3. Go to <strong>this</strong> repository to see all the changes that the Angular app needs. I’ll point out the necessary ones here.</p><p>First, we’ll see the <strong>“app.router.js”</strong> file. You can see that on line 13, a <strong>“PageNotfoundComponent”</strong> is being used to handle the 404 Page not found errors. In Django, this was an in-built feature but now here we need to implement it ourselves.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5160cedc32fc9c5e3bd076619b8d6922/href">https://medium.com/media/5160cedc32fc9c5e3bd076619b8d6922/href</a></iframe><p>4. In the <strong>“app.module.ts”</strong> import the HttpModule and AppRoutingModule.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d432238e16f28e5887862e34287a42be/href">https://medium.com/media/d432238e16f28e5887862e34287a42be/href</a></iframe><p>5. And, else just is the regular Angular stuff.</p><p>All of the source code is on my Github repository. Find it at the bottom.</p><h3><strong>Run the project</strong></h3><p>To run the Django server, just run</p><pre>                    python manage.py runserver</pre><p>And run the Angular app,</p><pre>ng build --prod --output-path /path-to your-project-directory/backend/my-app-name/my-app/static/ang --watch --output-hashing none</pre><p><strong>prod</strong> is used for generating production-ready version of the app</p><p><strong>output-path</strong> is the directory where we are placing the Angular App. We are placing the files in the <strong>static</strong> folder of Django as these files will be served as static files.</p><p><strong>watch</strong> tell to constantly look for changes in the Angular App you make and then immediately compile and place them in the output-path directory</p><p><strong>hashing none </strong>removes the hashes generated in the <strong>styles.css, runtime.js</strong>, <strong>polyfills.js </strong>and<strong> main.js </strong>file names.</p><p>And that’s all you need to do. Remember the steps:</p><ol><li>Create a Django project.</li><li>Use <strong>DRF</strong> or <strong>tastypie</strong> or any other API framework of your choice.</li><li>Remember to define your API in <strong>urls.py</strong> file.</li><li>Create an Angular app.</li><li>Handle the error pages like 404.</li><li>Create <strong>HTTP</strong> requests to the API you created for getting and sending data.</li><li>Done!</li></ol><p>Congratulations !!! You now know how to use the power of Django + Angular to build powerful apps.</p><p>The code for above: <a href="https://github.com/adesgautam/dj-angular">Github repo link</a>.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/adeshgautam/"><strong>Instagram</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a><strong> </strong><a href="https://github.com/adesgautam"><strong>Github</strong></a></p><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqDjlKFwScoQYQ62DWEdig.png" /></a></figure><h4>This story is published in <a href="https://medium.com/swlh">The Startup</a>, Medium’s largest entrepreneurship publication followed by + 379,306 people.</h4><h4>Subscribe to receive <a href="http://growthsupply.com/the-startup-newsletter/">our top stories here</a>.</h4><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouK9XR4xuNWtCes-TIUNAw.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b6fb39ef34" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/django-angular-4-a-powerful-web-application-60b6fb39ef34">Django + Angular 4 = A powerful web application</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Reinforcement Learning (Coding Q-Learning) — Part 3]]></title>
            <link>https://medium.com/swlh/introduction-to-reinforcement-learning-coding-q-learning-part-3-9778366a41c0?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/9778366a41c0</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[q-learning]]></category>
            <category><![CDATA[gym]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Mon, 09 Jul 2018 12:20:40 GMT</pubDate>
            <atom:updated>2018-12-22T05:58:47.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7aTsPF6H4xFneBod8UOUcw.jpeg" /><figcaption>Talk is cheap. Show me the code — Linus Torvalds</figcaption></figure><blockquote>In the previous part, we saw what an MDP is and what is Q-learning. Now in this part, we’ll see how to solve a finite MDP using Q-learning and code it.</blockquote><h3>OpenAI gym</h3><p>As stated on the <a href="https://gym.openai.com/">official website</a> of OpenAI gym:</p><blockquote>Gym is a toolkit for developing and comparing reinforcement learning algorithms.</blockquote><p>We’ll use this toolkit to solve the <a href="https://gym.openai.com/envs/FrozenLake-v0">FrozenLake</a> environment. There are a wide variety of games available like the Atari 2600 ones, text based games etc. Check out all of them <a href="https://gym.openai.com/envs/">here</a>.</p><h3>Installation</h3><p>Install gym using the steps provided <a href="https://github.com/openai/gym">here</a>. First install the gym library then, the OS specific packages.</p><p>Now, let’s see how to use gym toolkit.</p><p>Import gym using:</p><pre>import gym</pre><p>Then, specify the game you want to use, we’ll use the FrozenLake game.</p><pre>env = gym.make(&#39;FrozenLake-v0&#39;)</pre><p>The environment of the game can be reset to the default/initial state using:</p><pre>env.reset()</pre><p>And, to see the game GUI, use:</p><pre>env.render()</pre><p>The official documentation can be found <a href="http://gym.openai.com/docs/">here</a> where you can see the detailed usage and explanation of gym toolkit.</p><h3>FrozenLake Game</h3><p>Now, lets see what is the FrozenLake game.</p><p>Imagine, you are standing on a frozen lake. The lake is not all frozen, there are some parts where the ice is very thin. You goal is to go from place S to G without falling into the holes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*Qp14HWQfOeE2UoSxrxCxAg.png" /><figcaption><a href="https://www.google.co.in/url?sa=i&amp;rct=j&amp;q=&amp;esrc=s&amp;source=images&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjnpe-owY_cAhUGVH0KHVyTAYAQjRx6BAgBEAU&amp;url=https%3A%2F%2Fanalyticsindiamag.com%2Fopenai-gym-frozen-lake-beginners-guide-reinforcement-learning%2F&amp;psig=AOvVaw095bfUMvJGKysgeHZjz6ZT&amp;ust=1531139425155647">Source</a></figcaption></figure><p>Here, S is the starting point, G is the goal, F is the solid ice where the agent can stand and H is the hole where if the agent goes, it falls down.</p><p>The agent has 4 possible moves which are represented in the environment as 0, 1, 2, 3 for left, right, down, up respectively.</p><p>For every state F, the agent gets 0 reward, for state H it gets -1 reward as in state H the agent will die and upon reaching the goal, the agent gets +1 reward.</p><p>The game upon rendering in the terminal looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Zf_ozFRh4ZqhOI-RfkZfxA.gif" /><figcaption>FrozenLake-v0</figcaption></figure><p>The states here are F, S and G. That is there are 4x4=16 states and 4 actions.</p><p>To solve this game using Q-learning we’ll make use of the theory we saw in the <a href="https://medium.com/@adeshg7/introduction-to-reinforcement-learning-part-2-74e0a3fad9d3">previous part</a>.</p><p>This is the code for solving the “FrozenLake-v0” environment using Q-learning. It is pretty straight-forward and you’ll feel comfortable with it till the end of the post.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/778fac84f7a921ff8ddebb003cbd3ebf/href">https://medium.com/media/778fac84f7a921ff8ddebb003cbd3ebf/href</a></iframe><p>Let’s dissect it.</p><p>Lines 1–3 are importing the libraries we’ll use. <strong>Numpy</strong> for storing the Q-table and <strong>pickle</strong> to save our Q-table as “pkl” file.</p><p>Line 5 initializes out FrozenLake environment.</p><p>Lines 7–12 initializes our variables. <strong><em>epsilon</em></strong> for the epsilon-greedy approach, <strong><em>gamma</em></strong> is the discount factor, <strong><em>max_episodes</em></strong> is the maximum amount of times we’ll run the game, <strong><em>max_steps</em></strong> is the maximum steps we’ll run for every episode and <strong><em>lr_rate</em></strong> is the learning rate.</p><p>Line 14 initializes our Q-table as a 16x4 matrix filled with zeros. <strong><em>env.observation-space.n</em></strong> tells the total number of states in the game and <strong><em>env.action-space.n</em></strong> tells the total number of actions.</p><p>On line 30, we start running the episodes.</p><p>On line 31, the variable <strong><em>state</em></strong> stores the initial state using <strong><em>env.reset()</em></strong>.</p><p>On Line 32, <strong><em>t</em></strong> is used for storing the number of time steps.</p><p>Using line 35, the environment is rendered.</p><p>On line 37 the appropriate action is chosen. This is done using the <strong><em>epsilon-greedy</em></strong> approach. See the lines 16–22, here we randomly generate a number between 0 and 1 and see if it’s smaller than epsilon. If it’s smaller, then a random action is chosen using <strong><em>env.action_space.sample()</em></strong> and if it’s greater then we choose the action having the maximum value in the Q-table for state: <strong><em>state</em></strong>. Eg:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*gi3FZfY0AG8nHrSxksS4qw.png" /><figcaption>State 10 with q values</figcaption></figure><p>Suppose, for the actions 0–3 in state 10, it has the values 0.33, 0.34, 0.79 and 0.23. The maximum Q-value is 0.79, for the action 2 and this action 2 is chosen for state 10.</p><p>On line 39, the action we chose is taken in the environment and the next state, reward for the action are returned. <strong><em>done</em></strong> returns true if the episode has terminated and <strong><em>info</em></strong> stores the extra information that is used for debugging.</p><p>At this point we have:</p><p>1. The previous state, <strong><em>state</em></strong>.</p><p>2. The next state, <strong><em>state2.</em></strong></p><p>3. And the <strong><em>action</em></strong> and <strong><em>reward</em></strong> for the <strong><em>state2</em></strong>.</p><p>On line 41, we use the above information to update our Q-table using the function <strong><em>learn(state, state2, reward, action) </em></strong>by the following equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Lq_5xHxRdXRBlYIBCEssg.png" /><figcaption>Q-value updation equation</figcaption></figure><p>After updating the Q-table, we set the previous state, <strong><em>state</em></strong> as the current state, <strong><em>state2 </em></strong>on line 43.</p><p>The time-steps are increased on Line 45. Line 47–48 checks if done is true that is, if the episode is finished.</p><p>On lines 54 and 55 we save our Q-table into <em>“frozenlake_qTable.pkl” file.</em></p><p>And that’s it. Feel free to play around with the code.</p><h3>FrozenLake in action</h3><p>Running the code above you’ll see the game in action. But, please be patient as it’ll take some time for 10000 episodes to finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*jQOFmSzotNW4p4U2g19GkA.gif" /><figcaption>Agent in action</figcaption></figure><p>You can load the Q-table afterwards and play the game using the code below. It’s fairly simple. Only the training part is removed from the code below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbab063925e0ca045d17c11b3b84f354/href">https://medium.com/media/fbab063925e0ca045d17c11b3b84f354/href</a></iframe><p>Stay tuned for more fun with Reinforcement Learning. Happy exploring 😄.</p><p>Please click on the 👏 button if you liked the post and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://twitter.com/gautamades"><strong>Twitter</strong></a><strong> </strong><a href="https://www.instagram.com/adeshgautam/"><strong>Instagram</strong></a><strong> </strong><a href="https://www.linkedin.com/in/adesh-gautam-518810127/"><strong>LinkedIn</strong></a><strong> </strong><a href="https://github.com/adesgautam"><strong>Github</strong></a></p><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqDjlKFwScoQYQ62DWEdig.png" /></a></figure><h4>This story is published in <a href="https://medium.com/swlh">The Startup</a>, Medium’s largest entrepreneurship publication followed by 343,876+ people.</h4><h4>Subscribe to receive <a href="http://growthsupply.com/the-startup-newsletter/">our top stories here</a>.</h4><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouK9XR4xuNWtCes-TIUNAw.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9778366a41c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-to-reinforcement-learning-coding-q-learning-part-3-9778366a41c0">Introduction to Reinforcement Learning (Coding Q-Learning) — Part 3</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Read/Write on external HDD with NTFS partition on macOS]]></title>
            <link>https://medium.com/swlh/how-to-read-write-on-external-hdd-with-ntfs-partition-on-macos-2aa2db1f8a5?source=rss-d90d6240dcbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aa2db1f8a5</guid>
            <category><![CDATA[mount]]></category>
            <category><![CDATA[ntfs-3g]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[ntfs]]></category>
            <category><![CDATA[mac]]></category>
            <dc:creator><![CDATA[Adesh Gautam]]></dc:creator>
            <pubDate>Thu, 05 Jul 2018 09:47:27 GMT</pubDate>
            <atom:updated>2018-07-05T10:02:43.824Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9wHrewC1Dyf2Au_qEqwWcg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/B3l0g6HLxr8?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Blake Connally</a> on <a href="https://unsplash.com/search/photos/mac-code?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This is a <strong>how-to</strong> for using <strong>NTFS</strong> formatted external HDD on MacOS using free tools available.</p><p>MacOS doesn’t provide write permissions on NTFS format as default. So to mount external drives as Read/Write follow the given steps below:</p><h3><strong>Step 1</strong></h3><p>Download <strong>FUSE</strong> for macOS from <a href="https://sourceforge.net/projects/osxfuse/files/latest/download">here</a></p><h3>Step 2</h3><p>Then we have to install xcode command line tools. For this open terminal and copy paste this.</p><pre>xcode-select --install</pre><p>Then click <strong>install </strong>when the dialogue appears. Click <strong>Agree </strong>when the<strong> </strong>License Agreement appears. Once that’s done proceed to step 3.</p><h3><strong>Step 3</strong></h3><p>Now we have to install <strong>Homebrew</strong> which is a package manager for macOS. Copy and paste the following in the terminal.</p><pre>ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</pre><h3>Step 4</h3><p>Paste the following in terminal to install ntfs-3g for mac:</p><p>brew install ntfs-3g</p><h3>Step 5</h3><p>Now connect your external HDD system and follow the below steps:</p><p>a) diskutil list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*st3jLBOUQxVGapEfraPCOA.png" /><figcaption>diskutil list</figcaption></figure><p>This will list all the connected drives to your device. There will be the names such as disk2s1, disk2s1 etc. These are the partitions of your external HDD.</p><p>Note the names of the External HDD drives.</p><p>b) sudo mkdir /Volumes/NTFS1</p><p>We have to create a folder for giving a mount point to the disks. This command will create <strong>NTFS1</strong> folder for mounting. If you are trying to mount 2 partitions of your HDD then make another folder using:</p><p>sudo mkdir /Volumes/NTFS2</p><p>The number of folders will depend on the number of drives you want to mount.</p><p>c) sudo umount /dev/disk2s1</p><p>This command will unmount the disks already mounted by the macOS system as we will again mount them by ntfs-3g in RW mode. Again if there are 2 partitions mounted then use:</p><p>sudo umount /dev/disk2s2</p><p><strong>disk2s1 </strong>and <strong>disk2s2</strong> are the names of the disks.</p><p>d) Run the below in terminal to mount the disk named as disk2s1 to the pre created folder NTFS1 in RW mode.</p><p>sudo /usr/local/bin/ntfs-3g /dev/disk2s1 /Volumes/NTFS1 -olocal -oallow_other</p><p>Congratulations you are done !</p><p>So lets say you have 2 partitions on your HDD formatted as NTFS, then you will be using the following commands in sequence on terminal.</p><ol><li>diskutil list</li><li>sudo mkdir /Volumes/NTFS1</li><li>sudo mkdir /Volumes/NTFS2</li><li>sudo umount /dev/disk2s1</li><li>sudo umount /dev/disk2s2</li><li>sudo /usr/local/bin/ntfs-3g /dev/disk2s1 /Volumes/NTFS1 -olocal -oallow_other</li><li>sudo /usr/local/bin/ntfs-3g /dev/disk2s2 /Volumes/NTFS2 -olocal -oallow_other</li></ol><p>After this the two drives will be mounted in RW mode on your system.</p><p>This is a manual process which needs to be done every time when you’ll connect your external HDD to the system.</p><h3>Auto mount the NTFS volumes in RW mode</h3><blockquote>This is not recommended as this will involve the replacement of the Apple’s NTFS mount tool /sbin/mount_ntfs. This will present a security risk for the system.</blockquote><p>For replacing the ntfs-3g tool with the Apple’s NTFS mount tool execute the following commands in the terminal. The following commands needs to be executed in the <strong><em>recovery mode</em></strong>. To go into the <strong><em>recovery mode</em></strong> press <em>command+R</em> when the system boots. When in recovery mode go to Utilities and then click on Terminal and enter the following:</p><p>sudo mv &quot;/Volumes/Macintosh HD/sbin/mount_ntfs&quot; &quot;/Volumes/Macintosh HD/sbin/mount_ntfs.orig&quot;</p><p>sudo ln -s /usr/local/sbin/mount_ntfs &quot;/Volumes/Macintosh HD/sbin/mount_ntfs&quot;</p><h3>Uninstallation</h3><p>To uninstall ntfs-3g execute following in terminal:</p><p>brew uninstall ntfs-3g</p><p>And to restore the Apple’s NTFS mount tool again go to <em>recovery</em> and enter following in the terminal:</p><p>sudo mv &quot;/Volumes/Macintosh HD/sbin/mount_ntfs.orig&quot; &quot;/Volumes/Macintosh HD/sbin/mount_ntfs&quot;</p><p>This was quite a long process but it involves free tools,but if you want to use a straightforward method then use the Paragon NTFS software which costs $19.95.</p><p><strong>The list of commands is provided in the repository </strong><a href="https://github.com/adesgautam/how_to_RW_on_external_hdd_on_macOS/tree/master"><strong>here</strong></a><strong>.</strong></p><p>Please click on the 👏 button if you liked it and hold it for giving more love.</p><p>If you wish to connect:</p><p><a href="https://twitter.com/gautamades">Twitter</a> <a href="https://www.instagram.com/adeshgautam/">Instagram</a> <a href="https://www.linkedin.com/in/adesh-gautam-518810127/">LinkedIn</a> <a href="https://github.com/adesgautam">Github</a></p><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqDjlKFwScoQYQ62DWEdig.png" /></a></figure><h4>This story is published in <a href="https://medium.com/swlh">The Startup</a>, Medium’s largest entrepreneurship publication followed by 340,876+ people.</h4><h4>Subscribe to receive <a href="http://growthsupply.com/the-startup-newsletter/">our top stories here</a>.</h4><figure><a href="https://medium.com/swlh"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouK9XR4xuNWtCes-TIUNAw.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aa2db1f8a5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-read-write-on-external-hdd-with-ntfs-partition-on-macos-2aa2db1f8a5">How to Read/Write on external HDD with NTFS partition on macOS</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>