<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Yoke Keong</title><link>https://yokekeong.com/blog/python/</link><description>Recent content in Python on Yoke Keong</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 15 Aug 2019 12:00:52 +0000</lastBuildDate><atom:link href="https://yokekeong.com/blog/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Dim Sum Classifier – from Data to App part 2</title><link>https://yokekeong.com/dim-sum-classifier-from-data-to-app-part-2/</link><pubDate>Thu, 15 Aug 2019 12:00:52 +0000</pubDate><guid>https://yokekeong.com/dim-sum-classifier-from-data-to-app-part-2/</guid><description>&lt;p&gt;&lt;em&gt;Picture Credits&lt;/em&gt; &lt;a href="https://www.wallpaperflare.com/vibrant-shot-of-feasting-on-chinese-steamed-and-fried-dim-sum-wallpaper-aaubx"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;In the previous &lt;a href="https://yokekeong.com/dim-sum-classifier-from-data-to-app-part-1"&gt;post&lt;/a&gt;, we see how we can acquire data, process, clean and train an Image Classifier to identify some yummy dim sums.&lt;/p&gt;&#10;&lt;p&gt;In this post, we shall look at completing the loop by developing the web app using &lt;a href="https://www.starlette.io/"&gt;starlette&lt;/a&gt; (a framework similar to that of flask but supports asynchronous IO), setting up and automating deployment of our web app with Github, Docker contanier and &lt;a href="https://render.com/"&gt;Render&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;The very helpful &lt;a href="https://course.fast.ai/"&gt;fast.ai course&lt;/a&gt; team and community has given us a quick start with the following resources:&lt;/p&gt;</description></item><item><title>Dim Sum Classifier - from Data to App part 1</title><link>https://yokekeong.com/dim-sum-classifier-from-data-to-app-part-1/</link><pubDate>Tue, 13 Aug 2019 12:00:07 +0000</pubDate><guid>https://yokekeong.com/dim-sum-classifier-from-data-to-app-part-1/</guid><description>&lt;p&gt;&lt;em&gt;Picture Credits&lt;/em&gt; &lt;a href="https://www.wallpaperflare.com/vibrant-shot-of-feasting-on-chinese-steamed-and-fried-dim-sum-wallpaper-aaubx"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;In a typically machine learning lifecycle, we will need to acquire data, process data, train and validate/test models and finally deploy the trained models in applications/services. In this first part of two post, inspired by fast.ai 2019 &lt;a href="https://github.com/fastai/course-v3/blob/master/nbs/dl1/lesson2-download.ipynb"&gt;lesson 2&lt;/a&gt;, we shall build a &lt;a href="https://en.wikipedia.org/wiki/Dim_sum"&gt;Dim Sum&lt;/a&gt; (a Cantonese bite-size style of cuisine with many yummy choices) classifier application by leveraging on Google Images as a data source.&lt;/p&gt;&#10;&lt;p&gt;Due to the wide variety of choices, we shall focus on 5 common dim sum dishes below, with links for your interest:&lt;/p&gt;</description></item><item><title>Rock, paper, scissors - vision transfer learning with fast.ai</title><link>https://yokekeong.com/rock-paper-scissors-vision-transfer-learning-with-fast-ai/</link><pubDate>Wed, 07 Aug 2019 12:00:00 +0000</pubDate><guid>https://yokekeong.com/rock-paper-scissors-vision-transfer-learning-with-fast-ai/</guid><description>&lt;p&gt;&lt;em&gt;Picture Credits:&lt;/em&gt; &lt;a href="https://en.wikipedia.org/wiki/Rock_paper_scissors"&gt;&lt;em&gt;Wikipedia&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;In the previous &lt;a href="https://yokekeong.com/serving-rock-paper-scissors-image-classifier-app-built-with-tensorflow-2-keras-and-flask"&gt;post&lt;/a&gt;, we used the Rock, Paper Scissors &lt;a href="https://github.com/yoke2/rps_tf2_flask_app/blob/master/misc/notebook/rock_paper_scissors_tf2b_colab.ipynb"&gt;notebook&lt;/a&gt; that trained a custom image classification model from scratch.&lt;/p&gt;&#10;&lt;p&gt;While the notebook is demonstrates building custom layers, for such a task, we can also leverage on Transfer Learning using models trained on similar image classification tasks that can often reduce time in training and experimentation and yet achieve results fairly good results, which will be shown here using the &lt;a href="https://github.com/fastai/fastai"&gt;fastai v1&lt;/a&gt; library as demonstrated by Jeremy Howard in his awesome &lt;a href="https://course.fast.ai/"&gt;Practical Deep Learning for Coders&lt;/a&gt; 2019 course.&lt;/p&gt;</description></item><item><title>Serving Rock, Paper, Scissors Image Classifier App built with Tensorflow 2, Keras and Flask</title><link>https://yokekeong.com/serving-rock-paper-scissors-image-classifier-app-built-with-tensorflow-2-keras-and-flask/</link><pubDate>Mon, 05 Aug 2019 12:00:00 +0000</pubDate><guid>https://yokekeong.com/serving-rock-paper-scissors-image-classifier-app-built-with-tensorflow-2-keras-and-flask/</guid><description>&lt;p&gt;&lt;em&gt;Picture Credits:&lt;/em&gt; &lt;a href="https://pixabay.com/vectors/interface-internet-program-browser-3614766/"&gt;&lt;em&gt;Pixabay&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;In this post, we shall be looking at serving a Tensorflow 2 Keras image classification model with a Flask app.&lt;/p&gt;&#10;&lt;p&gt;We shall be leveraging on the &lt;a href="https://github.com/lmoroney/io19/blob/master/Zero%20to%20Hero/Rock-Paper-Scissors.ipynb"&gt;Rock Paper Scissors Tensorflow 2 Notebook&lt;/a&gt; created by &lt;a href="http://laurencemoroney.com/"&gt;Laurence Moroney&lt;/a&gt; and built on the Image Classifier App template provided by &lt;a href="https://github.com/mtobeiyf"&gt;Fing&lt;/a&gt; on the Github repository &lt;a href="https://github.com/mtobeiyf/keras-flask-deploy-webapp"&gt;here&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h3 id="training-and-saving-the-model-in-google-colab"&gt;Training and saving the Model in Google Colab&lt;/h3&gt;&#10;&lt;p&gt;To train the model, we can run the aforementioned Jupyter Notebook on &lt;a href="https://colab.research.google.com/"&gt;Google Colab&lt;/a&gt;. To train the model successfully, we will need to ensure that Tensorflow 2 beta is installed with the following command:&lt;/p&gt;</description></item><item><title>Find version of python package installed</title><link>https://yokekeong.com/find-version-of-python-package-installed/</link><pubDate>Thu, 04 Aug 2016 11:00:52 +0000</pubDate><guid>https://yokekeong.com/find-version-of-python-package-installed/</guid><description>&lt;p&gt;Below are 3 methods we can try to find the version of an installed python package. We shall use &lt;code&gt;scipy&lt;/code&gt; as an example.&lt;/p&gt;&#10;&lt;h3 id="using-pip"&gt;Using pip&lt;/h3&gt;&#10;&lt;p&gt;Method 1 - For pip 1.3 and above: &lt;code&gt;pip show scipy&lt;/code&gt;&lt;/p&gt;&#10;&lt;p&gt;Method 2 - Alternative (works with older versions of pip): &lt;code&gt;pip freeze | grep scipy&lt;/code&gt;&lt;/p&gt;&#10;&lt;h3 id="using-version-attribute"&gt;Using &lt;strong&gt;version&lt;/strong&gt; attribute&lt;/h3&gt;&#10;&lt;p&gt;Method 3 - Launch python/ipython, then execute the commands below:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;1&lt;/span&gt;&lt;span&gt;import scipy&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;2&lt;/span&gt;&lt;span&gt;scipy.__version__&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Reference for Method 1 is &lt;a href="http://stackoverflow.com/questions/10214827/find-which-version-of-package-is-installed-with-pip"&gt;here&lt;/a&gt;. Reference for Method 2 is &lt;a href="https://davidwalsh.name/python-package-version"&gt;here&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Getting session information in Python</title><link>https://yokekeong.com/getting-session-information-in-python/</link><pubDate>Tue, 07 Jul 2015 11:00:08 +0000</pubDate><guid>https://yokekeong.com/getting-session-information-in-python/</guid><description>&lt;p&gt;We&amp;rsquo;ve gone through how to get session information in R &lt;a href="https://yokekeong.com/getting-session-information-in-r/"&gt;previously&lt;/a&gt;, so how do we do the same for Python? It seems that there is no single convenient function available so here&amp;rsquo;s one approach.&lt;/p&gt;&#10;&lt;p&gt;To get the system information, you can utilize the commonly used IPython package:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#d8dee9;background-color:#2e3440;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;1&lt;/span&gt;&lt;span&gt;&lt;span style="color:#81a1c1;font-weight:bold"&gt;import&lt;/span&gt; &lt;span style="color:#8fbcbb"&gt;IPython&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#6c6f74"&gt;2&lt;/span&gt;&lt;span&gt;IPython&lt;span style="color:#81a1c1"&gt;.&lt;/span&gt;sys_info&lt;span style="color:#eceff4"&gt;()&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To find out packages that have been loaded at the time (includes modules loaded by Python itself and by any Python IDE), you can utilize the &lt;code&gt;sys.modules.keys()&lt;/code&gt; method. The code below gets the package name rather than the sub-components.&lt;/p&gt;</description></item><item><title>Data Science Learning - A Cross Reference</title><link>https://yokekeong.com/data-science-learning-a-cross-reference/</link><pubDate>Tue, 17 Feb 2015 11:00:12 +0000</pubDate><guid>https://yokekeong.com/data-science-learning-a-cross-reference/</guid><description>&lt;p&gt;While learning data science, I&amp;rsquo;ve discovered that it is very useful to think of the data science processing as a &amp;ldquo;pipeline&amp;rdquo; i.e. a series of actions in a process. Along this pipeline, you will be tackling lots of &amp;ldquo;How do I&amp;hellip;&amp;rdquo; questions like &amp;ldquo;How do I remove NA values?&amp;rdquo; and &amp;ldquo;How do I create N-grams?&amp;rdquo;&lt;/p&gt;&#10;&lt;p&gt;Furthermore, given the many data science tools and languages available online, you will most likely ask the same questions again when you are learning how to perform data science tasks in another language. While Google Search and Stack Overflow/Stack Exchange comes in very handy when searching for answers, I wanted some structure - a collection of sorts - to these questions and have working examples in different language implementations.&lt;/p&gt;</description></item><item><title>A virtual environment for data science</title><link>https://yokekeong.com/a-virtual-environment-for-data-science/</link><pubDate>Tue, 13 Jan 2015 11:00:23 +0000</pubDate><guid>https://yokekeong.com/a-virtual-environment-for-data-science/</guid><description>&lt;p&gt;I wanted to conveniently use data science tools without the hassle of installing the required languages and packages, while benefiting from the strengths of the Linux command line tools. There is a pre-packaged VM called the &lt;a href="http://datasciencetoolbox.org/"&gt;Data Science Toolbox&lt;/a&gt; that fills this need.&lt;/p&gt;&#10;&lt;p&gt;It comes with R and Python installed, along with the respective popular data analysis packages for R and Python. You will be able to install the VM successfully by following the instructions on the &lt;a href="http://datasciencetoolbox.org/"&gt;website&lt;/a&gt;, including installation of pre-requisites like VirtualBox and Vagrant.&lt;/p&gt;</description></item></channel></rss>