<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Usama Subhani</title>
    <description>The latest articles on DEV Community by Usama Subhani (@usamasubhani).</description>
    <link>https://dev.to/usamasubhani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F377013%2F2d259bea-7f09-4280-954f-ad1a89af42a9.jpg</url>
      <title>DEV Community: Usama Subhani</title>
      <link>https://dev.to/usamasubhani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/usamasubhani"/>
    <language>en</language>
    <item>
      <title>Deploy React Apps on Surge using GitHub Actions (Free)</title>
      <dc:creator>Usama Subhani</dc:creator>
      <pubDate>Tue, 23 Jun 2020 11:03:35 +0000</pubDate>
      <link>https://dev.to/usamasubhani/deploy-react-apps-on-surge-using-github-actions-free-2h7i</link>
      <guid>https://dev.to/usamasubhani/deploy-react-apps-on-surge-using-github-actions-free-2h7i</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/features/actions"&gt;GitHub Actions&lt;/a&gt; is a tool by GitHub to automate building, testing and deployment of code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://surge.sh/"&gt;Surge&lt;/a&gt; is a simple tool for publishing static websites for free, by only running a single command.&lt;/p&gt;

&lt;p&gt;In this post, I have written the steps you can follow to deploy a react app to surge.sh using GitHub actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we need:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A React application. &lt;a href="https://create-react-app.dev/"&gt;create&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A GitHub repository. &lt;a href="https://Github.com/new"&gt;create&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;A Surge deploy token.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Get surge deploy token
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install surge
surge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Enter username/email and password to login.&lt;br&gt;
Then run &lt;code&gt;surge token&lt;/code&gt; to generate token.&lt;br&gt;
Copy this token and add it as a &lt;a href="https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets"&gt;secret&lt;/a&gt; in the GitHub repository.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup GitHub Actions
&lt;/h2&gt;

&lt;p&gt;GitHub actions are triggered by yaml files in &lt;code&gt;.github/workflows/&lt;/code&gt; directory. Create a yaml file in this directory and add these lines.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;master&lt;/span&gt; &lt;span class="pi"&gt;]&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v2&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Setup Node&lt;/span&gt;
      &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v2-beta&lt;/span&gt;
      &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build React App&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;npm install # Install Dependencies&lt;/span&gt;
        &lt;span class="s"&gt;CI=false npm run build # CI=false to ignore warnings&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install Surge&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm install -g surge&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy to Surge&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="s"&gt;surge ./build https://someawsomeurl.surge.sh/ --token ${{secrets.TOKEN}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;What this does is on every push to master branch, these steps are performed by GitHub actions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setup Node&lt;/li&gt;
&lt;li&gt;Install all dependecies.&lt;/li&gt;
&lt;li&gt;Build the app.&lt;/li&gt;
&lt;li&gt;Install surge.&lt;/li&gt;
&lt;li&gt;Run surge to deploy on given url.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Deploy
&lt;/h2&gt;

&lt;p&gt;Commit and push your changes to the GitHub repository. You can now see the progress in the Actions tab on GitHub.&lt;br&gt;
After all steps are completed, you React app will be available on the URL used in the deploy.yaml file.&lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You can use this process to deploy Vue and Angular app too. GitHub actions is a great tool that can be used to automate your workflow.&lt;/p&gt;

&lt;p&gt;Checkout this React project in which I used the above steps for deployment:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/usamasubhani"&gt;
        usamasubhani
      &lt;/a&gt; / &lt;a href="https://github.com/usamasubhani/another-covid-tracker"&gt;
        another-covid-tracker
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Covid-19 Tracker project for Panacloud Bootcamp 2020
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;Feel free to share what automation tools are you using and what tasks are you planning to automate.&lt;/p&gt;

</description>
      <category>react</category>
      <category>github</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Digit Recognizer: A Computer Vision Project From Training to Deployment.</title>
      <dc:creator>Usama Subhani</dc:creator>
      <pubDate>Fri, 29 May 2020 16:31:52 +0000</pubDate>
      <link>https://dev.to/usamasubhani/digit-recognizer-from-training-a-neural-net-to-deployment-3k4b</link>
      <guid>https://dev.to/usamasubhani/digit-recognizer-from-training-a-neural-net-to-deployment-3k4b</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdf63zqhsfoffxaphgj8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdf63zqhsfoffxaphgj8g.png" alt="Digit Recognizer"&gt;&lt;/a&gt;&lt;br&gt;
As recommended by most people, I decided to get my hands dirty in the field of computer vision by playing with the famous MNIST data-set to create a digit recognizer. &lt;/p&gt;

&lt;p&gt;Link to app: &lt;a href="https://usamasubhani.tech/projects/digit-recognizer" rel="noopener noreferrer"&gt;https://usamasubhani.tech/projects/digit-recognizer&lt;/a&gt;&lt;br&gt;
Source code: &lt;a href="https://github.com/usamasubhani/digit-recognizer" rel="noopener noreferrer"&gt;https://github.com/usamasubhani/digit-recognizer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: This is the first iteration of my first computer vision project. I will be improving this project (and this post) as I learn more.&lt;/p&gt;
&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Data-set&lt;/li&gt;
&lt;li&gt;
Training and Testing

&lt;ul&gt;
&lt;li&gt;Training&lt;/li&gt;
&lt;li&gt;Testing&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Web app + Deployment

&lt;ul&gt;
&lt;li&gt;Deployment on Heroku&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Data-set
&lt;/h2&gt;

&lt;p&gt;Considered the "hello world" data-set of computer vision, the MNIST Data-set contains labeled gray-scale images of handwritten digits (0-9). Each image has 28x28 pixels. and the pixel values are between 0 and 255.&lt;/p&gt;

&lt;p&gt;This data-set is very popular, so it is already available in Tensorflow&lt;/p&gt;
&lt;h3&gt;
  
  
  Load and Normalize the Data:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tensorflow&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mnist&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load_data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# Normailize
&lt;/span&gt;&lt;span class="n"&gt;x_train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;x_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Training and testing
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Training
&lt;/h3&gt;

&lt;p&gt;Keras is a library for implementing neural networks and can work as a high level API for TensorFlow. For this project, I used the &lt;code&gt;Sequential&lt;/code&gt; model.&lt;/p&gt;

&lt;p&gt;According to the &lt;a href="https://keras.io/api/" rel="noopener noreferrer"&gt;Keras documentation&lt;/a&gt;, A &lt;code&gt;Sequential&lt;/code&gt; model is appropriate for a plain stack of layers where each layer has exactly one input tensor and one output tensor.&lt;/p&gt;

&lt;p&gt;Creating a neural network:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;keras.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Sequential&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;keras.layers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Dense&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Conv2D&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Dropout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Flatten&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;MaxPool2D&lt;/span&gt;

&lt;span class="n"&gt;input_shape&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Sequential&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;Conv2D&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kernel_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;input_shape&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;input_shape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;MaxPool2D&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;pool_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;Flatten&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;Dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;relu&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;Dropout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;Dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;softmax&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compiling and Fitting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Set optimizer and loss function
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; 
    &lt;span class="n"&gt;optimizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;adam&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;loss&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sparse_categorical_crossentropy&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;accuracy&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Fit the model using training data
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;I will add explanation of the above code once I will learn more about neural networks.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Testing
&lt;/h3&gt;

&lt;p&gt;Test the accuracy of trained model by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the model by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;model_json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;w&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;jsonFile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;jsonFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save_weights&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Model_mnist.h5&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trained model is now saved and can be deployed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;The plan was to create a web application that allows user to draw a digit using a mouse.&lt;br&gt;
I decided to use Flask, which is a minimalist web framework for python and is perfect for small to medium scale projects.&lt;/p&gt;

&lt;p&gt;Directory structure for the Flask app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Digit-recognizer
|
└─api
| └─templates
| | └─index.html
| └─static
| | └─sketchpad.js
| └─__init__.py
|
└─model
  └─model.json
  └─modl_mnist.h5

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Complete source code can be seen at the Github &lt;a href="[https://github.com/usamasubhani/digit-recognizer](https://github.com/usamasubhani/digit-recognizer)"&gt;repository&lt;/a&gt;. Pasting all the code here will be unnecessary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment on Heroku
&lt;/h3&gt;

&lt;p&gt;To deploy a Flask app on heroku, we need 3 files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Procfile
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: gunicorn wsgi:app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; wsgi.py
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from api import app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;requirements.txt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install pipreqs
pipreqs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a project on Heroku and connect it to your Github repo.&lt;/li&gt;
&lt;li&gt;Push the application code to the repo. 
The app is now deployed on Heroku.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There is a lot to improve. I am listing some to-dos here, feel free to contribute the project or give feedback.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improve the model&lt;/li&gt;
&lt;li&gt;(Done)Enable drawing on touch devices.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>showdev</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to Keep Home Directory Clean?</title>
      <dc:creator>Usama Subhani</dc:creator>
      <pubDate>Fri, 15 May 2020 09:50:16 +0000</pubDate>
      <link>https://dev.to/usamasubhani/how-to-keep-home-directory-clean-4pl2</link>
      <guid>https://dev.to/usamasubhani/how-to-keep-home-directory-clean-4pl2</guid>
      <description>&lt;p&gt;I hate it when every program stores it's config and cache files in the home directory.&lt;/p&gt;

&lt;p&gt;Have you ever felt that?&lt;/p&gt;

&lt;p&gt;How do you deal with it?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Run this in your home directory to count the number of files.&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-la&lt;/span&gt; | &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>discuss</category>
      <category>linux</category>
      <category>productivity</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Setup a Blog With Hugo and GitHub Pages</title>
      <dc:creator>Usama Subhani</dc:creator>
      <pubDate>Fri, 01 May 2020 18:55:41 +0000</pubDate>
      <link>https://dev.to/usamasubhani/setup-a-blog-with-hugo-and-github-pages-562n</link>
      <guid>https://dev.to/usamasubhani/setup-a-blog-with-hugo-and-github-pages-562n</guid>
      <description>&lt;p&gt;If you want to share your thoughts with the world, starting an online blog is a good idea. You can use a static site generator and a free static hosting service to host your blog for free.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: My experience with SSGs is not very good, I am looking for something better than Hugo for blogging.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this post, I will show you how I setup my blog using &lt;strong&gt;Hugo&lt;/strong&gt; and &lt;strong&gt;GitHub pages&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Workflow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Write posts in markdown.&lt;/li&gt;
&lt;li&gt;Convert to a static website using hugo.&lt;/li&gt;
&lt;li&gt;Commit and push to GitHub to deploy.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Install Hugo
&lt;/h2&gt;

&lt;p&gt;To build the site, hugo must be installed on your system. &lt;/p&gt;

&lt;p&gt;Use your package manager to install Hugo.&lt;/p&gt;

&lt;p&gt;On macOS use &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install hugo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;On Arch linux&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pacman -S hugo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For other distros and Windows, &lt;a href="https://gohugo.io/getting-started/installing/"&gt;this&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To check if hugo is installed, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hugo version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Create and Configure Site
&lt;/h2&gt;

&lt;p&gt;Create a new site named 'blog'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hugo new site blog
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hugo will generate files required for a site in a new folder called blog.&lt;/p&gt;

&lt;p&gt;Initialize an empty Git repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;A theme is required for a hugo site. Visit &lt;a href="https://themes.gohugo.io/"&gt;https://themes.gohugo.io/&lt;/a&gt; and select a theme. For this tutorial, I am using notepadium. To use a theme, it should be in themes directory of hugo site. It is recommended to add theme as a &lt;a href="https://git-scm.com/book/en/v2/Git-Tools-Submodules"&gt;Git Submodule&lt;/a&gt; because it makes easier to update themes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git submodule add https://GitHub.com/cntrump/hugo-notepadium.git themes/hugo-notepadium
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To use installed theme, add these lines to &lt;code&gt;config.toml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;theme = "hugo-notepadium"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Write Some Content
&lt;/h2&gt;

&lt;p&gt;To write a post, you can manually create a markdown file in content folder or use the Hugo cli.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hugo new posts/first-post.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above command will create a new file in &lt;code&gt;content/posts/&lt;/code&gt; directory called &lt;code&gt;first-post.md&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Open this file in your text editor of choice and write your first post.&lt;/p&gt;

&lt;p&gt;Preview your site before deploying by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hugo server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Your website will be available at &lt;a href="http://localhost:1313/"&gt;http://localhost:1313/&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build and Deploy on GitHub Pages
&lt;/h2&gt;

&lt;p&gt;Types of GitHub Pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User Pages: [username].GitHub.io&lt;/li&gt;
&lt;li&gt;Project Pages: [username].GitHub.io/[project]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I recommend using Project Pages for blog.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;config.toml&lt;/code&gt;, add&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;publishDir = "docs"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will output generated static files to docs folder. GitHub pages will deploy from this folder.&lt;/p&gt;

&lt;p&gt;Also set &lt;code&gt;baseURL&lt;/code&gt; and &lt;code&gt;title&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Create a new repository in your GitHub account and copy its URL.&lt;/p&gt;

&lt;p&gt;In your hugo site directory,  run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin &amp;lt;URL-of-new-Repo&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Build your site by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hugo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then run following to deploy&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m "First Post"
git push origin master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Go to GitHub repository Settings &amp;gt; GitHub pages. Select /docs in &lt;strong&gt;Source&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Navigate to your site at [username].GitHub.io/blog&lt;/p&gt;

&lt;p&gt;Profit.&lt;/p&gt;

&lt;h2&gt;
  
  
  To-Do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Automate build and deploy.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;This is my first post on dev.to and I need your feedback, Thanks&lt;/em&gt;&lt;/p&gt;

</description>
      <category>hugo</category>
      <category>blog</category>
      <category>github</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
